# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
432922 |
2021-06-18T15:12:30 Z |
balbit |
Sorting (IOI15_sorting) |
C++14 |
|
194 ms |
20336 KB |
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#endif // BALBIT
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int )((x).size())
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
//signed main(){bug(1,2);}
const int maxn = 2e5+5;
bool seen[maxn];
int where[maxn];
int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]) {
// int IT = 0;
{
int l = 0, r = M;
while (l!=r) {
int mid = (l+r)/2;
vector<int> ts(n);
REP(i,n) ts[i] = S[i];
for (int j = 0; j<mid; ++j) {
swap(ts[X[j]], ts[Y[j]]);
}
memset(seen, 0, sizeof seen);
int tt = n;
REP(i,n) {
if (!seen[i]) {
--tt;
for (int j = i; ; j = ts[j]) {
seen[j] = 1;
if (ts[j] == i) break;
}
}
}
bug(mid, tt, l, r);
if (tt <= mid) {
r = mid;
}else{
l = mid+1;
}
}
bug(l);
vector<int> ts(n);
REP(i,n) ts[i] = S[i];
for (int j = 0; j<l; ++j) {
swap(ts[X[j]], ts[Y[j]]);
}
REP(i,n) bug(ts[i]);
int IT = 0;
REP(i,n) where[S[i]] = i;
for (int i = 0; i<n; ++i) {
while (ts[i] != i) {
bug(i, ts[i]);
{
swap(where[S[X[IT]]], where[S[Y[IT]]]);
swap(S[X[IT]], S[Y[IT]]);
}
int p1 = where[ts[i]], p2 = where[ts[ts[i]]];
P[IT] = p1; Q[IT] = p2;
++IT;
{
swap(where[S[p1]], where[S[p2]]);
swap(S[p1], S[p2]);
}
swap(ts[i], ts[ts[i]]);
bug(i, ts[i]);
}
}
while (IT != l) {
Q[IT] = P[IT] = 0;
++IT;
}
return l;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 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 |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 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 |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
2 ms |
696 KB |
Output is correct |
23 |
Correct |
2 ms |
716 KB |
Output is correct |
24 |
Correct |
2 ms |
716 KB |
Output is correct |
25 |
Correct |
2 ms |
704 KB |
Output is correct |
26 |
Correct |
2 ms |
700 KB |
Output is correct |
27 |
Correct |
2 ms |
716 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 |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 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 |
2 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 |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
2 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 |
2 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 |
186 ms |
17256 KB |
Output is correct |
16 |
Correct |
183 ms |
17676 KB |
Output is correct |
17 |
Correct |
190 ms |
19028 KB |
Output is correct |
18 |
Correct |
69 ms |
14964 KB |
Output is correct |
19 |
Correct |
157 ms |
17780 KB |
Output is correct |
20 |
Correct |
144 ms |
18292 KB |
Output is correct |
21 |
Correct |
158 ms |
18412 KB |
Output is correct |
22 |
Correct |
133 ms |
13904 KB |
Output is correct |
23 |
Correct |
164 ms |
19304 KB |
Output is correct |
24 |
Correct |
190 ms |
19224 KB |
Output is correct |
25 |
Correct |
183 ms |
19416 KB |
Output is correct |
26 |
Correct |
148 ms |
18272 KB |
Output is correct |
27 |
Correct |
140 ms |
17528 KB |
Output is correct |
28 |
Correct |
177 ms |
18888 KB |
Output is correct |
29 |
Correct |
194 ms |
19072 KB |
Output is correct |
30 |
Correct |
103 ms |
17092 KB |
Output is correct |
31 |
Correct |
172 ms |
19452 KB |
Output is correct |
32 |
Correct |
168 ms |
18516 KB |
Output is correct |
33 |
Correct |
179 ms |
19488 KB |
Output is correct |
34 |
Correct |
173 ms |
19276 KB |
Output is correct |
35 |
Correct |
139 ms |
17608 KB |
Output is correct |
36 |
Correct |
54 ms |
16040 KB |
Output is correct |
37 |
Correct |
180 ms |
20336 KB |
Output is correct |
38 |
Correct |
181 ms |
19264 KB |
Output is correct |
39 |
Correct |
179 ms |
19820 KB |
Output is correct |