Submission #1090971

#TimeUsernameProblemLanguageResultExecution timeMemory
1090971owoovoSorting (IOI15_sorting)C++17
100 / 100
215 ms26960 KiB
#include "sorting.h" #include<bits/stdc++.h> using namespace std; int tar[1000010],tarp[1000010],n,x[1000010],y[1000010],s[1000010],mp[1000010],bmp[1000010]; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; for(int i=0;i<M;i++){ x[i+1]=X[i]; y[i+1]=Y[i]; } int l=0,r=M; while(l!=r){ int m=(l+r)>>1,ok=1; //cout<<l<<" "<<r<<" "<<m<<"\n"; for(int i=0;i<N;i++){ tar[i]=i; s[i]=S[i]; } for(int i=m;i>0;i--){ swap(tar[x[i]],tar[y[i]]); } for(int i=0;i<N;i++){ tarp[tar[i]]=i; } int ans=0; for(int i=0;i<N;i++){ if(s[i]==tar[i])continue; int ori=i; while(tarp[s[ori]]!=ori){ P[ans]=tarp[s[ori]]; Q[ans]=ori; swap(s[tarp[s[ori]]],s[ori]); ans++; } } if(ans>m){ l=m+1; }else{ r=m; } } int m=l; for(int i=0;i<N;i++){ tar[i]=i; s[i]=S[i]; } for(int i=m;i>0;i--){ swap(tar[x[i]],tar[y[i]]); } for(int i=0;i<N;i++){ tarp[tar[i]]=i; } int ans=0; for(int i=0;i<N;i++){ //cout<<s[i]<<" "<<tar[i]<<"\n"; if(s[i]==tar[i])continue; int ori=i; while(ori!=tarp[s[ori]]){ //cout<<now<<" "<<ori<<"\n"; P[ans]=tarp[s[ori]]; Q[ans]=ori; swap(s[tarp[s[ori]]],s[ori]); ans++; } } for(int i=0;i<N;i++)mp[i]=i,bmp[i]=i; for(int i=0;i<m;i++){ swap(mp[X[i]],mp[Y[i]]); bmp[mp[X[i]]]=X[i]; bmp[mp[Y[i]]]=Y[i]; P[i]=bmp[P[i]]; Q[i]=bmp[Q[i]]; } for(int i=ans;i<m;i++)Q[i]=0,P[i]=0; return l; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:14:18: warning: unused variable 'ok' [-Wunused-variable]
   14 |   int m=(l+r)>>1,ok=1;
      |                  ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...