# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
587515 | 2022-07-02T04:09:09 Z | benson1029 | Sorting (IOI15_sorting) | C++14 | 1000 ms | 17656 KB |
#include "sorting.h" #include<bits/stdc++.h> using namespace std; int a[200005], b[200005], s[200005]; vector< pair<int,int> > v; set<int> st; void swapa(int x, int y) { b[a[x]] = y; b[a[y]] = x; if(st.find(x)==st.end() && st.find(y)!=st.end()) { st.erase(y); st.insert(x); } else if(st.find(x)!=st.end() && st.find(y)==st.end()) { st.erase(x); st.insert(y); } swap(a[x], a[y]); } int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { int l = 0, r = N, mid; while(l <= r) { mid = (l+r)/2; for(int i=0; i<N; i++) { a[i] = i; s[i] = S[i]; } for(int i=mid-1; i>=0; i--) { swap(a[X[i]], a[Y[i]]); } st.clear(); for(int i=0; i<N; i++) { if(a[i] != s[i]) st.insert(i); b[a[i]] = i; } v.clear(); for(int i=0; i<mid; i++) { swapa(X[i], Y[i]); swap(s[X[i]], s[Y[i]]); if(!st.empty()) { int j = *st.begin(); int k = b[s[j]]; swap(s[j], s[k]); v.push_back({j, k}); if(s[j] == a[j]) st.erase(j); if(s[k] == a[k]) st.erase(k); } else v.push_back({0, 0}); } if(l==r) { for(int i=0; i<v.size(); i++) P[i] = v[i].first, Q[i] = v[i].second; return v.size(); } else { bool ok = true; for(int i=0; i<N; i++) if(s[i] != i) ok = false; if(ok) r = mid; else l = mid+1; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 1 ms | 340 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 3 ms | 468 KB | Output is correct |
22 | Correct | 3 ms | 468 KB | Output is correct |
23 | Correct | 3 ms | 468 KB | Output is correct |
24 | Correct | 3 ms | 468 KB | Output is correct |
25 | Correct | 2 ms | 340 KB | Output is correct |
26 | Correct | 2 ms | 468 KB | Output is correct |
27 | Correct | 3 ms | 468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 468 KB | Output is correct |
2 | Correct | 9 ms | 424 KB | Output is correct |
3 | Correct | 15 ms | 508 KB | Output is correct |
4 | Correct | 2 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 468 KB | Output is correct |
6 | Correct | 4 ms | 468 KB | Output is correct |
7 | Correct | 7 ms | 492 KB | Output is correct |
8 | Correct | 11 ms | 468 KB | Output is correct |
9 | Correct | 14 ms | 520 KB | Output is correct |
10 | Correct | 12 ms | 512 KB | Output is correct |
11 | Correct | 11 ms | 524 KB | Output is correct |
12 | Correct | 7 ms | 504 KB | Output is correct |
13 | Correct | 11 ms | 480 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 468 KB | Output is correct |
2 | Correct | 9 ms | 424 KB | Output is correct |
3 | Correct | 15 ms | 508 KB | Output is correct |
4 | Correct | 2 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 468 KB | Output is correct |
6 | Correct | 4 ms | 468 KB | Output is correct |
7 | Correct | 7 ms | 492 KB | Output is correct |
8 | Correct | 11 ms | 468 KB | Output is correct |
9 | Correct | 14 ms | 520 KB | Output is correct |
10 | Correct | 12 ms | 512 KB | Output is correct |
11 | Correct | 11 ms | 524 KB | Output is correct |
12 | Correct | 7 ms | 504 KB | Output is correct |
13 | Correct | 11 ms | 480 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Execution timed out | 1088 ms | 17656 KB | Time limit exceeded |
16 | Halted | 0 ms | 0 KB | - |