#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
int tab[200005],pos[200005],L;
ii ans[200005];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int l=0,r=M;
while(l<=r){
for (int i = 0; i < N; ++i){
tab[i]=S[i];
pos[S[i]]=i;
}
int med=(l+r)>>1,idx=0;
for (int i = 0; i < med; ++i)
swap(pos[tab[X[i]]],pos[tab[Y[i]]]),swap(tab[X[i]],tab[Y[i]]);
for (int i = 0; i < N; ++i)
{
if(tab[i]!=i){
int k=pos[i];
ans[idx++]={i,tab[i]};
swap(pos[tab[i]],pos[i]);
swap(tab[i],tab[k]);
}
}
if(idx>med)l=med+1;
else{
L=med;
for (int i = 0; i < N; ++i){
tab[i]=S[i];
pos[S[i]]=i;
}
for (int i = 0; i < med; ++i)
{
swap(pos[tab[X[i]]],pos[tab[Y[i]]]),swap(tab[X[i]],tab[Y[i]]);
if(i<idx)P[i]=pos[ans[i].fi],Q[i]=pos[ans[i].se],swap(tab[P[i]],tab[Q[i]]),swap(pos[ans[i].fi],pos[ans[i].se]);
else P[i]=Q[i]=0;
}
r=med-1;
}
}
return L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
640 KB |
Output is correct |
22 |
Correct |
2 ms |
640 KB |
Output is correct |
23 |
Correct |
2 ms |
640 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
640 KB |
Output is correct |
26 |
Correct |
2 ms |
640 KB |
Output is correct |
27 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
568 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
568 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
512 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
198 ms |
19960 KB |
Output is correct |
16 |
Correct |
264 ms |
20476 KB |
Output is correct |
17 |
Correct |
302 ms |
21624 KB |
Output is correct |
18 |
Correct |
121 ms |
18552 KB |
Output is correct |
19 |
Correct |
208 ms |
20728 KB |
Output is correct |
20 |
Correct |
224 ms |
21368 KB |
Output is correct |
21 |
Correct |
213 ms |
21368 KB |
Output is correct |
22 |
Correct |
196 ms |
17016 KB |
Output is correct |
23 |
Correct |
246 ms |
22428 KB |
Output is correct |
24 |
Correct |
331 ms |
22148 KB |
Output is correct |
25 |
Correct |
358 ms |
21848 KB |
Output is correct |
26 |
Correct |
228 ms |
20856 KB |
Output is correct |
27 |
Correct |
208 ms |
20088 KB |
Output is correct |
28 |
Correct |
291 ms |
21872 KB |
Output is correct |
29 |
Correct |
304 ms |
21468 KB |
Output is correct |
30 |
Correct |
154 ms |
19536 KB |
Output is correct |
31 |
Correct |
319 ms |
21880 KB |
Output is correct |
32 |
Correct |
225 ms |
21752 KB |
Output is correct |
33 |
Correct |
337 ms |
22108 KB |
Output is correct |
34 |
Correct |
260 ms |
22008 KB |
Output is correct |
35 |
Correct |
212 ms |
20396 KB |
Output is correct |
36 |
Correct |
83 ms |
18424 KB |
Output is correct |
37 |
Correct |
327 ms |
22648 KB |
Output is correct |
38 |
Correct |
310 ms |
21756 KB |
Output is correct |
39 |
Correct |
319 ms |
22136 KB |
Output is correct |