# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
986371 |
2024-05-20T11:22:55 Z |
Pyqe |
Sorting (IOI15_sorting) |
C++17 |
|
140 ms |
25392 KB |
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
long long a[200069],dsu[200069],pst[200069],pr[200069];
long long fd(long long x)
{
if(dsu[x]!=x)
{
dsu[x]=fd(dsu[x]);
}
return dsu[x];
}
int findSwapPairs(int n,int aa[],int m,int ka[],int la[],int sq[],int sq2[])
{
long long i,j,lh,rh,md,zz,c;
for(lh=0,rh=m;lh<=rh;)
{
md=(lh+rh)/2;
for(i=0;i<n;i++)
{
a[i]=aa[i];
dsu[i]=i;
}
for(i=0;i<md;i++)
{
swap(a[ka[i]],a[la[i]]);
}
c=0;
for(i=0;i<n;i++)
{
c+=fd(i)!=fd(a[i]);
dsu[fd(i)]=fd(a[i]);
}
if(c<=md)
{
zz=md;
rh=md-1;
}
else
{
lh=md+1;
}
}
for(i=0;i<n;i++)
{
a[i]=aa[i];
pst[i]=i;
pr[i]=i;
}
for(i=0;i<zz;i++)
{
swap(a[ka[i]],a[la[i]]);
sq[i]=0;
sq2[i]=0;
}
for(i=zz-1;i+1;i--)
{
swap(pst[pr[ka[i]]],pst[pr[la[i]]]);
swap(pr[ka[i]],pr[la[i]]);
}
for(j=0,i=0;i<zz;i++)
{
swap(pst[pr[ka[i]]],pst[pr[la[i]]]);
swap(pr[ka[i]],pr[la[i]]);
for(;j<n&&a[j]==j;j++);
if(j==n)
{
break;
}
sq[i]=pst[j];
sq2[i]=pst[a[j]];
swap(a[j],a[a[j]]);
}
return zz;
}
Compilation message
sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:75:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
75 | sq[i]=pst[j];
| ~~~~~^
sorting.cpp:76:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
76 | sq2[i]=pst[a[j]];
| ~~~~~~~~^
sorting.cpp:79:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
79 | return zz;
| ^~
sorting.cpp:55:11: warning: 'zz' may be used uninitialized in this function [-Wmaybe-uninitialized]
55 | for(i=0;i<zz;i++)
| ~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4552 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4552 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4540 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4452 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4552 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4540 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4452 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
2 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
2 ms |
4700 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
2 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4552 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4560 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
2 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4552 KB |
Output is correct |
2 |
Correct |
2 ms |
4700 KB |
Output is correct |
3 |
Correct |
2 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
2 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4560 KB |
Output is correct |
9 |
Correct |
2 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
2 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4700 KB |
Output is correct |
14 |
Correct |
1 ms |
4560 KB |
Output is correct |
15 |
Correct |
122 ms |
21736 KB |
Output is correct |
16 |
Correct |
125 ms |
22028 KB |
Output is correct |
17 |
Correct |
127 ms |
23500 KB |
Output is correct |
18 |
Correct |
55 ms |
19364 KB |
Output is correct |
19 |
Correct |
98 ms |
24252 KB |
Output is correct |
20 |
Correct |
106 ms |
24916 KB |
Output is correct |
21 |
Correct |
115 ms |
24908 KB |
Output is correct |
22 |
Correct |
100 ms |
18512 KB |
Output is correct |
23 |
Correct |
128 ms |
23888 KB |
Output is correct |
24 |
Correct |
125 ms |
23636 KB |
Output is correct |
25 |
Correct |
140 ms |
23920 KB |
Output is correct |
26 |
Correct |
103 ms |
22864 KB |
Output is correct |
27 |
Correct |
89 ms |
22104 KB |
Output is correct |
28 |
Correct |
140 ms |
23496 KB |
Output is correct |
29 |
Correct |
126 ms |
23632 KB |
Output is correct |
30 |
Correct |
73 ms |
21600 KB |
Output is correct |
31 |
Correct |
130 ms |
24036 KB |
Output is correct |
32 |
Correct |
112 ms |
22952 KB |
Output is correct |
33 |
Correct |
124 ms |
25392 KB |
Output is correct |
34 |
Correct |
120 ms |
23752 KB |
Output is correct |
35 |
Correct |
93 ms |
22124 KB |
Output is correct |
36 |
Correct |
46 ms |
20540 KB |
Output is correct |
37 |
Correct |
129 ms |
24908 KB |
Output is correct |
38 |
Correct |
130 ms |
23692 KB |
Output is correct |
39 |
Correct |
127 ms |
24256 KB |
Output is correct |