# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1011668 | 2024-07-01T04:11:59 Z | hotboy2703 | Sorting (IOI15_sorting) | C++17 | 148 ms | 23172 KB |
#include "sorting.h" #include<bits/stdc++.h> using namespace std; using ll = int; #define pll pair <ll,ll> #define fi first #define se second #define MP make_pair #define sz(a) (ll((a).size())) #define BIT(mask,i) (((mask) >> (i))&1) #define MASK(i) (1LL << (i)) const ll MAXN = 2e5+100; ll p[MAXN]; ll pos[MAXN]; void sw(ll x,ll y){ swap(p[x],p[y]); swap(pos[p[x]],pos[p[y]]); } int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[]) { ll l = 0; ll r = n - 1; vector <pll> ans; while (l <= r){ ll mid = (l + r) >> 1; for (ll i = 0;i < n;i ++){ p[i] = S[i]; pos[p[i]] = i; } for (ll i = 0;i < mid;i ++){ sw(X[i],Y[i]); } vector <pll> val; for (ll i = 0;i < n;i ++){ if (p[i] != i){ val.push_back(MP(i,p[i])); sw(i,pos[i]); } } if (sz(val) > mid){ l = mid + 1; } else { while (sz(val) < mid)val.push_back(MP(0,0)); for (ll i = mid - 1;i >= 0;i --){ sw(pos[val[i].fi],pos[val[i].se]); val[i] = MP(pos[val[i].fi],pos[val[i].se]); sw(X[i],Y[i]); } ans = val; r = mid - 1; } } for (ll i =0 ;i < sz(ans);i ++){ tie(P[i],Q[i]) = ans[i]; } return sz(ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
17 | Correct | 0 ms | 344 KB | Output is correct |
18 | Correct | 0 ms | 440 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 0 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 604 KB | Output is correct |
22 | Correct | 1 ms | 604 KB | Output is correct |
23 | Correct | 1 ms | 600 KB | Output is correct |
24 | Correct | 1 ms | 680 KB | Output is correct |
25 | Correct | 1 ms | 604 KB | Output is correct |
26 | Correct | 1 ms | 604 KB | Output is correct |
27 | Correct | 1 ms | 600 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 524 KB | Output is correct |
3 | Correct | 1 ms | 496 KB | Output is correct |
4 | Correct | 1 ms | 520 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 452 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 600 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 1 ms | 600 KB | Output is correct |
13 | Correct | 1 ms | 600 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 1 ms | 524 KB | Output is correct |
3 | Correct | 1 ms | 496 KB | Output is correct |
4 | Correct | 1 ms | 520 KB | Output is correct |
5 | Correct | 1 ms | 604 KB | Output is correct |
6 | Correct | 1 ms | 452 KB | Output is correct |
7 | Correct | 1 ms | 604 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 600 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 1 ms | 600 KB | Output is correct |
13 | Correct | 1 ms | 600 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
15 | Correct | 110 ms | 19596 KB | Output is correct |
16 | Correct | 111 ms | 19864 KB | Output is correct |
17 | Correct | 122 ms | 21068 KB | Output is correct |
18 | Correct | 55 ms | 16372 KB | Output is correct |
19 | Correct | 103 ms | 18464 KB | Output is correct |
20 | Correct | 103 ms | 22096 KB | Output is correct |
21 | Correct | 106 ms | 20436 KB | Output is correct |
22 | Correct | 115 ms | 16424 KB | Output is correct |
23 | Correct | 108 ms | 23172 KB | Output is correct |
24 | Correct | 128 ms | 22904 KB | Output is correct |
25 | Correct | 148 ms | 21148 KB | Output is correct |
26 | Correct | 88 ms | 20220 KB | Output is correct |
27 | Correct | 110 ms | 18664 KB | Output is correct |
28 | Correct | 134 ms | 22756 KB | Output is correct |
29 | Correct | 120 ms | 20536 KB | Output is correct |
30 | Correct | 84 ms | 20280 KB | Output is correct |
31 | Correct | 135 ms | 21072 KB | Output is correct |
32 | Correct | 111 ms | 21048 KB | Output is correct |
33 | Correct | 135 ms | 22852 KB | Output is correct |
34 | Correct | 122 ms | 21516 KB | Output is correct |
35 | Correct | 87 ms | 18204 KB | Output is correct |
36 | Correct | 44 ms | 17712 KB | Output is correct |
37 | Correct | 118 ms | 22092 KB | Output is correct |
38 | Correct | 112 ms | 20528 KB | Output is correct |
39 | Correct | 119 ms | 22696 KB | Output is correct |