답안 #184027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
184027 2020-01-10T11:26:40 Z oolimry 무지개나라 (APIO17_rainbow) C++14
100 / 100
1184 ms 99176 KB
#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 200002; int totalRivers;
struct segment{
	vector<int> tree[2*N+5];
	inline void update(int i, int v){ tree[i+N].push_back(v); }
	inline void getReady(){
		for(int i = N;i < 2*N;i++){
			sort(tree[i].begin(),tree[i].end());
			tree[i].erase(unique(tree[i].begin(),tree[i].end()),tree[i].end());
		}
		for(int i = N-1;i > 0;i--){ ///basically merge sort
			tree[i] = vector<int>(tree[i<<1].size()+tree[i<<1|1].size());
			merge(tree[i<<1].begin(),tree[i<<1].end(), tree[i<<1|1].begin(),tree[i<<1|1].end(),tree[i].begin());
		}
	}
	inline int query(int l, int r, int x, int y){ 
		int ans = 0;
		for(l += N, r += (N+1);l < r;l >>= 1, r >>= 1){
			if(l&1) ans += upper_bound(tree[l].begin(),tree[l].end(),y) - lower_bound(tree[l].begin(),tree[l].end(),x), l++;
			if(r&1) r--, ans += upper_bound(tree[r].begin(),tree[r].end(),y) - lower_bound(tree[r].begin(),tree[r].end(),x);
		}
		return ans;
	}
} vertices, horizontal, vertical, faces;
void addRiver(int r, int c){
	vertices.update(r,c);
	horizontal.update(r,c-1); horizontal.update(r,c);
	vertical.update(c,r-1); vertical.update(c,r);
	faces.update(r-1,c-1); faces.update(r,c-1); faces.update(r-1,c); faces.update(r,c);
}
void init(int R, int C, int sr, int sc, int M, char *S) {
	addRiver(sr,sc);
	for(int i = 0;i < M;i++){
		if(S[i] == 'N') sr--; else if(S[i] == 'S') sr++; else if(S[i] == 'E') sc++; else sc--;
		addRiver(sr,sc);
	}
	vertices.getReady(); horizontal.getReady(); vertical.getReady(); faces.getReady();
	totalRivers = vertices.query(0,N-1,0,N-1);
}
int colour(int T, int L, int B, int R) {
	long long H = B - T + 1, W = R - L + 1;
	long long V = H * W - vertices.query(T,B,L,R);
	long long E = (H-1)*W + (W-1)*H - horizontal.query(T,B,L,R-1) - vertical.query(L,R,T,B-1);
	long long F = (H-1)*(W-1) - faces.query(T,B-1,L,R-1);
	if(vertices.query(T+1,B-1,L+1,R-1) == totalRivers) F++;
	return V - E + F;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 38132 KB Output is correct
2 Correct 48 ms 38264 KB Output is correct
3 Correct 49 ms 38136 KB Output is correct
4 Correct 55 ms 38136 KB Output is correct
5 Correct 54 ms 38520 KB Output is correct
6 Correct 46 ms 37852 KB Output is correct
7 Correct 44 ms 37880 KB Output is correct
8 Correct 44 ms 37880 KB Output is correct
9 Correct 54 ms 37880 KB Output is correct
10 Correct 54 ms 37880 KB Output is correct
11 Correct 58 ms 38264 KB Output is correct
12 Correct 58 ms 38264 KB Output is correct
13 Correct 66 ms 38492 KB Output is correct
14 Correct 69 ms 38748 KB Output is correct
15 Correct 45 ms 37880 KB Output is correct
16 Correct 44 ms 37880 KB Output is correct
17 Correct 44 ms 37880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 37880 KB Output is correct
2 Correct 44 ms 37880 KB Output is correct
3 Correct 334 ms 69848 KB Output is correct
4 Correct 467 ms 89336 KB Output is correct
5 Correct 429 ms 88468 KB Output is correct
6 Correct 336 ms 77428 KB Output is correct
7 Correct 388 ms 77136 KB Output is correct
8 Correct 168 ms 45920 KB Output is correct
9 Correct 507 ms 89312 KB Output is correct
10 Correct 550 ms 88448 KB Output is correct
11 Correct 384 ms 77580 KB Output is correct
12 Correct 216 ms 85720 KB Output is correct
13 Correct 238 ms 89392 KB Output is correct
14 Correct 247 ms 88288 KB Output is correct
15 Correct 229 ms 77364 KB Output is correct
16 Correct 320 ms 75104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 37880 KB Output is correct
2 Correct 132 ms 87836 KB Output is correct
3 Correct 166 ms 95504 KB Output is correct
4 Correct 147 ms 88000 KB Output is correct
5 Correct 141 ms 78800 KB Output is correct
6 Correct 99 ms 51064 KB Output is correct
7 Correct 107 ms 58872 KB Output is correct
8 Correct 173 ms 79152 KB Output is correct
9 Correct 128 ms 74860 KB Output is correct
10 Correct 90 ms 48464 KB Output is correct
11 Correct 123 ms 63584 KB Output is correct
12 Correct 130 ms 87756 KB Output is correct
13 Correct 186 ms 95520 KB Output is correct
14 Correct 168 ms 87800 KB Output is correct
15 Correct 139 ms 78892 KB Output is correct
16 Correct 92 ms 49328 KB Output is correct
17 Correct 119 ms 58212 KB Output is correct
18 Correct 127 ms 83084 KB Output is correct
19 Correct 146 ms 89428 KB Output is correct
20 Correct 144 ms 89440 KB Output is correct
21 Correct 129 ms 79136 KB Output is correct
22 Correct 126 ms 74960 KB Output is correct
23 Correct 87 ms 48500 KB Output is correct
24 Correct 117 ms 63528 KB Output is correct
25 Correct 129 ms 87756 KB Output is correct
26 Correct 168 ms 95504 KB Output is correct
27 Correct 140 ms 87900 KB Output is correct
28 Correct 126 ms 78916 KB Output is correct
29 Correct 96 ms 49336 KB Output is correct
30 Correct 100 ms 58340 KB Output is correct
31 Correct 125 ms 82948 KB Output is correct
32 Correct 151 ms 89364 KB Output is correct
33 Correct 142 ms 89412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 38132 KB Output is correct
2 Correct 48 ms 38264 KB Output is correct
3 Correct 49 ms 38136 KB Output is correct
4 Correct 55 ms 38136 KB Output is correct
5 Correct 54 ms 38520 KB Output is correct
6 Correct 46 ms 37852 KB Output is correct
7 Correct 44 ms 37880 KB Output is correct
8 Correct 44 ms 37880 KB Output is correct
9 Correct 54 ms 37880 KB Output is correct
10 Correct 54 ms 37880 KB Output is correct
11 Correct 58 ms 38264 KB Output is correct
12 Correct 58 ms 38264 KB Output is correct
13 Correct 66 ms 38492 KB Output is correct
14 Correct 69 ms 38748 KB Output is correct
15 Correct 45 ms 37880 KB Output is correct
16 Correct 44 ms 37880 KB Output is correct
17 Correct 44 ms 37880 KB Output is correct
18 Correct 1184 ms 66676 KB Output is correct
19 Correct 285 ms 42448 KB Output is correct
20 Correct 253 ms 41572 KB Output is correct
21 Correct 246 ms 41604 KB Output is correct
22 Correct 269 ms 42020 KB Output is correct
23 Correct 238 ms 42360 KB Output is correct
24 Correct 316 ms 41840 KB Output is correct
25 Correct 314 ms 42128 KB Output is correct
26 Correct 296 ms 42288 KB Output is correct
27 Correct 508 ms 62980 KB Output is correct
28 Correct 496 ms 54276 KB Output is correct
29 Correct 514 ms 61700 KB Output is correct
30 Correct 890 ms 86356 KB Output is correct
31 Correct 48 ms 38008 KB Output is correct
32 Correct 969 ms 62800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 38132 KB Output is correct
2 Correct 48 ms 38264 KB Output is correct
3 Correct 49 ms 38136 KB Output is correct
4 Correct 55 ms 38136 KB Output is correct
5 Correct 54 ms 38520 KB Output is correct
6 Correct 46 ms 37852 KB Output is correct
7 Correct 44 ms 37880 KB Output is correct
8 Correct 44 ms 37880 KB Output is correct
9 Correct 54 ms 37880 KB Output is correct
10 Correct 54 ms 37880 KB Output is correct
11 Correct 58 ms 38264 KB Output is correct
12 Correct 58 ms 38264 KB Output is correct
13 Correct 66 ms 38492 KB Output is correct
14 Correct 69 ms 38748 KB Output is correct
15 Correct 45 ms 37880 KB Output is correct
16 Correct 44 ms 37880 KB Output is correct
17 Correct 44 ms 37880 KB Output is correct
18 Correct 1184 ms 66676 KB Output is correct
19 Correct 285 ms 42448 KB Output is correct
20 Correct 253 ms 41572 KB Output is correct
21 Correct 246 ms 41604 KB Output is correct
22 Correct 269 ms 42020 KB Output is correct
23 Correct 238 ms 42360 KB Output is correct
24 Correct 316 ms 41840 KB Output is correct
25 Correct 314 ms 42128 KB Output is correct
26 Correct 296 ms 42288 KB Output is correct
27 Correct 508 ms 62980 KB Output is correct
28 Correct 496 ms 54276 KB Output is correct
29 Correct 514 ms 61700 KB Output is correct
30 Correct 890 ms 86356 KB Output is correct
31 Correct 48 ms 38008 KB Output is correct
32 Correct 969 ms 62800 KB Output is correct
33 Correct 132 ms 87836 KB Output is correct
34 Correct 166 ms 95504 KB Output is correct
35 Correct 147 ms 88000 KB Output is correct
36 Correct 141 ms 78800 KB Output is correct
37 Correct 99 ms 51064 KB Output is correct
38 Correct 107 ms 58872 KB Output is correct
39 Correct 173 ms 79152 KB Output is correct
40 Correct 128 ms 74860 KB Output is correct
41 Correct 90 ms 48464 KB Output is correct
42 Correct 123 ms 63584 KB Output is correct
43 Correct 130 ms 87756 KB Output is correct
44 Correct 186 ms 95520 KB Output is correct
45 Correct 168 ms 87800 KB Output is correct
46 Correct 139 ms 78892 KB Output is correct
47 Correct 92 ms 49328 KB Output is correct
48 Correct 119 ms 58212 KB Output is correct
49 Correct 127 ms 83084 KB Output is correct
50 Correct 146 ms 89428 KB Output is correct
51 Correct 144 ms 89440 KB Output is correct
52 Correct 129 ms 79136 KB Output is correct
53 Correct 126 ms 74960 KB Output is correct
54 Correct 87 ms 48500 KB Output is correct
55 Correct 117 ms 63528 KB Output is correct
56 Correct 129 ms 87756 KB Output is correct
57 Correct 168 ms 95504 KB Output is correct
58 Correct 140 ms 87900 KB Output is correct
59 Correct 126 ms 78916 KB Output is correct
60 Correct 96 ms 49336 KB Output is correct
61 Correct 100 ms 58340 KB Output is correct
62 Correct 125 ms 82948 KB Output is correct
63 Correct 151 ms 89364 KB Output is correct
64 Correct 142 ms 89412 KB Output is correct
65 Correct 654 ms 82644 KB Output is correct
66 Correct 773 ms 78412 KB Output is correct
67 Correct 495 ms 52136 KB Output is correct
68 Correct 683 ms 67108 KB Output is correct
69 Correct 548 ms 91468 KB Output is correct
70 Correct 840 ms 99176 KB Output is correct
71 Correct 538 ms 91512 KB Output is correct
72 Correct 582 ms 82572 KB Output is correct
73 Correct 353 ms 52848 KB Output is correct
74 Correct 373 ms 61732 KB Output is correct
75 Correct 375 ms 86672 KB Output is correct
76 Correct 727 ms 93064 KB Output is correct
77 Correct 839 ms 92980 KB Output is correct
78 Correct 334 ms 69848 KB Output is correct
79 Correct 467 ms 89336 KB Output is correct
80 Correct 429 ms 88468 KB Output is correct
81 Correct 336 ms 77428 KB Output is correct
82 Correct 388 ms 77136 KB Output is correct
83 Correct 168 ms 45920 KB Output is correct
84 Correct 507 ms 89312 KB Output is correct
85 Correct 550 ms 88448 KB Output is correct
86 Correct 384 ms 77580 KB Output is correct
87 Correct 216 ms 85720 KB Output is correct
88 Correct 238 ms 89392 KB Output is correct
89 Correct 247 ms 88288 KB Output is correct
90 Correct 229 ms 77364 KB Output is correct
91 Correct 320 ms 75104 KB Output is correct