#include<bits/stdc++.h>
#include "rainbow.h"
#define MAXN 200007
using namespace std;
const int maxs=2e5+7;
struct PST{
struct node{
int l,r;
int val;
};
int root[MAXN],last,num=1;
node tree[20*MAXN];
void upgrade(){
last++; root[last]=num;
}
int update(int v,int l,int r,int pos){
if(l==r){
num++;
tree[num].val=tree[v].val+1;
return num;
}else{
int tt=(l+r)/2;
int lt,rt;
if(pos<=tt){
lt=update(tree[v].l,l,tt,pos);
rt=tree[v].r;
}else{
lt=tree[v].l;
rt=update(tree[v].r,tt+1,r,pos);
}
num++;
tree[num].val=tree[lt].val+tree[rt].val;
tree[num].l=lt; tree[num].r=rt;
return num;
}
}
int getsum(int v1,int v2,int l,int r,int ll,int rr){
if(ll>rr)return 0;
if(l==ll and r==rr){
return tree[v2].val-tree[v1].val;
}else{
int tt=(l+r)/2;
return getsum(tree[v1].l,tree[v2].l,l,tt,ll,min(tt,rr)) + getsum(tree[v1].r,tree[v2].r,tt+1,r,max(tt+1,ll),rr);
}
}
void build(set< pair<int,int> > &s){
auto it=s.begin();
for(int i=1;i<=maxs;i++){
while(it!=s.end()){
pair<int,int> curr=*it;
if(curr.first==i)update(num,1,maxs,curr.second);
else break;
it++;
}
upgrade();
}
}
int query(int a,int c,int b,int d){
return getsum(root[a-1],root[c],1,maxs,b,d);
}
}rivers,vertices,edgesh,edgesv;
int n,m,x,y,minx,miny,maxx,maxy;
set< pair<int,int> > ver,eh,ev,riv;
void add(int x,int y){
ver.insert({x,y});
ver.insert({x+1,y});
ver.insert({x,y+1});
ver.insert({x+1,y+1});
riv.insert({x,y});
ev.insert({x,y});
ev.insert({x,y+1});
eh.insert({x,y});
eh.insert({x+1,y});
}
void init(int R, int C, int sr, int sc, int M, char *S) {
n=R; m=C;
x=sr; y=sc;
add(x,y);
minx=maxx=x;
miny=maxy=y;
for(int i=0;i<M;i++){
if(S[i]=='N')x--;
if(S[i]=='S')x++;
if(S[i]=='E')y++;
if(S[i]=='W')y--;
add(x,y);
minx=min(minx,x);
miny=min(miny,y);
maxx=max(maxx,x);
maxy=max(maxy,y);
}
rivers.build(riv);
edgesh.build(eh);
edgesv.build(ev);
vertices.build(ver);
}
int colour(int ar,int ac,int br,int bc){
int R=rivers.query(ar,br,ac,bc);
int V=vertices.query(ar+1,br,ac+1,bc) + 2*(bc-ac+2) + 2*(br-ar+2) - 4;
int E=edgesv.query(ar,br,ac+1,bc) + edgesh.query(ar+1,br,ac,bc) + 2*(bc-ac+1) + 2*(br-ar+1) ;
if(minx>ar and maxx<br and miny>ac and maxy<bc)E++;
return E-V-R+1;
}
/*int main(){
init(6, 4,3, 3, 9,"NWESSWEWS");
cout<<colour(2,3, 2, 3)<<"\n";
cout<<colour(3,2,4,4)<<"\n";
cout<<colour(5,3,6,4)<<"\n";
cout<<colour(1,2,5,3)<<"\n";
cout<<colour(1,1,6,4)<<":\n";
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3672 KB |
Output is correct |
2 |
Correct |
6 ms |
4700 KB |
Output is correct |
3 |
Correct |
3 ms |
3928 KB |
Output is correct |
4 |
Correct |
6 ms |
4140 KB |
Output is correct |
5 |
Correct |
5 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
4 ms |
3932 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
5 ms |
5628 KB |
Output is correct |
14 |
Correct |
7 ms |
5980 KB |
Output is correct |
15 |
Correct |
2 ms |
3404 KB |
Output is correct |
16 |
Correct |
2 ms |
3420 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3420 KB |
Output is correct |
2 |
Correct |
2 ms |
3420 KB |
Output is correct |
3 |
Correct |
341 ms |
102292 KB |
Output is correct |
4 |
Correct |
494 ms |
166848 KB |
Output is correct |
5 |
Correct |
482 ms |
165712 KB |
Output is correct |
6 |
Correct |
449 ms |
129248 KB |
Output is correct |
7 |
Correct |
489 ms |
127056 KB |
Output is correct |
8 |
Correct |
154 ms |
7252 KB |
Output is correct |
9 |
Correct |
519 ms |
166868 KB |
Output is correct |
10 |
Correct |
540 ms |
165608 KB |
Output is correct |
11 |
Correct |
418 ms |
129108 KB |
Output is correct |
12 |
Correct |
324 ms |
155520 KB |
Output is correct |
13 |
Correct |
323 ms |
166736 KB |
Output is correct |
14 |
Correct |
341 ms |
165588 KB |
Output is correct |
15 |
Correct |
352 ms |
129276 KB |
Output is correct |
16 |
Correct |
360 ms |
119976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3404 KB |
Output is correct |
2 |
Correct |
282 ms |
163800 KB |
Output is correct |
3 |
Correct |
238 ms |
163412 KB |
Output is correct |
4 |
Correct |
253 ms |
163412 KB |
Output is correct |
5 |
Correct |
187 ms |
122196 KB |
Output is correct |
6 |
Correct |
78 ms |
33652 KB |
Output is correct |
7 |
Correct |
143 ms |
63280 KB |
Output is correct |
8 |
Correct |
230 ms |
146260 KB |
Output is correct |
9 |
Correct |
219 ms |
130260 KB |
Output is correct |
10 |
Correct |
68 ms |
35084 KB |
Output is correct |
11 |
Correct |
153 ms |
82000 KB |
Output is correct |
12 |
Correct |
300 ms |
163432 KB |
Output is correct |
13 |
Correct |
225 ms |
163412 KB |
Output is correct |
14 |
Correct |
280 ms |
163620 KB |
Output is correct |
15 |
Correct |
179 ms |
122312 KB |
Output is correct |
16 |
Correct |
69 ms |
27604 KB |
Output is correct |
17 |
Correct |
145 ms |
63280 KB |
Output is correct |
18 |
Correct |
222 ms |
163412 KB |
Output is correct |
19 |
Correct |
281 ms |
164692 KB |
Output is correct |
20 |
Correct |
238 ms |
164436 KB |
Output is correct |
21 |
Correct |
242 ms |
146208 KB |
Output is correct |
22 |
Correct |
216 ms |
130084 KB |
Output is correct |
23 |
Correct |
67 ms |
35244 KB |
Output is correct |
24 |
Correct |
155 ms |
82060 KB |
Output is correct |
25 |
Correct |
309 ms |
163408 KB |
Output is correct |
26 |
Correct |
240 ms |
163412 KB |
Output is correct |
27 |
Correct |
268 ms |
163520 KB |
Output is correct |
28 |
Correct |
195 ms |
122224 KB |
Output is correct |
29 |
Correct |
73 ms |
27580 KB |
Output is correct |
30 |
Correct |
151 ms |
63284 KB |
Output is correct |
31 |
Correct |
251 ms |
163632 KB |
Output is correct |
32 |
Correct |
252 ms |
164692 KB |
Output is correct |
33 |
Correct |
253 ms |
164460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3672 KB |
Output is correct |
2 |
Correct |
6 ms |
4700 KB |
Output is correct |
3 |
Correct |
3 ms |
3928 KB |
Output is correct |
4 |
Correct |
6 ms |
4140 KB |
Output is correct |
5 |
Correct |
5 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
4 ms |
3932 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
5 ms |
5628 KB |
Output is correct |
14 |
Correct |
7 ms |
5980 KB |
Output is correct |
15 |
Correct |
2 ms |
3404 KB |
Output is correct |
16 |
Correct |
2 ms |
3420 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
358 ms |
87632 KB |
Output is correct |
19 |
Correct |
117 ms |
10612 KB |
Output is correct |
20 |
Correct |
110 ms |
7508 KB |
Output is correct |
21 |
Correct |
102 ms |
8080 KB |
Output is correct |
22 |
Correct |
118 ms |
8784 KB |
Output is correct |
23 |
Correct |
115 ms |
10320 KB |
Output is correct |
24 |
Correct |
89 ms |
7928 KB |
Output is correct |
25 |
Correct |
97 ms |
8784 KB |
Output is correct |
26 |
Correct |
146 ms |
9296 KB |
Output is correct |
27 |
Correct |
269 ms |
72272 KB |
Output is correct |
28 |
Correct |
210 ms |
38480 KB |
Output is correct |
29 |
Correct |
334 ms |
66548 KB |
Output is correct |
30 |
Correct |
456 ms |
166980 KB |
Output is correct |
31 |
Correct |
5 ms |
3672 KB |
Output is correct |
32 |
Correct |
370 ms |
73132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3672 KB |
Output is correct |
2 |
Correct |
6 ms |
4700 KB |
Output is correct |
3 |
Correct |
3 ms |
3928 KB |
Output is correct |
4 |
Correct |
6 ms |
4140 KB |
Output is correct |
5 |
Correct |
5 ms |
4952 KB |
Output is correct |
6 |
Correct |
2 ms |
3420 KB |
Output is correct |
7 |
Correct |
2 ms |
3420 KB |
Output is correct |
8 |
Correct |
2 ms |
3420 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
4 ms |
3932 KB |
Output is correct |
12 |
Correct |
4 ms |
4444 KB |
Output is correct |
13 |
Correct |
5 ms |
5628 KB |
Output is correct |
14 |
Correct |
7 ms |
5980 KB |
Output is correct |
15 |
Correct |
2 ms |
3404 KB |
Output is correct |
16 |
Correct |
2 ms |
3420 KB |
Output is correct |
17 |
Correct |
2 ms |
3420 KB |
Output is correct |
18 |
Correct |
358 ms |
87632 KB |
Output is correct |
19 |
Correct |
117 ms |
10612 KB |
Output is correct |
20 |
Correct |
110 ms |
7508 KB |
Output is correct |
21 |
Correct |
102 ms |
8080 KB |
Output is correct |
22 |
Correct |
118 ms |
8784 KB |
Output is correct |
23 |
Correct |
115 ms |
10320 KB |
Output is correct |
24 |
Correct |
89 ms |
7928 KB |
Output is correct |
25 |
Correct |
97 ms |
8784 KB |
Output is correct |
26 |
Correct |
146 ms |
9296 KB |
Output is correct |
27 |
Correct |
269 ms |
72272 KB |
Output is correct |
28 |
Correct |
210 ms |
38480 KB |
Output is correct |
29 |
Correct |
334 ms |
66548 KB |
Output is correct |
30 |
Correct |
456 ms |
166980 KB |
Output is correct |
31 |
Correct |
5 ms |
3672 KB |
Output is correct |
32 |
Correct |
370 ms |
73132 KB |
Output is correct |
33 |
Correct |
282 ms |
163800 KB |
Output is correct |
34 |
Correct |
238 ms |
163412 KB |
Output is correct |
35 |
Correct |
253 ms |
163412 KB |
Output is correct |
36 |
Correct |
187 ms |
122196 KB |
Output is correct |
37 |
Correct |
78 ms |
33652 KB |
Output is correct |
38 |
Correct |
143 ms |
63280 KB |
Output is correct |
39 |
Correct |
230 ms |
146260 KB |
Output is correct |
40 |
Correct |
219 ms |
130260 KB |
Output is correct |
41 |
Correct |
68 ms |
35084 KB |
Output is correct |
42 |
Correct |
153 ms |
82000 KB |
Output is correct |
43 |
Correct |
300 ms |
163432 KB |
Output is correct |
44 |
Correct |
225 ms |
163412 KB |
Output is correct |
45 |
Correct |
280 ms |
163620 KB |
Output is correct |
46 |
Correct |
179 ms |
122312 KB |
Output is correct |
47 |
Correct |
69 ms |
27604 KB |
Output is correct |
48 |
Correct |
145 ms |
63280 KB |
Output is correct |
49 |
Correct |
222 ms |
163412 KB |
Output is correct |
50 |
Correct |
281 ms |
164692 KB |
Output is correct |
51 |
Correct |
238 ms |
164436 KB |
Output is correct |
52 |
Correct |
242 ms |
146208 KB |
Output is correct |
53 |
Correct |
216 ms |
130084 KB |
Output is correct |
54 |
Correct |
67 ms |
35244 KB |
Output is correct |
55 |
Correct |
155 ms |
82060 KB |
Output is correct |
56 |
Correct |
309 ms |
163408 KB |
Output is correct |
57 |
Correct |
240 ms |
163412 KB |
Output is correct |
58 |
Correct |
268 ms |
163520 KB |
Output is correct |
59 |
Correct |
195 ms |
122224 KB |
Output is correct |
60 |
Correct |
73 ms |
27580 KB |
Output is correct |
61 |
Correct |
151 ms |
63284 KB |
Output is correct |
62 |
Correct |
251 ms |
163632 KB |
Output is correct |
63 |
Correct |
252 ms |
164692 KB |
Output is correct |
64 |
Correct |
253 ms |
164460 KB |
Output is correct |
65 |
Correct |
341 ms |
102292 KB |
Output is correct |
66 |
Correct |
494 ms |
166848 KB |
Output is correct |
67 |
Correct |
482 ms |
165712 KB |
Output is correct |
68 |
Correct |
449 ms |
129248 KB |
Output is correct |
69 |
Correct |
489 ms |
127056 KB |
Output is correct |
70 |
Correct |
154 ms |
7252 KB |
Output is correct |
71 |
Correct |
519 ms |
166868 KB |
Output is correct |
72 |
Correct |
540 ms |
165608 KB |
Output is correct |
73 |
Correct |
418 ms |
129108 KB |
Output is correct |
74 |
Correct |
324 ms |
155520 KB |
Output is correct |
75 |
Correct |
323 ms |
166736 KB |
Output is correct |
76 |
Correct |
341 ms |
165588 KB |
Output is correct |
77 |
Correct |
352 ms |
129276 KB |
Output is correct |
78 |
Correct |
360 ms |
119976 KB |
Output is correct |
79 |
Correct |
590 ms |
149824 KB |
Output is correct |
80 |
Correct |
552 ms |
133712 KB |
Output is correct |
81 |
Correct |
217 ms |
38736 KB |
Output is correct |
82 |
Correct |
306 ms |
85352 KB |
Output is correct |
83 |
Correct |
534 ms |
166992 KB |
Output is correct |
84 |
Correct |
404 ms |
166740 KB |
Output is correct |
85 |
Correct |
430 ms |
167096 KB |
Output is correct |
86 |
Correct |
341 ms |
125884 KB |
Output is correct |
87 |
Correct |
214 ms |
31000 KB |
Output is correct |
88 |
Correct |
294 ms |
66900 KB |
Output is correct |
89 |
Correct |
378 ms |
166996 KB |
Output is correct |
90 |
Correct |
485 ms |
168024 KB |
Output is correct |
91 |
Correct |
454 ms |
168004 KB |
Output is correct |