# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
115465 |
2019-06-07T15:35:14 Z |
구사과(#2864) |
무지개나라 (APIO17_rainbow) |
C++14 |
|
1373 ms |
188788 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(F == 0) return 1;
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 |
26 ms |
19200 KB |
Output is correct |
2 |
Correct |
21 ms |
19584 KB |
Output is correct |
3 |
Correct |
21 ms |
19192 KB |
Output is correct |
4 |
Correct |
23 ms |
19320 KB |
Output is correct |
5 |
Correct |
21 ms |
19712 KB |
Output is correct |
6 |
Correct |
20 ms |
19192 KB |
Output is correct |
7 |
Correct |
17 ms |
19200 KB |
Output is correct |
8 |
Correct |
18 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19200 KB |
Output is correct |
10 |
Correct |
19 ms |
19200 KB |
Output is correct |
11 |
Correct |
20 ms |
19456 KB |
Output is correct |
12 |
Correct |
20 ms |
19584 KB |
Output is correct |
13 |
Correct |
21 ms |
19840 KB |
Output is correct |
14 |
Correct |
21 ms |
20096 KB |
Output is correct |
15 |
Correct |
19 ms |
19200 KB |
Output is correct |
16 |
Correct |
18 ms |
19200 KB |
Output is correct |
17 |
Correct |
18 ms |
19072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19200 KB |
Output is correct |
2 |
Correct |
18 ms |
19072 KB |
Output is correct |
3 |
Correct |
964 ms |
122656 KB |
Output is correct |
4 |
Correct |
1107 ms |
177632 KB |
Output is correct |
5 |
Correct |
1089 ms |
176604 KB |
Output is correct |
6 |
Correct |
970 ms |
146524 KB |
Output is correct |
7 |
Correct |
991 ms |
145028 KB |
Output is correct |
8 |
Correct |
717 ms |
46352 KB |
Output is correct |
9 |
Correct |
1159 ms |
177184 KB |
Output is correct |
10 |
Correct |
1227 ms |
176424 KB |
Output is correct |
11 |
Correct |
1057 ms |
146368 KB |
Output is correct |
12 |
Correct |
478 ms |
168296 KB |
Output is correct |
13 |
Correct |
429 ms |
177568 KB |
Output is correct |
14 |
Correct |
595 ms |
176312 KB |
Output is correct |
15 |
Correct |
391 ms |
146396 KB |
Output is correct |
16 |
Correct |
1012 ms |
137872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
19200 KB |
Output is correct |
2 |
Correct |
264 ms |
176980 KB |
Output is correct |
3 |
Correct |
215 ms |
185324 KB |
Output is correct |
4 |
Correct |
205 ms |
179960 KB |
Output is correct |
5 |
Correct |
186 ms |
147488 KB |
Output is correct |
6 |
Correct |
98 ms |
71108 KB |
Output is correct |
7 |
Correct |
124 ms |
95224 KB |
Output is correct |
8 |
Correct |
195 ms |
130136 KB |
Output is correct |
9 |
Correct |
173 ms |
115488 KB |
Output is correct |
10 |
Correct |
62 ms |
39852 KB |
Output is correct |
11 |
Correct |
131 ms |
83128 KB |
Output is correct |
12 |
Correct |
235 ms |
177052 KB |
Output is correct |
13 |
Correct |
262 ms |
185208 KB |
Output is correct |
14 |
Correct |
235 ms |
180068 KB |
Output is correct |
15 |
Correct |
182 ms |
147548 KB |
Output is correct |
16 |
Correct |
92 ms |
65656 KB |
Output is correct |
17 |
Correct |
126 ms |
95736 KB |
Output is correct |
18 |
Correct |
204 ms |
177400 KB |
Output is correct |
19 |
Correct |
209 ms |
182196 KB |
Output is correct |
20 |
Correct |
221 ms |
182004 KB |
Output is correct |
21 |
Correct |
195 ms |
130144 KB |
Output is correct |
22 |
Correct |
188 ms |
115628 KB |
Output is correct |
23 |
Correct |
61 ms |
39932 KB |
Output is correct |
24 |
Correct |
133 ms |
83284 KB |
Output is correct |
25 |
Correct |
212 ms |
177108 KB |
Output is correct |
26 |
Correct |
237 ms |
185212 KB |
Output is correct |
27 |
Correct |
238 ms |
180036 KB |
Output is correct |
28 |
Correct |
197 ms |
147812 KB |
Output is correct |
29 |
Correct |
95 ms |
65724 KB |
Output is correct |
30 |
Correct |
122 ms |
95608 KB |
Output is correct |
31 |
Correct |
205 ms |
177468 KB |
Output is correct |
32 |
Correct |
211 ms |
182096 KB |
Output is correct |
33 |
Correct |
212 ms |
181988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
19200 KB |
Output is correct |
2 |
Correct |
21 ms |
19584 KB |
Output is correct |
3 |
Correct |
21 ms |
19192 KB |
Output is correct |
4 |
Correct |
23 ms |
19320 KB |
Output is correct |
5 |
Correct |
21 ms |
19712 KB |
Output is correct |
6 |
Correct |
20 ms |
19192 KB |
Output is correct |
7 |
Correct |
17 ms |
19200 KB |
Output is correct |
8 |
Correct |
18 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19200 KB |
Output is correct |
10 |
Correct |
19 ms |
19200 KB |
Output is correct |
11 |
Correct |
20 ms |
19456 KB |
Output is correct |
12 |
Correct |
20 ms |
19584 KB |
Output is correct |
13 |
Correct |
21 ms |
19840 KB |
Output is correct |
14 |
Correct |
21 ms |
20096 KB |
Output is correct |
15 |
Correct |
19 ms |
19200 KB |
Output is correct |
16 |
Correct |
18 ms |
19200 KB |
Output is correct |
17 |
Correct |
18 ms |
19072 KB |
Output is correct |
18 |
Correct |
815 ms |
66824 KB |
Output is correct |
19 |
Correct |
264 ms |
24688 KB |
Output is correct |
20 |
Correct |
194 ms |
22968 KB |
Output is correct |
21 |
Correct |
189 ms |
23160 KB |
Output is correct |
22 |
Correct |
215 ms |
23544 KB |
Output is correct |
23 |
Correct |
227 ms |
24580 KB |
Output is correct |
24 |
Correct |
154 ms |
23132 KB |
Output is correct |
25 |
Correct |
175 ms |
23416 KB |
Output is correct |
26 |
Correct |
197 ms |
23764 KB |
Output is correct |
27 |
Correct |
383 ms |
59388 KB |
Output is correct |
28 |
Correct |
295 ms |
43256 KB |
Output is correct |
29 |
Correct |
388 ms |
56952 KB |
Output is correct |
30 |
Correct |
555 ms |
104796 KB |
Output is correct |
31 |
Correct |
26 ms |
19328 KB |
Output is correct |
32 |
Correct |
656 ms |
59284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
19200 KB |
Output is correct |
2 |
Correct |
21 ms |
19584 KB |
Output is correct |
3 |
Correct |
21 ms |
19192 KB |
Output is correct |
4 |
Correct |
23 ms |
19320 KB |
Output is correct |
5 |
Correct |
21 ms |
19712 KB |
Output is correct |
6 |
Correct |
20 ms |
19192 KB |
Output is correct |
7 |
Correct |
17 ms |
19200 KB |
Output is correct |
8 |
Correct |
18 ms |
19192 KB |
Output is correct |
9 |
Correct |
18 ms |
19200 KB |
Output is correct |
10 |
Correct |
19 ms |
19200 KB |
Output is correct |
11 |
Correct |
20 ms |
19456 KB |
Output is correct |
12 |
Correct |
20 ms |
19584 KB |
Output is correct |
13 |
Correct |
21 ms |
19840 KB |
Output is correct |
14 |
Correct |
21 ms |
20096 KB |
Output is correct |
15 |
Correct |
19 ms |
19200 KB |
Output is correct |
16 |
Correct |
18 ms |
19200 KB |
Output is correct |
17 |
Correct |
18 ms |
19072 KB |
Output is correct |
18 |
Correct |
815 ms |
66824 KB |
Output is correct |
19 |
Correct |
264 ms |
24688 KB |
Output is correct |
20 |
Correct |
194 ms |
22968 KB |
Output is correct |
21 |
Correct |
189 ms |
23160 KB |
Output is correct |
22 |
Correct |
215 ms |
23544 KB |
Output is correct |
23 |
Correct |
227 ms |
24580 KB |
Output is correct |
24 |
Correct |
154 ms |
23132 KB |
Output is correct |
25 |
Correct |
175 ms |
23416 KB |
Output is correct |
26 |
Correct |
197 ms |
23764 KB |
Output is correct |
27 |
Correct |
383 ms |
59388 KB |
Output is correct |
28 |
Correct |
295 ms |
43256 KB |
Output is correct |
29 |
Correct |
388 ms |
56952 KB |
Output is correct |
30 |
Correct |
555 ms |
104796 KB |
Output is correct |
31 |
Correct |
26 ms |
19328 KB |
Output is correct |
32 |
Correct |
656 ms |
59284 KB |
Output is correct |
33 |
Correct |
264 ms |
176980 KB |
Output is correct |
34 |
Correct |
215 ms |
185324 KB |
Output is correct |
35 |
Correct |
205 ms |
179960 KB |
Output is correct |
36 |
Correct |
186 ms |
147488 KB |
Output is correct |
37 |
Correct |
98 ms |
71108 KB |
Output is correct |
38 |
Correct |
124 ms |
95224 KB |
Output is correct |
39 |
Correct |
195 ms |
130136 KB |
Output is correct |
40 |
Correct |
173 ms |
115488 KB |
Output is correct |
41 |
Correct |
62 ms |
39852 KB |
Output is correct |
42 |
Correct |
131 ms |
83128 KB |
Output is correct |
43 |
Correct |
235 ms |
177052 KB |
Output is correct |
44 |
Correct |
262 ms |
185208 KB |
Output is correct |
45 |
Correct |
235 ms |
180068 KB |
Output is correct |
46 |
Correct |
182 ms |
147548 KB |
Output is correct |
47 |
Correct |
92 ms |
65656 KB |
Output is correct |
48 |
Correct |
126 ms |
95736 KB |
Output is correct |
49 |
Correct |
204 ms |
177400 KB |
Output is correct |
50 |
Correct |
209 ms |
182196 KB |
Output is correct |
51 |
Correct |
221 ms |
182004 KB |
Output is correct |
52 |
Correct |
195 ms |
130144 KB |
Output is correct |
53 |
Correct |
188 ms |
115628 KB |
Output is correct |
54 |
Correct |
61 ms |
39932 KB |
Output is correct |
55 |
Correct |
133 ms |
83284 KB |
Output is correct |
56 |
Correct |
212 ms |
177108 KB |
Output is correct |
57 |
Correct |
237 ms |
185212 KB |
Output is correct |
58 |
Correct |
238 ms |
180036 KB |
Output is correct |
59 |
Correct |
197 ms |
147812 KB |
Output is correct |
60 |
Correct |
95 ms |
65724 KB |
Output is correct |
61 |
Correct |
122 ms |
95608 KB |
Output is correct |
62 |
Correct |
205 ms |
177468 KB |
Output is correct |
63 |
Correct |
211 ms |
182096 KB |
Output is correct |
64 |
Correct |
212 ms |
181988 KB |
Output is correct |
65 |
Correct |
1339 ms |
133692 KB |
Output is correct |
66 |
Correct |
1373 ms |
118900 KB |
Output is correct |
67 |
Correct |
515 ms |
43416 KB |
Output is correct |
68 |
Correct |
774 ms |
86648 KB |
Output is correct |
69 |
Correct |
1258 ms |
180596 KB |
Output is correct |
70 |
Correct |
1050 ms |
188788 KB |
Output is correct |
71 |
Correct |
1079 ms |
183528 KB |
Output is correct |
72 |
Correct |
1083 ms |
151148 KB |
Output is correct |
73 |
Correct |
993 ms |
69108 KB |
Output is correct |
74 |
Correct |
898 ms |
99252 KB |
Output is correct |
75 |
Correct |
967 ms |
180964 KB |
Output is correct |
76 |
Correct |
1192 ms |
185592 KB |
Output is correct |
77 |
Correct |
890 ms |
185468 KB |
Output is correct |
78 |
Correct |
964 ms |
122656 KB |
Output is correct |
79 |
Correct |
1107 ms |
177632 KB |
Output is correct |
80 |
Correct |
1089 ms |
176604 KB |
Output is correct |
81 |
Correct |
970 ms |
146524 KB |
Output is correct |
82 |
Correct |
991 ms |
145028 KB |
Output is correct |
83 |
Correct |
717 ms |
46352 KB |
Output is correct |
84 |
Correct |
1159 ms |
177184 KB |
Output is correct |
85 |
Correct |
1227 ms |
176424 KB |
Output is correct |
86 |
Correct |
1057 ms |
146368 KB |
Output is correct |
87 |
Correct |
478 ms |
168296 KB |
Output is correct |
88 |
Correct |
429 ms |
177568 KB |
Output is correct |
89 |
Correct |
595 ms |
176312 KB |
Output is correct |
90 |
Correct |
391 ms |
146396 KB |
Output is correct |
91 |
Correct |
1012 ms |
137872 KB |
Output is correct |