Submission #56187

# Submission time Handle Problem Language Result Execution time Memory
56187 2018-07-10T07:55:18 Z 윤교준(#1582) Swap (BOI16_swap) C++11
100 / 100
213 ms 46592 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 200005;

struct NOD {
	NOD(NOD *l, NOD *r, int dt, bool *c)
		: l(l), r(r), dt(dt), c(c) {}
	NOD *l, *r;
	int dt;
	bool *c;

	int get() {
		if(dt) return dt;
		if(*c) return l -> get();
		return min(l -> get(), r -> get());
	}
	bool upd(int x) {
		if(dt) {
			if(dt != x) return false;
			dt = INF;
			return true;
		}
		if(*c) return l -> upd(x);
		if(l -> upd(x)) {
			*c = true;
			return true;
		}
		if(r -> upd(x)) {
			*c = true;
			swap(*l, *r);
			return true;
		}
		return false;
	}
};

NOD *nod[MAXN];

int A[MAXN];
int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	
	for(int i = 1; i <= N; i++)
		nod[i] = new NOD(NULL, NULL, A[i], NULL);
	for(int i = 2; i <= N; i++) {
		NOD *a = nod[i/2], *b = nod[i];
		bool *c = new bool(false);
		nod[i/2] = new NOD(a, b, 0, c);
		nod[i] = new NOD(b, a, 0, c);
	}
	for(int i = 1, x; i <= N; i++) {
		x = nod[i] -> get();
		nod[i] -> upd(x);
		printf("%d ", x);
	}
	puts("");
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 3 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 3 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 3 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 3 ms 696 KB Output is correct
11 Correct 3 ms 828 KB Output is correct
12 Correct 3 ms 832 KB Output is correct
13 Correct 2 ms 836 KB Output is correct
14 Correct 3 ms 840 KB Output is correct
15 Correct 3 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 3 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 3 ms 696 KB Output is correct
11 Correct 3 ms 828 KB Output is correct
12 Correct 3 ms 832 KB Output is correct
13 Correct 2 ms 836 KB Output is correct
14 Correct 3 ms 840 KB Output is correct
15 Correct 3 ms 848 KB Output is correct
16 Correct 36 ms 10448 KB Output is correct
17 Correct 49 ms 10748 KB Output is correct
18 Correct 28 ms 11048 KB Output is correct
19 Correct 36 ms 11364 KB Output is correct
20 Correct 65 ms 11648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 4 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 588 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 3 ms 676 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 3 ms 696 KB Output is correct
11 Correct 3 ms 828 KB Output is correct
12 Correct 3 ms 832 KB Output is correct
13 Correct 2 ms 836 KB Output is correct
14 Correct 3 ms 840 KB Output is correct
15 Correct 3 ms 848 KB Output is correct
16 Correct 36 ms 10448 KB Output is correct
17 Correct 49 ms 10748 KB Output is correct
18 Correct 28 ms 11048 KB Output is correct
19 Correct 36 ms 11364 KB Output is correct
20 Correct 65 ms 11648 KB Output is correct
21 Correct 124 ms 41476 KB Output is correct
22 Correct 128 ms 42708 KB Output is correct
23 Correct 131 ms 44020 KB Output is correct
24 Correct 179 ms 45304 KB Output is correct
25 Correct 213 ms 46592 KB Output is correct