Submission #1104397

#TimeUsernameProblemLanguageResultExecution timeMemory
1104397ziyad_alharbiXor Sort (eJOI20_xorsort)C++17
0 / 100
1 ms500 KiB
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,t; cin>>n>>t; int a[n+5],b[n+5]; set<pair<int,int>>st; for(int x=1;x<=n;x++) { cin>>a[x]; st.insert({a[x],x}); b[x]=a[x]; } vector<pair<int,int>>ans; if(t==1) { for(int x=1;x<n;x++) { ans.push_back({x,x+1}); b[x]=(b[x]^b[x+1]); } int I=n; while(st.size()) { auto [v,i]=*st.rbegin(); st.erase({v,i}); if(i==I)continue; //cout<<v<<' '<<i<<'\n'; for(int x=i-1;x>1;x--) { ans.push_back({x-1,x}); b[x-1]=(b[x-1]^b[x]); } for(int x=i+1;x<=I;x++) { ans.push_back({x,x-1}); b[x]=(b[x]^b[x-1]); } for(int x=2;x<=I;x++) { ans.push_back({x-1,x}); b[x-1]=(b[x-1]^b[x]); if(x>i) { st.erase({a[x],x}); swap(a[x],a[x-1]); st.insert({a[x-1],x-1}); } } I--; } } cout<<ans.size()<<'\n'; for(auto [x,y]:ans)cout<<x<<' '<<y<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...