# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91286 | 2018-12-27T01:50:45 Z | faustaadp | Sorting (IOI15_sorting) | C++17 | 423 ms | 27228 KB |
#include "sorting.h" #include<bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; ll i,pos[202020],a[202020],n,j,xo[602020],yo[602020]; bool sor() { ll ii; for(ii=0;ii<n;ii++)if(a[ii]!=ii)return 0; return 1; } ll te=0; ll mir[202020],m; ll Pmir[202020],ta,tb,taa,tbb,P[202020]; ll cari(ll aa) { if(P[aa]==aa)return aa; else { ll temp=cari(P[aa]); P[aa]=temp; return P[aa]; } } ll bisa(ll aa) { ll ii,H=0; for(ii=0;ii<n;ii++)P[ii]=ii; for(ii=0;ii<aa;ii++) { swap(a[xo[ii]],a[yo[ii]]); pos[a[xo[ii]]]=xo[ii]; pos[a[yo[ii]]]=yo[ii]; } for(ii=0;ii<n;ii++) { //cout<<i<<" "<<ii<<" "<<a[ii]<<"\n"; ta=ii; tb=a[ii]; taa=cari(ta); tbb=cari(tb); if(taa!=tbb) { H++; P[taa]=tbb; } } return (aa>=H); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { n=N; for(i=0;i<M;i++)xo[i]=X[i]; for(i=0;i<M;i++)yo[i]=Y[i]; for(j=0;j<N;j++)a[j]=S[j]; for(j=0;j<N;j++)pos[S[j]]=j; if(sor())return 0; ll L=1,R=N,C; while(L<=R) { C=(L+R)/2; for(j=0;j<N;j++)a[j]=S[j]; for(j=0;j<N;j++)pos[S[j]]=j; ll O=bisa(C); if(O) { m=C; R=C-1; } else L=C+1; } // cout<<"M"<<m<<"\n"; for(j=0;j<N;j++)pos[S[j]]=j; for(j=0;j<N;j++)a[j]=S[j]; for(i=0;i<N;i++)mir[i]=i; for(i=m-2;i>=0;i--) swap(mir[X[i+1]],mir[Y[i+1]]); for(j=0;j<N;j++) Pmir[mir[j]]=j; te=0; for(i=0;i<m;i++) { swap(a[X[i]],a[Y[i]]); pos[a[X[i]]]=X[i]; pos[a[Y[i]]]=Y[i]; while(te<=n&&Pmir[te]==pos[te])te++; if(te>n) { P[i]=0; Q[i]=0; } else { P[i]=Pmir[te]; Q[i]=pos[te]; swap(a[P[i]],a[Q[i]]); pos[a[P[i]]]=P[i]; pos[a[Q[i]]]=Q[i]; } if(i<(m-1)) { swap(mir[X[i+1]],mir[Y[i+1]]); Pmir[mir[X[i+1]]]=X[i+1]; Pmir[mir[Y[i+1]]]=Y[i+1]; } } return m; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
3 | Correct | 3 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 384 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 512 KB | Output is correct |
11 | Correct | 2 ms | 384 KB | Output is correct |
12 | Correct | 3 ms | 380 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 3 ms | 384 KB | Output is correct |
15 | Correct | 3 ms | 384 KB | Output is correct |
16 | Correct | 3 ms | 512 KB | Output is correct |
17 | Correct | 2 ms | 384 KB | Output is correct |
18 | Correct | 2 ms | 384 KB | Output is correct |
19 | Correct | 3 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 4 ms | 768 KB | Output is correct |
22 | Correct | 4 ms | 768 KB | Output is correct |
23 | Correct | 3 ms | 768 KB | Output is correct |
24 | Correct | 3 ms | 768 KB | Output is correct |
25 | Correct | 4 ms | 768 KB | Output is correct |
26 | Correct | 3 ms | 768 KB | Output is correct |
27 | Correct | 3 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 640 KB | Output is correct |
2 | Correct | 4 ms | 640 KB | Output is correct |
3 | Correct | 4 ms | 640 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 3 ms | 640 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 3 ms | 640 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 4 ms | 640 KB | Output is correct |
10 | Correct | 4 ms | 640 KB | Output is correct |
11 | Correct | 4 ms | 640 KB | Output is correct |
12 | Correct | 4 ms | 640 KB | Output is correct |
13 | Correct | 4 ms | 640 KB | Output is correct |
14 | Correct | 4 ms | 640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 640 KB | Output is correct |
2 | Correct | 4 ms | 640 KB | Output is correct |
3 | Correct | 4 ms | 640 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 3 ms | 640 KB | Output is correct |
6 | Correct | 3 ms | 640 KB | Output is correct |
7 | Correct | 3 ms | 640 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 4 ms | 640 KB | Output is correct |
10 | Correct | 4 ms | 640 KB | Output is correct |
11 | Correct | 4 ms | 640 KB | Output is correct |
12 | Correct | 4 ms | 640 KB | Output is correct |
13 | Correct | 4 ms | 640 KB | Output is correct |
14 | Correct | 4 ms | 640 KB | Output is correct |
15 | Correct | 205 ms | 24184 KB | Output is correct |
16 | Correct | 260 ms | 24772 KB | Output is correct |
17 | Correct | 406 ms | 25936 KB | Output is correct |
18 | Correct | 50 ms | 16888 KB | Output is correct |
19 | Correct | 236 ms | 24540 KB | Output is correct |
20 | Correct | 316 ms | 25216 KB | Output is correct |
21 | Correct | 324 ms | 25220 KB | Output is correct |
22 | Correct | 196 ms | 26356 KB | Output is correct |
23 | Correct | 357 ms | 26896 KB | Output is correct |
24 | Correct | 350 ms | 26488 KB | Output is correct |
25 | Correct | 328 ms | 26232 KB | Output is correct |
26 | Correct | 243 ms | 25080 KB | Output is correct |
27 | Correct | 230 ms | 24312 KB | Output is correct |
28 | Correct | 280 ms | 26360 KB | Output is correct |
29 | Correct | 288 ms | 25720 KB | Output is correct |
30 | Correct | 172 ms | 23800 KB | Output is correct |
31 | Correct | 423 ms | 26232 KB | Output is correct |
32 | Correct | 204 ms | 26112 KB | Output is correct |
33 | Correct | 344 ms | 26556 KB | Output is correct |
34 | Correct | 217 ms | 26488 KB | Output is correct |
35 | Correct | 188 ms | 24184 KB | Output is correct |
36 | Correct | 63 ms | 23004 KB | Output is correct |
37 | Correct | 294 ms | 27228 KB | Output is correct |
38 | Correct | 295 ms | 26104 KB | Output is correct |
39 | Correct | 409 ms | 26360 KB | Output is correct |