• E Minimum Array (二分+multiset) ( Codeforces Round #555 (Div. 3) )


    You are given two arrays aa and bb, both of length nn. All elements of both arrays are from 00 to n1n−1.

    You can reorder elements of the array bb (if you want, you may leave the order of elements as it is). After that, let array cc be the array of length nn, the ii-th element of this array is ci=(ai+bi)%nci=(ai+bi)%n, where x%yx%y is xx modulo yy.

    Your task is to reorder elements of the array bb to obtain the lexicographicallyminimum possible array cc.

    Array xx of length nn is lexicographically less than array yy of length nn, if there exists such ii (1in1≤i≤n), that xi<yixi<yi, and for any jj (1j<i1≤j<i) xj=yjxj=yj.

    Input

    The first line of the input contains one integer nn (1n21051≤n≤2⋅105) — the number of elements in aa, bb and cc.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (0ai<n0≤ai<n), where aiaiis the ii-th element of aa.

    The third line of the input contains nn integers b1,b2,,bnb1,b2,…,bn (0bi<n0≤bi<n), where bibi is the ii-th element of bb.

    Output

    Print the lexicographically minimum possible array cc. Recall that your task is to reorder elements of the array bb and obtain the lexicographically minimum possible array cc, where the ii-th element of cc is ci=(ai+bi)%nci=(ai+bi)%n.

    Examples

    Input
    4
    0 1 2 1  
    3 2 1 1
    
    Output
    1 0 0 2 
    
    Input
    7
    2 5 1 5 3 4 3
    2 4 3 5 6 5 1
    
    Output
    0 0 0 1 0 2 4 
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    //
    #define lson rt<<1, l, m
    #define rson rt<<1|1, m+1, r
    //
    #define fi      first
    #define se      second
    #define pb      push_back
    #define pq      priority_queue<int>
    #define ok      return 0;
    #define os(str) cout<<string(str)<<endl;
    #define gcd __gcd
    #define mem(s,t) memset(s,t,sizeof(s))
    #define debug(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
    #define debug1(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";  cout<<endl;
    #define debug02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" ";   cout<<endl; }
    #define read11(a,k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i];}
    #define read02(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cin>>a[i][j] ; }
    #define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    
    using namespace std;
    inline void NO()
    {
        cout<<"NO"<<endl;
    }
    inline void YES()
    {
        cout<<"YES"<<endl;
    }
    const  int  mxn = 2e5+10;
    #define oi(x)   cout<<x<<endl;
    #define rep(k)    for (int i=0;i<n;i++)
    #define rep1(j,k) for (int i=j;i<=k;  i++)
    #define per(j,k)  for (int i=j;i>=k; i--)
    #define test cout<<"    +++++++ "<<endl;
    multiset<int> v;
    multiset<int> :: iterator it ;
    
    int main()
    {
    
        int n,b;
        cin>>n;
        int a[n+5];
        for(int i=0; i<n; i++)
            cin>>a[i];
        for(int i=0; i<n; i++)
        {
            cin>>b;
            v.insert(b);
        }
        for(int i=0; i<n; i++)
        {
            int p = n-a[i];
            it = v.lower_bound(p);
            if(it==v.end()) it = v.begin();
            cout<<(a[i]+(*it))%n<<" ";
            v.erase(it);
        }
        cout<<endl;
        return 0;
    }
    所遇皆星河
  • 相关阅读:
    开发笔记:python与随机数(转)
    如何建立内核级钩子控制操作系统实现程序隐身(转)
    SPOJ 7001. Visible Lattice Points (莫比乌斯反演)
    BZOJ 2301: [HAOI2011]Problem b (莫比乌斯反演)
    HDU 1695 GCD (莫比乌斯反演)
    HDU 4691 Front compression (2013多校9 1006题 后缀数组)
    HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)
    HDU 1695 GCD (欧拉函数+容斥原理)
    【转】[专题学习][计算几何]
    POJ 1755 Triathlon (半平面交)
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11620911.html
Copyright © 2020-2023  润新知