답안 #115469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115469 2019-06-07T15:38:10 Z gs14004 무지개나라 (APIO17_rainbow) C++17
100 / 100
1272 ms 185976 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
const int MAXT = 20000000;
const int MAXN = 200005;

struct node{
	int l, r, sum;
}pool[MAXT];
int piv;

int newnode(){ return ++piv; }

void init(int s, int e, int p){
	if(s == e) return;
	int m = (s+e)/2;
	pool[p].l = newnode();
	pool[p].r = newnode();
	init(s, m, pool[p].l);
	init(m+1, e, pool[p].r);
}

void add(int pos, int s, int e, int prv, int cur){
	pool[cur].sum = pool[prv].sum + 1;
	if(s == e) return;
	int m = (s+e)/2;
	if(pos <= m){
		pool[cur].l = newnode();
		pool[cur].r = pool[prv].r;
		add(pos, s, m, pool[prv].l, pool[cur].l);
	}
	else{
		pool[cur].l = pool[prv].l;
		pool[cur].r = newnode();
		add(pos, m+1, e, pool[prv].r, pool[cur].r);
	}
}

int query(int s, int e, int ps, int pe, int p){
	if(e < ps || pe < s) return 0;
	if(s <= ps && pe <= e) return pool[p].sum;
	int pm = (ps + pe) / 2;
	return query(s, e, ps, pm, pool[p].l) + query(s, e, pm+1, pe, pool[p].r);
}

int tree[4][MAXN];
vector<int> v[4][MAXN];
int minx = 1e9, miny = 1e9, maxx = -1e9, maxy = -1e9, yMax;

void init(int R, int C, int sr, int sc, int M, char *S) {
	auto upload = [&](int x, int y){
		v[0][x].push_back(y);
		v[0][x].push_back(y + 1);
		v[0][x + 1].push_back(y);
		v[0][x + 1].push_back(y + 1);
		v[1][x].push_back(y);
		v[1][x].push_back(y + 1);
		v[2][x].push_back(y);
		v[2][x + 1].push_back(y);
		v[3][x].push_back(y);
		minx = min(minx, x); maxx = max(maxx, x + 1);
		miny = min(miny, y); maxy = max(maxy, y + 1);
	};
	upload(sr, sc);
	for(int i=0; i<M; i++){
		if(S[i] == 'N') sr--;
		if(S[i] == 'S') sr++;
		if(S[i] == 'E') sc++;
		if(S[i] == 'W') sc--;
		upload(sr, sc);
	}
	yMax = C + 1;
	for(int i=0; i<4; i++){
		tree[i][0] = newnode();
		init(1, yMax, tree[i][0]); 
		for(int j=1; j<=R+1; j++){
			sort(v[i][j].begin(), v[i][j].end());
			v[i][j].resize(unique(v[i][j].begin(), v[i][j].end()) - v[i][j].begin());
			int prv = tree[i][j-1];
			for(auto &k : v[i][j]){
				int nxt = newnode();
				add(k, 1, yMax, prv, nxt);
				prv = nxt;
			}
			tree[i][j] = prv;
		}
	}
}

int colour(int ar, int ac, int br, int bc) {
	auto query_helper = [&](int idx, int sx, int ex, int sy, int ey){
		return query(sy, ey, 1, yMax, tree[idx][ex]) 
		- query(sy, ey, 1, yMax, tree[idx][sx - 1]);
	};
	int V = query_helper(0, ar + 1, br, ac + 1, bc);
	int E = query_helper(1, ar, br, ac + 1, bc) + query_helper(2, ar + 1, br, ac, bc);
	int F = query_helper(3, ar, br, ac, bc);
	if(ar < minx && maxx < br + 1 && ac < miny && maxy < bc + 1){
		return 2 + E - V - F;
	}
	return 1 + E - V - F;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19200 KB Output is correct
2 Correct 21 ms 19580 KB Output is correct
3 Correct 30 ms 19320 KB Output is correct
4 Correct 20 ms 19320 KB Output is correct
5 Correct 22 ms 19840 KB Output is correct
6 Correct 18 ms 19200 KB Output is correct
7 Correct 20 ms 19200 KB Output is correct
8 Correct 18 ms 19200 KB Output is correct
9 Correct 17 ms 19188 KB Output is correct
10 Correct 17 ms 19200 KB Output is correct
11 Correct 20 ms 19328 KB Output is correct
12 Correct 21 ms 19584 KB Output is correct
13 Correct 20 ms 19840 KB Output is correct
14 Correct 21 ms 20096 KB Output is correct
15 Correct 21 ms 19072 KB Output is correct
16 Correct 18 ms 19072 KB Output is correct
17 Correct 21 ms 19072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 19072 KB Output is correct
2 Correct 21 ms 19072 KB Output is correct
3 Correct 900 ms 120296 KB Output is correct
4 Correct 1053 ms 174588 KB Output is correct
5 Correct 1155 ms 173536 KB Output is correct
6 Correct 1016 ms 143628 KB Output is correct
7 Correct 963 ms 142128 KB Output is correct
8 Correct 680 ms 43360 KB Output is correct
9 Correct 1191 ms 174396 KB Output is correct
10 Correct 1138 ms 173528 KB Output is correct
11 Correct 992 ms 143392 KB Output is correct
12 Correct 360 ms 165460 KB Output is correct
13 Correct 447 ms 174556 KB Output is correct
14 Correct 413 ms 173568 KB Output is correct
15 Correct 433 ms 143744 KB Output is correct
16 Correct 1008 ms 135184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19072 KB Output is correct
2 Correct 205 ms 176980 KB Output is correct
3 Correct 212 ms 185180 KB Output is correct
4 Correct 214 ms 179776 KB Output is correct
5 Correct 187 ms 147604 KB Output is correct
6 Correct 104 ms 71028 KB Output is correct
7 Correct 145 ms 95132 KB Output is correct
8 Correct 224 ms 129988 KB Output is correct
9 Correct 191 ms 115432 KB Output is correct
10 Correct 65 ms 39928 KB Output is correct
11 Correct 126 ms 83180 KB Output is correct
12 Correct 209 ms 176984 KB Output is correct
13 Correct 230 ms 185208 KB Output is correct
14 Correct 201 ms 179912 KB Output is correct
15 Correct 182 ms 147528 KB Output is correct
16 Correct 92 ms 65528 KB Output is correct
17 Correct 120 ms 95608 KB Output is correct
18 Correct 198 ms 177508 KB Output is correct
19 Correct 213 ms 181988 KB Output is correct
20 Correct 207 ms 181860 KB Output is correct
21 Correct 190 ms 130148 KB Output is correct
22 Correct 190 ms 115404 KB Output is correct
23 Correct 67 ms 39928 KB Output is correct
24 Correct 142 ms 83012 KB Output is correct
25 Correct 232 ms 176984 KB Output is correct
26 Correct 232 ms 185244 KB Output is correct
27 Correct 210 ms 179832 KB Output is correct
28 Correct 180 ms 147556 KB Output is correct
29 Correct 92 ms 65500 KB Output is correct
30 Correct 124 ms 95516 KB Output is correct
31 Correct 198 ms 177400 KB Output is correct
32 Correct 212 ms 182156 KB Output is correct
33 Correct 206 ms 181860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19200 KB Output is correct
2 Correct 21 ms 19580 KB Output is correct
3 Correct 30 ms 19320 KB Output is correct
4 Correct 20 ms 19320 KB Output is correct
5 Correct 22 ms 19840 KB Output is correct
6 Correct 18 ms 19200 KB Output is correct
7 Correct 20 ms 19200 KB Output is correct
8 Correct 18 ms 19200 KB Output is correct
9 Correct 17 ms 19188 KB Output is correct
10 Correct 17 ms 19200 KB Output is correct
11 Correct 20 ms 19328 KB Output is correct
12 Correct 21 ms 19584 KB Output is correct
13 Correct 20 ms 19840 KB Output is correct
14 Correct 21 ms 20096 KB Output is correct
15 Correct 21 ms 19072 KB Output is correct
16 Correct 18 ms 19072 KB Output is correct
17 Correct 21 ms 19072 KB Output is correct
18 Correct 761 ms 63976 KB Output is correct
19 Correct 232 ms 21880 KB Output is correct
20 Correct 164 ms 20088 KB Output is correct
21 Correct 190 ms 20344 KB Output is correct
22 Correct 202 ms 20892 KB Output is correct
23 Correct 275 ms 21752 KB Output is correct
24 Correct 180 ms 20324 KB Output is correct
25 Correct 173 ms 20748 KB Output is correct
26 Correct 211 ms 21076 KB Output is correct
27 Correct 401 ms 56632 KB Output is correct
28 Correct 355 ms 40440 KB Output is correct
29 Correct 377 ms 54248 KB Output is correct
30 Correct 587 ms 102136 KB Output is correct
31 Correct 25 ms 19192 KB Output is correct
32 Correct 669 ms 56412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19200 KB Output is correct
2 Correct 21 ms 19580 KB Output is correct
3 Correct 30 ms 19320 KB Output is correct
4 Correct 20 ms 19320 KB Output is correct
5 Correct 22 ms 19840 KB Output is correct
6 Correct 18 ms 19200 KB Output is correct
7 Correct 20 ms 19200 KB Output is correct
8 Correct 18 ms 19200 KB Output is correct
9 Correct 17 ms 19188 KB Output is correct
10 Correct 17 ms 19200 KB Output is correct
11 Correct 20 ms 19328 KB Output is correct
12 Correct 21 ms 19584 KB Output is correct
13 Correct 20 ms 19840 KB Output is correct
14 Correct 21 ms 20096 KB Output is correct
15 Correct 21 ms 19072 KB Output is correct
16 Correct 18 ms 19072 KB Output is correct
17 Correct 21 ms 19072 KB Output is correct
18 Correct 761 ms 63976 KB Output is correct
19 Correct 232 ms 21880 KB Output is correct
20 Correct 164 ms 20088 KB Output is correct
21 Correct 190 ms 20344 KB Output is correct
22 Correct 202 ms 20892 KB Output is correct
23 Correct 275 ms 21752 KB Output is correct
24 Correct 180 ms 20324 KB Output is correct
25 Correct 173 ms 20748 KB Output is correct
26 Correct 211 ms 21076 KB Output is correct
27 Correct 401 ms 56632 KB Output is correct
28 Correct 355 ms 40440 KB Output is correct
29 Correct 377 ms 54248 KB Output is correct
30 Correct 587 ms 102136 KB Output is correct
31 Correct 25 ms 19192 KB Output is correct
32 Correct 669 ms 56412 KB Output is correct
33 Correct 205 ms 176980 KB Output is correct
34 Correct 212 ms 185180 KB Output is correct
35 Correct 214 ms 179776 KB Output is correct
36 Correct 187 ms 147604 KB Output is correct
37 Correct 104 ms 71028 KB Output is correct
38 Correct 145 ms 95132 KB Output is correct
39 Correct 224 ms 129988 KB Output is correct
40 Correct 191 ms 115432 KB Output is correct
41 Correct 65 ms 39928 KB Output is correct
42 Correct 126 ms 83180 KB Output is correct
43 Correct 209 ms 176984 KB Output is correct
44 Correct 230 ms 185208 KB Output is correct
45 Correct 201 ms 179912 KB Output is correct
46 Correct 182 ms 147528 KB Output is correct
47 Correct 92 ms 65528 KB Output is correct
48 Correct 120 ms 95608 KB Output is correct
49 Correct 198 ms 177508 KB Output is correct
50 Correct 213 ms 181988 KB Output is correct
51 Correct 207 ms 181860 KB Output is correct
52 Correct 190 ms 130148 KB Output is correct
53 Correct 190 ms 115404 KB Output is correct
54 Correct 67 ms 39928 KB Output is correct
55 Correct 142 ms 83012 KB Output is correct
56 Correct 232 ms 176984 KB Output is correct
57 Correct 232 ms 185244 KB Output is correct
58 Correct 210 ms 179832 KB Output is correct
59 Correct 180 ms 147556 KB Output is correct
60 Correct 92 ms 65500 KB Output is correct
61 Correct 124 ms 95516 KB Output is correct
62 Correct 198 ms 177400 KB Output is correct
63 Correct 212 ms 182156 KB Output is correct
64 Correct 206 ms 181860 KB Output is correct
65 Correct 1195 ms 131004 KB Output is correct
66 Correct 1272 ms 116200 KB Output is correct
67 Correct 488 ms 40660 KB Output is correct
68 Correct 781 ms 83912 KB Output is correct
69 Correct 1187 ms 177800 KB Output is correct
70 Correct 1012 ms 185976 KB Output is correct
71 Correct 968 ms 180600 KB Output is correct
72 Correct 959 ms 148268 KB Output is correct
73 Correct 932 ms 66296 KB Output is correct
74 Correct 958 ms 96248 KB Output is correct
75 Correct 1056 ms 178048 KB Output is correct
76 Correct 1228 ms 182892 KB Output is correct
77 Correct 853 ms 182688 KB Output is correct
78 Correct 900 ms 120296 KB Output is correct
79 Correct 1053 ms 174588 KB Output is correct
80 Correct 1155 ms 173536 KB Output is correct
81 Correct 1016 ms 143628 KB Output is correct
82 Correct 963 ms 142128 KB Output is correct
83 Correct 680 ms 43360 KB Output is correct
84 Correct 1191 ms 174396 KB Output is correct
85 Correct 1138 ms 173528 KB Output is correct
86 Correct 992 ms 143392 KB Output is correct
87 Correct 360 ms 165460 KB Output is correct
88 Correct 447 ms 174556 KB Output is correct
89 Correct 413 ms 173568 KB Output is correct
90 Correct 433 ms 143744 KB Output is correct
91 Correct 1008 ms 135184 KB Output is correct