# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
525167 |
2022-02-11T00:07:51 Z |
Lobo |
Sorting (IOI15_sorting) |
C++17 |
|
529 ms |
41484 KB |
#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define maxn 620000
int n, m, a[maxn], pos[maxn], s1[maxn], s2[maxn], p[maxn], q[maxn], cur[maxn], posf[maxn], curf[maxn];
int32_t findSwapPairs(int32_t N, int32_t S[], int32_t M, int32_t X[], int32_t Y[], int32_t P[], int32_t Q[]) {
n = N;
m = M;
int R = 0;
for(int i = 0; i < n; i++) {
a[i] = S[i];
}
for(int i = 0; i < m; i++) {
s1[i] = X[i];
s2[i] = Y[i];
}
int l = 0;
int r1 = m;
while(l <= r1) {
int mid = (l+r1)>>1;
for(int i = 0; i < n; i++) {
posf[i] = i;
curf[i] = i;
pos[i] = i;
cur[i] = i;
}
for(int i = 0; i < mid; i++) {
//quero trocar cur[s1[i]] e cur[s2[i]]
//quero trocar
swap(posf[curf[s1[i]]],posf[curf[s2[i]]]);
swap(curf[s1[i]],curf[s2[i]]);
}
int id = 0;
for(int i = 0; i < mid; i++) {
swap(pos[cur[s1[i]]],pos[cur[s2[i]]]);
swap(cur[s1[i]],cur[s2[i]]);
while(id != n && posf[id] == a[id]) {
id++;
}
if(id == n) {
p[i] = 0;
q[i] = 0;
continue;
}
//troco a posicao do cara id com a posicao do cara que vai terminar em a[id]
p[i] = pos[id];
q[i] = pos[curf[a[id]]];
swap(pos[id],pos[curf[a[id]]]);
swap(cur[p[i]],cur[q[i]]);
int pfid = posf[id];
int pfaid = posf[curf[a[id]]];
swap(posf[id],posf[curf[a[id]]]);
swap(curf[pfid],curf[pfaid]);
id++;
}
while(id != n && posf[id] == a[id]) {
id++;
}
if(id == n) {
//cara pode ser a resposta
R = mid;
for(int i = 0; i < mid; i++) {
P[i] = p[i];
Q[i] = q[i];
}
r1 = mid-1;
}
else {
l = mid+1;
}
}
return R;
}
Compilation message
sorting.cpp: In function 'int32_t findSwapPairs(int32_t, int32_t*, int32_t, int32_t*, int32_t*, int32_t*, int32_t*)':
sorting.cpp:90:27: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
90 | P[i] = p[i];
| ~~~^
sorting.cpp:91:27: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
91 | Q[i] = q[i];
| ~~~^
sorting.cpp:101:12: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
101 | return R;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
0 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
844 KB |
Output is correct |
22 |
Correct |
1 ms |
844 KB |
Output is correct |
23 |
Correct |
2 ms |
844 KB |
Output is correct |
24 |
Correct |
1 ms |
844 KB |
Output is correct |
25 |
Correct |
1 ms |
844 KB |
Output is correct |
26 |
Correct |
1 ms |
844 KB |
Output is correct |
27 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
2 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
303 ms |
28868 KB |
Output is correct |
16 |
Correct |
386 ms |
37280 KB |
Output is correct |
17 |
Correct |
529 ms |
39364 KB |
Output is correct |
18 |
Correct |
119 ms |
35780 KB |
Output is correct |
19 |
Correct |
257 ms |
39148 KB |
Output is correct |
20 |
Correct |
327 ms |
40176 KB |
Output is correct |
21 |
Correct |
263 ms |
40204 KB |
Output is correct |
22 |
Correct |
295 ms |
34884 KB |
Output is correct |
23 |
Correct |
349 ms |
40888 KB |
Output is correct |
24 |
Correct |
485 ms |
40308 KB |
Output is correct |
25 |
Correct |
494 ms |
39752 KB |
Output is correct |
26 |
Correct |
337 ms |
40084 KB |
Output is correct |
27 |
Correct |
278 ms |
39192 KB |
Output is correct |
28 |
Correct |
483 ms |
40224 KB |
Output is correct |
29 |
Correct |
482 ms |
39604 KB |
Output is correct |
30 |
Correct |
200 ms |
39108 KB |
Output is correct |
31 |
Correct |
460 ms |
40424 KB |
Output is correct |
32 |
Correct |
338 ms |
39472 KB |
Output is correct |
33 |
Correct |
497 ms |
40288 KB |
Output is correct |
34 |
Correct |
394 ms |
40080 KB |
Output is correct |
35 |
Correct |
248 ms |
38464 KB |
Output is correct |
36 |
Correct |
64 ms |
38440 KB |
Output is correct |
37 |
Correct |
457 ms |
41484 KB |
Output is correct |
38 |
Correct |
390 ms |
39868 KB |
Output is correct |
39 |
Correct |
379 ms |
40008 KB |
Output is correct |