# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96946 | 2019-02-12T20:01:28 Z | Kastanda | Swap (BOI16_swap) | C++11 | 1000 ms | 160308 KB |
// Borrowed. #include<bits/stdc++.h> using namespace std; const int N = 4e5 + 10; int n, l, r, A[N], R[N], rev[N]; set < int > S[N], B[N]; bitset < N > M; inline bool Check(int id, int val) { if (M[val]) return (1); while (id) { if (B[id].count(val)) return (1); id >>= 1; } return (0); } inline bool Sub(int id, int pr) { while (id) { if (id == pr) return (1); id >>= 1; } return (0); } int main() { scanf("%d", &n); memset(A, 1, sizeof(A)); for (int i = 1; i <= n; i++) scanf("%d", &A[i]), S[i].insert(A[i]), rev[A[i]] = i; for (int i = 1; i <= n; i++) { int lc = i * 2, rc = lc + 1; int best = *S[i].begin(); while (Check(i, best)) { S[i].erase(S[i].begin()); assert(S[i].size() != 0); best = *S[i].begin(); } if (best < A[lc] && best < A[rc]) { R[i] = best; M[best] = 1; if (Sub(i, rev[best])) { int pr = rev[best], id = i; while (id > pr) { for (auto X : S[(id >> 1)]) B[id^1].insert(X); B[id].insert(A[id ^1]); id >>= 1; S[id].clear(); } } else { int pr = rev[best]; B[pr].insert(A[pr]); for (auto X : S[(pr >> 1)]) B[pr^1].insert(X); int id = i; pr ^= 1; while (id > pr) { for (auto X : S[(id >> 1)]) B[id^1].insert(X); B[id].insert(A[id ^1]); id >>= 1; S[id].clear(); } } //S[i].clear(); continue; } if (A[lc] < A[rc]) { R[i] = A[lc]; M[R[i]] = 1; S[lc].clear(); for (auto X : S[i]) S[lc].insert(X); //S[i].clear(); continue; } R[i] = A[rc]; M[R[i]] = 1; S[rc].clear(); S[rc].insert(A[lc]); S[lc].insert(A[lc]); for (auto X : S[i]) { S[lc].insert(X); S[rc].insert(X); } //S[i].clear(); } for (int i = 1; i <= n; i++) printf("%d ", R[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 39424 KB | Output is correct |
2 | Correct | 34 ms | 39552 KB | Output is correct |
3 | Correct | 36 ms | 39416 KB | Output is correct |
4 | Correct | 42 ms | 39672 KB | Output is correct |
5 | Correct | 114 ms | 39544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 39424 KB | Output is correct |
2 | Correct | 34 ms | 39552 KB | Output is correct |
3 | Correct | 36 ms | 39416 KB | Output is correct |
4 | Correct | 42 ms | 39672 KB | Output is correct |
5 | Correct | 114 ms | 39544 KB | Output is correct |
6 | Correct | 44 ms | 39480 KB | Output is correct |
7 | Correct | 43 ms | 39508 KB | Output is correct |
8 | Correct | 31 ms | 39512 KB | Output is correct |
9 | Correct | 36 ms | 39416 KB | Output is correct |
10 | Correct | 35 ms | 39416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 39424 KB | Output is correct |
2 | Correct | 34 ms | 39552 KB | Output is correct |
3 | Correct | 36 ms | 39416 KB | Output is correct |
4 | Correct | 42 ms | 39672 KB | Output is correct |
5 | Correct | 114 ms | 39544 KB | Output is correct |
6 | Correct | 44 ms | 39480 KB | Output is correct |
7 | Correct | 43 ms | 39508 KB | Output is correct |
8 | Correct | 31 ms | 39512 KB | Output is correct |
9 | Correct | 36 ms | 39416 KB | Output is correct |
10 | Correct | 35 ms | 39416 KB | Output is correct |
11 | Correct | 36 ms | 39564 KB | Output is correct |
12 | Correct | 34 ms | 39544 KB | Output is correct |
13 | Correct | 39 ms | 39548 KB | Output is correct |
14 | Correct | 34 ms | 39816 KB | Output is correct |
15 | Correct | 44 ms | 39780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 39424 KB | Output is correct |
2 | Correct | 34 ms | 39552 KB | Output is correct |
3 | Correct | 36 ms | 39416 KB | Output is correct |
4 | Correct | 42 ms | 39672 KB | Output is correct |
5 | Correct | 114 ms | 39544 KB | Output is correct |
6 | Correct | 44 ms | 39480 KB | Output is correct |
7 | Correct | 43 ms | 39508 KB | Output is correct |
8 | Correct | 31 ms | 39512 KB | Output is correct |
9 | Correct | 36 ms | 39416 KB | Output is correct |
10 | Correct | 35 ms | 39416 KB | Output is correct |
11 | Correct | 36 ms | 39564 KB | Output is correct |
12 | Correct | 34 ms | 39544 KB | Output is correct |
13 | Correct | 39 ms | 39548 KB | Output is correct |
14 | Correct | 34 ms | 39816 KB | Output is correct |
15 | Correct | 44 ms | 39780 KB | Output is correct |
16 | Correct | 86 ms | 45436 KB | Output is correct |
17 | Correct | 80 ms | 45384 KB | Output is correct |
18 | Correct | 86 ms | 45452 KB | Output is correct |
19 | Correct | 174 ms | 73948 KB | Output is correct |
20 | Correct | 152 ms | 73732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 35 ms | 39424 KB | Output is correct |
2 | Correct | 34 ms | 39552 KB | Output is correct |
3 | Correct | 36 ms | 39416 KB | Output is correct |
4 | Correct | 42 ms | 39672 KB | Output is correct |
5 | Correct | 114 ms | 39544 KB | Output is correct |
6 | Correct | 44 ms | 39480 KB | Output is correct |
7 | Correct | 43 ms | 39508 KB | Output is correct |
8 | Correct | 31 ms | 39512 KB | Output is correct |
9 | Correct | 36 ms | 39416 KB | Output is correct |
10 | Correct | 35 ms | 39416 KB | Output is correct |
11 | Correct | 36 ms | 39564 KB | Output is correct |
12 | Correct | 34 ms | 39544 KB | Output is correct |
13 | Correct | 39 ms | 39548 KB | Output is correct |
14 | Correct | 34 ms | 39816 KB | Output is correct |
15 | Correct | 44 ms | 39780 KB | Output is correct |
16 | Correct | 86 ms | 45436 KB | Output is correct |
17 | Correct | 80 ms | 45384 KB | Output is correct |
18 | Correct | 86 ms | 45452 KB | Output is correct |
19 | Correct | 174 ms | 73948 KB | Output is correct |
20 | Correct | 152 ms | 73732 KB | Output is correct |
21 | Correct | 216 ms | 63700 KB | Output is correct |
22 | Correct | 258 ms | 63480 KB | Output is correct |
23 | Correct | 218 ms | 63532 KB | Output is correct |
24 | Execution timed out | 1163 ms | 160308 KB | Time limit exceeded |
25 | Halted | 0 ms | 0 KB | - |