Submission #640495

# Submission time Handle Problem Language Result Execution time Memory
640495 2022-09-14T19:01:47 Z Urvuk3 Xor Sort (eJOI20_xorsort) C++17
65 / 100
11 ms 1080 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) { cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }

void Solve(){
    int N,S; cin>>N>>S;
    bool subtask1=(2<=N && N<=150 && S==1);
    bool subtask2=(2<=N && N<=200 && S==1);
    bool subtask3=(2<=N && N<=1000 && S==2);
    vector<int> a(N+1); for(int i=1;i<=N;i++) cin>>a[i];
    vector<pii> opers;

    function<void(int,int)> Oper=[&](int i,int j){
        if(abs(i-j)==1) a[i]=a[i]^a[j];
        opers.pb({i,j});
    };
    function<bool(int,int)> Has=[&](int x,int bit){
        return (x&(1<<bit))>0;
    };

    if(subtask1){
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N-1;j++){
                if(a[j]>a[j+1]){
                    Oper(j,j+1);
                    Oper(j+1,j);
                    Oper(j,j+1);
                }
            }
        }
    }
    else if(subtask2){

    }
    else if(subtask3){
        set<int> s;
        function<void(int,int,int)> Update=[&](int i,int j,int bit){
            if(!Has(a[i],bit) && s.count(i)) s.erase(i);
            if(!Has(a[j],bit) && s.count(j)) s.erase(j);
            if(Has(a[i],bit)) s.insert(i);
            if(Has(a[j],bit)) s.insert(j);
        };

        int L=1,R=N;
        for(int bit=20;bit>=0;bit--){
            s.clear();
            bool pomeren=false;
            for(int i=L;i<=R;i++){
                if(Has(a[i],bit)){
                    s.insert(i);
                    pomeren=true;
                }
            }
            while(!s.empty() && !(sz(s)==1 && s.count(R))){
                int i=*(s.begin());
                if(Has(a[i+1],bit)){
                    Oper(i,i+1); Update(i,i+1,bit);
                }
                else{
                    Oper(i+1,i); Update(i,i+1,bit);
                    Oper(i,i+1); Update(i,i+1,bit);
                }
            }
            if(pomeren) --R;
        }
    }
    cout<<sz(opers)<<endl;
    for(auto p:opers) cout<<p.fi<<" "<<p.se<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        Solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 5 ms 856 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
14 Correct 7 ms 856 KB Output is correct
15 Correct 6 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 4 ms 600 KB Output is correct
9 Correct 3 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 5 ms 856 KB Output is correct
13 Correct 5 ms 856 KB Output is correct
14 Correct 7 ms 856 KB Output is correct
15 Correct 6 ms 984 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Incorrect 0 ms 212 KB Not sorted
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 9 ms 868 KB Output is correct
6 Correct 11 ms 1012 KB Output is correct
7 Correct 9 ms 956 KB Output is correct
8 Correct 9 ms 952 KB Output is correct
9 Correct 10 ms 904 KB Output is correct
10 Correct 10 ms 1016 KB Output is correct
11 Correct 7 ms 868 KB Output is correct
12 Correct 8 ms 996 KB Output is correct
13 Correct 8 ms 868 KB Output is correct
14 Correct 8 ms 868 KB Output is correct
15 Correct 8 ms 1080 KB Output is correct