#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
int kaf=(1<<18);
struct segment{
vector<int>all[maxn];
void add(int r,int c){
all[r].push_back(c);
}
struct node{
int lc,rc,sum;
node(){
lc=rc=sum=0;
}
};
node seg[(1<<19)*15];
int root[maxn],rt=0,nx=1;
void calc(int i){
seg[i].sum=seg[seg[i].lc].sum+seg[seg[i].rc].sum;
}
int ins(int i,int l,int r,int tl,int tr,int w){
if(l>r||l>tr||r<tl||tl>tr){
return i;
}
int now=nx;
seg[nx]=seg[i];
nx++;
if(l>=tl&&r<=tr){
seg[nx-1].sum+=w;
return nx-1;
}
int m=(l+r)>>1;
seg[now].lc=ins(seg[now].lc,l,m,tl,tr,w);
seg[now].rc=ins(seg[now].rc,m+1,r,tl,tr,w);
calc(now);
return now;
}
int get(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return 0;
}
if(l>=tl&&r<=tr){
return seg[i].sum;
}
int m=(l+r)>>1;
return get(seg[i].lc,l,m,tl,tr)+get(seg[i].rc,m+1,r,tl,tr);
}
int pors(int top,int bot,int tr,int tl){
//cout<<"get: "<<get(root[top],0,kaf-1,tl,tr)<<" hehe "<<get(root[bot-1],0,kaf-1,tl,tr)<<endl;
return get(root[top],0,kaf-1,tl,tr)-get(root[bot-1],0,kaf-1,tl,tr);
}
void build(){
for(int i=0;i<maxn;i++){
sort(all[i].begin(),all[i].end());
all[i].resize(unique(all[i].begin(),all[i].end())-all[i].begin());
for(auto x:all[i]){
rt=ins(rt,0,kaf-1,x,x,1);
}
root[i]=rt;
}
}
}segv,segeo,segea,segr;
int mxr=-1,mxc=-1,mnr=maxn+10,mnc=maxn+10;
void add(int r,int c){
//cout<<"addy: "<<r<<" "<<c<<endl;
mnr=min(mnr,r);
mxr=max(mxr,r);
mnc=min(mnc,c);
mxc=max(mxc,c);
segv.add(r,c);
segv.add(r,c+1);
segv.add(r+1,c);
segv.add(r+1,c+1);
segeo.add(r,c);
segeo.add(r+1,c);
segea.add(r,c);
segea.add(r,c+1);
segr.add(r,c);
}
void build(){
segv.build();
segeo.build();
segea.build();
segr.build();
}
void init(int R, int C, int sr, int sc, int M, char *S) {
add(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--;
}
add(sr,sc);
}
build();
}
int colour(int ar, int ac, int br, int bc) {
int v=segv.pors(br,ar+1,bc,ac+1)+(br-ar+2)*2+(bc-ac)*2;
int c=1;
int e=segeo.pors(br,ar+1,bc,ac)+segea.pors(br,ar,bc,ac+1)+(br-ar+1)*2+(bc-ac+1)*2;
int r=segr.pors(br,ar,bc,ac);
if(mnr>ar&&mxr<br&&mnc>ac&&mxc<bc){
c++;
}
int res=e-v+1+c-r-1;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
391504 KB |
Output is correct |
2 |
Correct |
123 ms |
391688 KB |
Output is correct |
3 |
Correct |
122 ms |
391472 KB |
Output is correct |
4 |
Correct |
123 ms |
391572 KB |
Output is correct |
5 |
Correct |
125 ms |
392020 KB |
Output is correct |
6 |
Correct |
125 ms |
391460 KB |
Output is correct |
7 |
Correct |
120 ms |
391696 KB |
Output is correct |
8 |
Correct |
126 ms |
391504 KB |
Output is correct |
9 |
Correct |
123 ms |
391680 KB |
Output is correct |
10 |
Correct |
122 ms |
391504 KB |
Output is correct |
11 |
Correct |
121 ms |
391648 KB |
Output is correct |
12 |
Correct |
123 ms |
391764 KB |
Output is correct |
13 |
Correct |
127 ms |
391784 KB |
Output is correct |
14 |
Correct |
128 ms |
391788 KB |
Output is correct |
15 |
Correct |
123 ms |
391668 KB |
Output is correct |
16 |
Correct |
125 ms |
391536 KB |
Output is correct |
17 |
Correct |
116 ms |
391532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
391536 KB |
Output is correct |
2 |
Correct |
116 ms |
391532 KB |
Output is correct |
3 |
Correct |
451 ms |
395240 KB |
Output is correct |
4 |
Correct |
564 ms |
396688 KB |
Output is correct |
5 |
Correct |
568 ms |
396468 KB |
Output is correct |
6 |
Correct |
539 ms |
396668 KB |
Output is correct |
7 |
Correct |
530 ms |
396912 KB |
Output is correct |
8 |
Correct |
349 ms |
396676 KB |
Output is correct |
9 |
Correct |
558 ms |
396580 KB |
Output is correct |
10 |
Correct |
577 ms |
396500 KB |
Output is correct |
11 |
Correct |
521 ms |
396752 KB |
Output is correct |
12 |
Correct |
387 ms |
396728 KB |
Output is correct |
13 |
Correct |
416 ms |
396472 KB |
Output is correct |
14 |
Correct |
416 ms |
396728 KB |
Output is correct |
15 |
Correct |
382 ms |
396860 KB |
Output is correct |
16 |
Correct |
475 ms |
395900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
391668 KB |
Output is correct |
2 |
Correct |
269 ms |
396036 KB |
Output is correct |
3 |
Correct |
261 ms |
404412 KB |
Output is correct |
4 |
Correct |
252 ms |
398664 KB |
Output is correct |
5 |
Correct |
227 ms |
399288 KB |
Output is correct |
6 |
Correct |
170 ms |
397048 KB |
Output is correct |
7 |
Correct |
186 ms |
396624 KB |
Output is correct |
8 |
Correct |
257 ms |
396172 KB |
Output is correct |
9 |
Correct |
248 ms |
396348 KB |
Output is correct |
10 |
Correct |
160 ms |
393812 KB |
Output is correct |
11 |
Correct |
205 ms |
396404 KB |
Output is correct |
12 |
Correct |
264 ms |
395868 KB |
Output is correct |
13 |
Correct |
251 ms |
404076 KB |
Output is correct |
14 |
Correct |
249 ms |
398596 KB |
Output is correct |
15 |
Correct |
232 ms |
399512 KB |
Output is correct |
16 |
Correct |
163 ms |
396656 KB |
Output is correct |
17 |
Correct |
187 ms |
397136 KB |
Output is correct |
18 |
Correct |
252 ms |
396372 KB |
Output is correct |
19 |
Correct |
254 ms |
399692 KB |
Output is correct |
20 |
Correct |
261 ms |
399908 KB |
Output is correct |
21 |
Correct |
266 ms |
396220 KB |
Output is correct |
22 |
Correct |
248 ms |
396324 KB |
Output is correct |
23 |
Correct |
161 ms |
393812 KB |
Output is correct |
24 |
Correct |
205 ms |
396440 KB |
Output is correct |
25 |
Correct |
254 ms |
396004 KB |
Output is correct |
26 |
Correct |
250 ms |
404268 KB |
Output is correct |
27 |
Correct |
248 ms |
398692 KB |
Output is correct |
28 |
Correct |
231 ms |
399744 KB |
Output is correct |
29 |
Correct |
161 ms |
396532 KB |
Output is correct |
30 |
Correct |
183 ms |
397140 KB |
Output is correct |
31 |
Correct |
251 ms |
396304 KB |
Output is correct |
32 |
Correct |
254 ms |
399852 KB |
Output is correct |
33 |
Correct |
252 ms |
399852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
391504 KB |
Output is correct |
2 |
Correct |
123 ms |
391688 KB |
Output is correct |
3 |
Correct |
122 ms |
391472 KB |
Output is correct |
4 |
Correct |
123 ms |
391572 KB |
Output is correct |
5 |
Correct |
125 ms |
392020 KB |
Output is correct |
6 |
Correct |
125 ms |
391460 KB |
Output is correct |
7 |
Correct |
120 ms |
391696 KB |
Output is correct |
8 |
Correct |
126 ms |
391504 KB |
Output is correct |
9 |
Correct |
123 ms |
391680 KB |
Output is correct |
10 |
Correct |
122 ms |
391504 KB |
Output is correct |
11 |
Correct |
121 ms |
391648 KB |
Output is correct |
12 |
Correct |
123 ms |
391764 KB |
Output is correct |
13 |
Correct |
127 ms |
391784 KB |
Output is correct |
14 |
Correct |
128 ms |
391788 KB |
Output is correct |
15 |
Correct |
123 ms |
391668 KB |
Output is correct |
16 |
Correct |
125 ms |
391536 KB |
Output is correct |
17 |
Correct |
116 ms |
391532 KB |
Output is correct |
18 |
Correct |
664 ms |
400256 KB |
Output is correct |
19 |
Correct |
291 ms |
395348 KB |
Output is correct |
20 |
Correct |
254 ms |
395168 KB |
Output is correct |
21 |
Correct |
262 ms |
395168 KB |
Output is correct |
22 |
Correct |
284 ms |
395016 KB |
Output is correct |
23 |
Correct |
327 ms |
395092 KB |
Output is correct |
24 |
Correct |
258 ms |
395452 KB |
Output is correct |
25 |
Correct |
272 ms |
395196 KB |
Output is correct |
26 |
Correct |
278 ms |
395192 KB |
Output is correct |
27 |
Correct |
370 ms |
400484 KB |
Output is correct |
28 |
Correct |
388 ms |
400392 KB |
Output is correct |
29 |
Correct |
370 ms |
400428 KB |
Output is correct |
30 |
Correct |
508 ms |
399960 KB |
Output is correct |
31 |
Correct |
122 ms |
391668 KB |
Output is correct |
32 |
Correct |
532 ms |
399576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
391504 KB |
Output is correct |
2 |
Correct |
123 ms |
391688 KB |
Output is correct |
3 |
Correct |
122 ms |
391472 KB |
Output is correct |
4 |
Correct |
123 ms |
391572 KB |
Output is correct |
5 |
Correct |
125 ms |
392020 KB |
Output is correct |
6 |
Correct |
125 ms |
391460 KB |
Output is correct |
7 |
Correct |
120 ms |
391696 KB |
Output is correct |
8 |
Correct |
126 ms |
391504 KB |
Output is correct |
9 |
Correct |
123 ms |
391680 KB |
Output is correct |
10 |
Correct |
122 ms |
391504 KB |
Output is correct |
11 |
Correct |
121 ms |
391648 KB |
Output is correct |
12 |
Correct |
123 ms |
391764 KB |
Output is correct |
13 |
Correct |
127 ms |
391784 KB |
Output is correct |
14 |
Correct |
128 ms |
391788 KB |
Output is correct |
15 |
Correct |
123 ms |
391668 KB |
Output is correct |
16 |
Correct |
125 ms |
391536 KB |
Output is correct |
17 |
Correct |
116 ms |
391532 KB |
Output is correct |
18 |
Correct |
664 ms |
400256 KB |
Output is correct |
19 |
Correct |
291 ms |
395348 KB |
Output is correct |
20 |
Correct |
254 ms |
395168 KB |
Output is correct |
21 |
Correct |
262 ms |
395168 KB |
Output is correct |
22 |
Correct |
284 ms |
395016 KB |
Output is correct |
23 |
Correct |
327 ms |
395092 KB |
Output is correct |
24 |
Correct |
258 ms |
395452 KB |
Output is correct |
25 |
Correct |
272 ms |
395196 KB |
Output is correct |
26 |
Correct |
278 ms |
395192 KB |
Output is correct |
27 |
Correct |
370 ms |
400484 KB |
Output is correct |
28 |
Correct |
388 ms |
400392 KB |
Output is correct |
29 |
Correct |
370 ms |
400428 KB |
Output is correct |
30 |
Correct |
508 ms |
399960 KB |
Output is correct |
31 |
Correct |
122 ms |
391668 KB |
Output is correct |
32 |
Correct |
532 ms |
399576 KB |
Output is correct |
33 |
Correct |
269 ms |
396036 KB |
Output is correct |
34 |
Correct |
261 ms |
404412 KB |
Output is correct |
35 |
Correct |
252 ms |
398664 KB |
Output is correct |
36 |
Correct |
227 ms |
399288 KB |
Output is correct |
37 |
Correct |
170 ms |
397048 KB |
Output is correct |
38 |
Correct |
186 ms |
396624 KB |
Output is correct |
39 |
Correct |
257 ms |
396172 KB |
Output is correct |
40 |
Correct |
248 ms |
396348 KB |
Output is correct |
41 |
Correct |
160 ms |
393812 KB |
Output is correct |
42 |
Correct |
205 ms |
396404 KB |
Output is correct |
43 |
Correct |
264 ms |
395868 KB |
Output is correct |
44 |
Correct |
251 ms |
404076 KB |
Output is correct |
45 |
Correct |
249 ms |
398596 KB |
Output is correct |
46 |
Correct |
232 ms |
399512 KB |
Output is correct |
47 |
Correct |
163 ms |
396656 KB |
Output is correct |
48 |
Correct |
187 ms |
397136 KB |
Output is correct |
49 |
Correct |
252 ms |
396372 KB |
Output is correct |
50 |
Correct |
254 ms |
399692 KB |
Output is correct |
51 |
Correct |
261 ms |
399908 KB |
Output is correct |
52 |
Correct |
266 ms |
396220 KB |
Output is correct |
53 |
Correct |
248 ms |
396324 KB |
Output is correct |
54 |
Correct |
161 ms |
393812 KB |
Output is correct |
55 |
Correct |
205 ms |
396440 KB |
Output is correct |
56 |
Correct |
254 ms |
396004 KB |
Output is correct |
57 |
Correct |
250 ms |
404268 KB |
Output is correct |
58 |
Correct |
248 ms |
398692 KB |
Output is correct |
59 |
Correct |
231 ms |
399744 KB |
Output is correct |
60 |
Correct |
161 ms |
396532 KB |
Output is correct |
61 |
Correct |
183 ms |
397140 KB |
Output is correct |
62 |
Correct |
251 ms |
396304 KB |
Output is correct |
63 |
Correct |
254 ms |
399852 KB |
Output is correct |
64 |
Correct |
252 ms |
399852 KB |
Output is correct |
65 |
Correct |
451 ms |
395240 KB |
Output is correct |
66 |
Correct |
564 ms |
396688 KB |
Output is correct |
67 |
Correct |
568 ms |
396468 KB |
Output is correct |
68 |
Correct |
539 ms |
396668 KB |
Output is correct |
69 |
Correct |
530 ms |
396912 KB |
Output is correct |
70 |
Correct |
349 ms |
396676 KB |
Output is correct |
71 |
Correct |
558 ms |
396580 KB |
Output is correct |
72 |
Correct |
577 ms |
396500 KB |
Output is correct |
73 |
Correct |
521 ms |
396752 KB |
Output is correct |
74 |
Correct |
387 ms |
396728 KB |
Output is correct |
75 |
Correct |
416 ms |
396472 KB |
Output is correct |
76 |
Correct |
416 ms |
396728 KB |
Output is correct |
77 |
Correct |
382 ms |
396860 KB |
Output is correct |
78 |
Correct |
475 ms |
395900 KB |
Output is correct |
79 |
Correct |
751 ms |
399912 KB |
Output is correct |
80 |
Correct |
826 ms |
399748 KB |
Output is correct |
81 |
Correct |
366 ms |
397368 KB |
Output is correct |
82 |
Correct |
437 ms |
399992 KB |
Output is correct |
83 |
Correct |
662 ms |
399688 KB |
Output is correct |
84 |
Correct |
513 ms |
407900 KB |
Output is correct |
85 |
Correct |
508 ms |
402260 KB |
Output is correct |
86 |
Correct |
487 ms |
403448 KB |
Output is correct |
87 |
Correct |
399 ms |
400104 KB |
Output is correct |
88 |
Correct |
405 ms |
400656 KB |
Output is correct |
89 |
Correct |
472 ms |
400400 KB |
Output is correct |
90 |
Correct |
550 ms |
403388 KB |
Output is correct |
91 |
Correct |
528 ms |
403244 KB |
Output is correct |