# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
640217 |
2022-09-14T02:14:44 Z |
ggoh |
Sorting (IOI15_sorting) |
C++14 |
|
406 ms |
20188 KB |
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
typedef long long lint;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int p=-1,q=M,h,st[200002],sz=0;;
vector<int>C(N),R(N),go(N),rev(N);
while(p!=q-1)
{
h=(p+q)/2;
for(int i=0;i<N;i++)C[i]=S[i];
for(int i=0;i<h;i++)swap(C[X[i]],C[Y[i]]);
sz=0;
for(int i=0;i<N;i++)
{
go[C[i]]=i;
rev[i]=C[i];
if(go[C[i]]!=C[i])
{
st[sz++]=C[i];
}
}
for(int i=0;i<N;i++)
{
C[i]=S[i];
R[S[i]]=i;
}
for(int i=0;i<h;i++)
{
swap(R[C[X[i]]],R[C[Y[i]]]);
swap(C[X[i]],C[Y[i]]);
while(sz>0 && go[st[sz-1]]==st[sz-1])sz--;
if(sz>0)
{
int ch=st[sz-1];
int j=rev[ch];
sz--;
swap(C[R[j]],C[R[ch]]);
swap(R[j],R[ch]);
swap(rev[go[j]],rev[go[ch]]);
swap(go[j],go[ch]);
}
}
int s=0;
for(int i=0;i<N;i++)if(go[i]==i)s++;
if(s==N)q=h;
else p=h;
}
for(int i=0;i<N;i++)C[i]=S[i];
for(int i=0;i<q;i++)swap(C[X[i]],C[Y[i]]);
sz=0;
for(int i=0;i<N;i++)
{
go[C[i]]=i;
rev[i]=C[i];
if(go[C[i]]!=C[i])st[sz++]=C[i];
}
for(int i=0;i<N;i++)
{
C[i]=S[i];
R[S[i]]=i;
}
for(int i=0;i<q;i++)
{
swap(R[C[X[i]]],R[C[Y[i]]]);
swap(C[X[i]],C[Y[i]]);
while(sz>0 && go[st[sz-1]]==st[sz-1])sz--;
if(sz>0)
{
int ch=st[sz-1];
int j=rev[ch];
sz--;
swap(C[R[j]],C[R[ch]]);
swap(R[j],R[ch]);
P[i]=R[j],Q[i]=R[ch];
swap(rev[go[j]],rev[go[ch]]);
swap(go[j],go[ch]);
}
else P[i]=Q[i]=0;
}
return q;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
0 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1064 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
0 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1064 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1076 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1076 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
0 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1064 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
980 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1076 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
980 KB |
Output is correct |
15 |
Correct |
1 ms |
980 KB |
Output is correct |
16 |
Correct |
1 ms |
1076 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
980 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
2 ms |
1236 KB |
Output is correct |
22 |
Correct |
2 ms |
1236 KB |
Output is correct |
23 |
Correct |
2 ms |
1236 KB |
Output is correct |
24 |
Correct |
2 ms |
1236 KB |
Output is correct |
25 |
Correct |
2 ms |
1208 KB |
Output is correct |
26 |
Correct |
2 ms |
1236 KB |
Output is correct |
27 |
Correct |
2 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
2 ms |
1236 KB |
Output is correct |
8 |
Correct |
2 ms |
1148 KB |
Output is correct |
9 |
Correct |
2 ms |
1236 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
2 ms |
1236 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
3 |
Correct |
2 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
2 ms |
1108 KB |
Output is correct |
7 |
Correct |
2 ms |
1236 KB |
Output is correct |
8 |
Correct |
2 ms |
1148 KB |
Output is correct |
9 |
Correct |
2 ms |
1236 KB |
Output is correct |
10 |
Correct |
3 ms |
1236 KB |
Output is correct |
11 |
Correct |
2 ms |
1144 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
2 ms |
1236 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
337 ms |
11892 KB |
Output is correct |
16 |
Correct |
361 ms |
18156 KB |
Output is correct |
17 |
Correct |
376 ms |
19020 KB |
Output is correct |
18 |
Correct |
107 ms |
16976 KB |
Output is correct |
19 |
Correct |
259 ms |
18772 KB |
Output is correct |
20 |
Correct |
302 ms |
19232 KB |
Output is correct |
21 |
Correct |
291 ms |
19356 KB |
Output is correct |
22 |
Correct |
329 ms |
14296 KB |
Output is correct |
23 |
Correct |
341 ms |
19824 KB |
Output is correct |
24 |
Correct |
384 ms |
19476 KB |
Output is correct |
25 |
Correct |
395 ms |
19180 KB |
Output is correct |
26 |
Correct |
280 ms |
19404 KB |
Output is correct |
27 |
Correct |
241 ms |
18852 KB |
Output is correct |
28 |
Correct |
404 ms |
19524 KB |
Output is correct |
29 |
Correct |
365 ms |
19164 KB |
Output is correct |
30 |
Correct |
196 ms |
18668 KB |
Output is correct |
31 |
Correct |
372 ms |
19660 KB |
Output is correct |
32 |
Correct |
372 ms |
19040 KB |
Output is correct |
33 |
Correct |
386 ms |
19544 KB |
Output is correct |
34 |
Correct |
365 ms |
19344 KB |
Output is correct |
35 |
Correct |
279 ms |
18524 KB |
Output is correct |
36 |
Correct |
83 ms |
18128 KB |
Output is correct |
37 |
Correct |
406 ms |
20188 KB |
Output is correct |
38 |
Correct |
397 ms |
19184 KB |
Output is correct |
39 |
Correct |
364 ms |
19332 KB |
Output is correct |