# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
56214 |
2018-07-10T09:11:25 Z |
강태규(#1579) |
Swap (BOI16_swap) |
C++11 |
|
161 ms |
23836 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
int n;
int x[200001];
int d[200000];
struct node {
node *l, *r;
int x;
int * ch;
node() {}
node(int x, node *l, node *r, int * ch) : l(l), r(r), x(x), ch(ch) {}
int query() {
if (x) return x;
if (*ch) return l->query();
return min(l->query(), r->query());
}
int erase(int v) {
if (x) {
if (x == v) return 1;
return 0;
}
if (*ch) return l->erase(v);
*ch = 1;
if (l->erase(v)) return 1;
if (r->erase(v)) {
swap(*l, *r);
return 1;
}
return *ch = 0;
}
} db[600000];
node * ns[200001];
int main() {
scanf("%d", &n);
int tp = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", x + i);
ns[i] = &(db[tp++] = node(x[i], 0, 0, 0));
}
for (int i = 2; i <= n; ++i) {
node *p = ns[i >> 1];
node *x = ns[i];
int * ch = d + (i - 2);
ns[i >> 1] = &(db[tp++] = node(0, p, x, ch));
ns[i] = &(db[tp++] = node(0, x, p, ch));
}
for (int i = 1; i <= n; ++i) {
int ret = ns[i]->query();
printf("%d%c", ret, i < n ? ' ' : '\n');
ns[i]->erase(ret);
}
return 0;
}
Compilation message
swap.cpp: In function 'int main()':
swap.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
swap.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", x + i);
~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
556 KB |
Output is correct |
10 |
Correct |
2 ms |
680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
556 KB |
Output is correct |
10 |
Correct |
2 ms |
680 KB |
Output is correct |
11 |
Correct |
3 ms |
680 KB |
Output is correct |
12 |
Correct |
3 ms |
704 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
14 |
Correct |
3 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
556 KB |
Output is correct |
10 |
Correct |
2 ms |
680 KB |
Output is correct |
11 |
Correct |
3 ms |
680 KB |
Output is correct |
12 |
Correct |
3 ms |
704 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
14 |
Correct |
3 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
27 ms |
6388 KB |
Output is correct |
17 |
Correct |
53 ms |
6396 KB |
Output is correct |
18 |
Correct |
27 ms |
6412 KB |
Output is correct |
19 |
Correct |
37 ms |
6412 KB |
Output is correct |
20 |
Correct |
36 ms |
6428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
536 KB |
Output is correct |
4 |
Correct |
2 ms |
556 KB |
Output is correct |
5 |
Correct |
2 ms |
556 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
556 KB |
Output is correct |
8 |
Correct |
2 ms |
556 KB |
Output is correct |
9 |
Correct |
2 ms |
556 KB |
Output is correct |
10 |
Correct |
2 ms |
680 KB |
Output is correct |
11 |
Correct |
3 ms |
680 KB |
Output is correct |
12 |
Correct |
3 ms |
704 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
14 |
Correct |
3 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
27 ms |
6388 KB |
Output is correct |
17 |
Correct |
53 ms |
6396 KB |
Output is correct |
18 |
Correct |
27 ms |
6412 KB |
Output is correct |
19 |
Correct |
37 ms |
6412 KB |
Output is correct |
20 |
Correct |
36 ms |
6428 KB |
Output is correct |
21 |
Correct |
161 ms |
23816 KB |
Output is correct |
22 |
Correct |
150 ms |
23836 KB |
Output is correct |
23 |
Correct |
99 ms |
23836 KB |
Output is correct |
24 |
Correct |
121 ms |
23836 KB |
Output is correct |
25 |
Correct |
127 ms |
23836 KB |
Output is correct |