#include "rainbow.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
struct node
{
int data=0;
node *l=0,*r=0;
void up()
{
data=0;
if(l) data+=l->data;
if(r) data+=r->data;
}
}*root[400005];
node* modify(int x,int l,int r,node *p,int v)
{
if(!p) p=new node;
else p=new node(*p);
if(l==r)
return p->data+=v,p;
int m=l+r>>1;
if(x<=m) p->l=modify(x,l,m,p->l,v);
else p->r=modify(x,m+1,r,p->r,v);
return p->up(),p;
}
node *lch(node *p){return p?p->l:0;}
node *rch(node *p){return p?p->r:0;}
int gdata(node *p){return p?p->data:0;}
int query(int L,int R,int l,int r,node *p,node *q)
{
if(!p&&!q) return 0;
if(L<=l && R>=r)
return gdata(p)-gdata(q);
int m=l+r>>1;
if(R<=m) return query(L,R,l,m,lch(p),lch(q));
if(L>m) return query(L,R,m+1,r,rch(p),rch(q));
return query(L,R,l,m,lch(p),lch(q))+query(L,R,m+1,r,rch(p),rch(q));
}
int MAXC,mir=1e9,mxr,mic=1e9,mxc;
set<pii> s,dt,rl,cl;
int num[256],dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
vector<pii> wei[400005];
void maintain(int x,int y)
{
mir=min(mir,x),mxr=max(mxr,x);
mic=min(mic,y),mxc=max(mxc,y);
s.insert(MP(x,y));
dt.insert(MP(x,y)),dt.insert(MP(x+1,y+1)),dt.insert(MP(x+1,y)),dt.insert(MP(x,y+1));
rl.insert(MP(x,y)),rl.insert(MP(x+1,y));
cl.insert(MP(x,y)),cl.insert(MP(x,y+1));
}
void init(int R, int C, int sr, int sc, int M, char *S)
{
num['N']=0,num['S']=1,num['E']=2,num['W']=3,maintain(sr,sc),MAXC=2*C+1;
for(int i=0;i<M;++i)
sr+=dx[num[S[i]]],sc+=dy[num[S[i]]],maintain(sr,sc);
for(auto i:s)
wei[i.F*2].pb(MP(i.S*2,-1));
for(auto i:dt)
wei[i.F*2-1].pb(MP(i.S*2-1,-1));
for(auto i:rl)
wei[i.F*2-1].pb(MP(i.S*2,1));
for(auto i:cl)
wei[i.F*2].pb(MP(i.S*2-1,1));
for(int i=1;i<=2*R+1;++i,root[i]=root[i-1])
for(auto j:wei[i])
root[i]=modify(j.F,1,MAXC,root[i],j.S);
}
int colour(int ar, int ac, int br, int bc)
{
if(ar<mir&&br>mxr&&ac<mic&&bc>mxc) return 2+query(ac*2,bc*2,1,MAXC,root[br*2],root[ar*2-1]);
return 1+query(ac*2,bc*2,1,MAXC,root[br*2],root[ar*2-1]);
}
Compilation message
rainbow.cpp: In function 'node* modify(int, int, int, node*, int)':
rainbow.cpp:36:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m=l+r>>1;
~^~
rainbow.cpp: In function 'int query(int, int, int, int, node*, node*)':
rainbow.cpp:51:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m=l+r>>1;
~^~
rainbow.cpp: In function 'void init(int, int, int, int, int, char*)':
rainbow.cpp:76:18: warning: array subscript has type 'char' [-Wchar-subscripts]
sr+=dx[num[S[i]]],sc+=dy[num[S[i]]],maintain(sr,sc);
^
rainbow.cpp:76:36: warning: array subscript has type 'char' [-Wchar-subscripts]
sr+=dx[num[S[i]]],sc+=dy[num[S[i]]],maintain(sr,sc);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9976 KB |
Output is correct |
2 |
Correct |
17 ms |
11300 KB |
Output is correct |
3 |
Correct |
13 ms |
10104 KB |
Output is correct |
4 |
Correct |
13 ms |
10232 KB |
Output is correct |
5 |
Correct |
17 ms |
11512 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
11 ms |
9724 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
11 ms |
9720 KB |
Output is correct |
11 |
Correct |
14 ms |
10360 KB |
Output is correct |
12 |
Correct |
15 ms |
10872 KB |
Output is correct |
13 |
Correct |
17 ms |
12152 KB |
Output is correct |
14 |
Correct |
21 ms |
12664 KB |
Output is correct |
15 |
Correct |
11 ms |
9720 KB |
Output is correct |
16 |
Correct |
11 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
11 ms |
9720 KB |
Output is correct |
3 |
Correct |
734 ms |
250824 KB |
Output is correct |
4 |
Correct |
1172 ms |
413560 KB |
Output is correct |
5 |
Correct |
1170 ms |
410312 KB |
Output is correct |
6 |
Correct |
937 ms |
318136 KB |
Output is correct |
7 |
Correct |
992 ms |
312820 KB |
Output is correct |
8 |
Correct |
93 ms |
10680 KB |
Output is correct |
9 |
Correct |
1156 ms |
413624 KB |
Output is correct |
10 |
Correct |
1181 ms |
410316 KB |
Output is correct |
11 |
Correct |
963 ms |
318132 KB |
Output is correct |
12 |
Correct |
1039 ms |
385352 KB |
Output is correct |
13 |
Correct |
1106 ms |
413508 KB |
Output is correct |
14 |
Correct |
1113 ms |
410216 KB |
Output is correct |
15 |
Correct |
926 ms |
318684 KB |
Output is correct |
16 |
Correct |
853 ms |
295008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
1080 ms |
415992 KB |
Output is correct |
3 |
Correct |
1033 ms |
420152 KB |
Output is correct |
4 |
Correct |
1000 ms |
418992 KB |
Output is correct |
5 |
Correct |
790 ms |
317308 KB |
Output is correct |
6 |
Correct |
236 ms |
88824 KB |
Output is correct |
7 |
Correct |
447 ms |
164472 KB |
Output is correct |
8 |
Correct |
867 ms |
330544 KB |
Output is correct |
9 |
Correct |
786 ms |
287544 KB |
Output is correct |
10 |
Correct |
194 ms |
66296 KB |
Output is correct |
11 |
Correct |
522 ms |
184044 KB |
Output is correct |
12 |
Correct |
1096 ms |
415876 KB |
Output is correct |
13 |
Correct |
1020 ms |
420364 KB |
Output is correct |
14 |
Correct |
1008 ms |
419164 KB |
Output is correct |
15 |
Correct |
779 ms |
317252 KB |
Output is correct |
16 |
Correct |
208 ms |
73464 KB |
Output is correct |
17 |
Correct |
436 ms |
164472 KB |
Output is correct |
18 |
Correct |
971 ms |
417544 KB |
Output is correct |
19 |
Correct |
1045 ms |
421168 KB |
Output is correct |
20 |
Correct |
1063 ms |
421004 KB |
Output is correct |
21 |
Correct |
885 ms |
330528 KB |
Output is correct |
22 |
Correct |
846 ms |
287700 KB |
Output is correct |
23 |
Correct |
198 ms |
66324 KB |
Output is correct |
24 |
Correct |
526 ms |
184224 KB |
Output is correct |
25 |
Correct |
1180 ms |
416056 KB |
Output is correct |
26 |
Correct |
1020 ms |
420144 KB |
Output is correct |
27 |
Correct |
1050 ms |
418960 KB |
Output is correct |
28 |
Correct |
786 ms |
317384 KB |
Output is correct |
29 |
Correct |
210 ms |
73496 KB |
Output is correct |
30 |
Correct |
438 ms |
164436 KB |
Output is correct |
31 |
Correct |
964 ms |
417752 KB |
Output is correct |
32 |
Correct |
1060 ms |
421108 KB |
Output is correct |
33 |
Correct |
1052 ms |
420800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9976 KB |
Output is correct |
2 |
Correct |
17 ms |
11300 KB |
Output is correct |
3 |
Correct |
13 ms |
10104 KB |
Output is correct |
4 |
Correct |
13 ms |
10232 KB |
Output is correct |
5 |
Correct |
17 ms |
11512 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
11 ms |
9724 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
11 ms |
9720 KB |
Output is correct |
11 |
Correct |
14 ms |
10360 KB |
Output is correct |
12 |
Correct |
15 ms |
10872 KB |
Output is correct |
13 |
Correct |
17 ms |
12152 KB |
Output is correct |
14 |
Correct |
21 ms |
12664 KB |
Output is correct |
15 |
Correct |
11 ms |
9720 KB |
Output is correct |
16 |
Correct |
11 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
553 ms |
145452 KB |
Output is correct |
19 |
Correct |
115 ms |
19064 KB |
Output is correct |
20 |
Correct |
90 ms |
13980 KB |
Output is correct |
21 |
Correct |
94 ms |
14840 KB |
Output is correct |
22 |
Correct |
102 ms |
15992 KB |
Output is correct |
23 |
Correct |
114 ms |
18808 KB |
Output is correct |
24 |
Correct |
97 ms |
14512 KB |
Output is correct |
25 |
Correct |
98 ms |
15616 KB |
Output is correct |
26 |
Correct |
104 ms |
16504 KB |
Output is correct |
27 |
Correct |
483 ms |
119284 KB |
Output is correct |
28 |
Correct |
289 ms |
64248 KB |
Output is correct |
29 |
Correct |
445 ms |
110196 KB |
Output is correct |
30 |
Correct |
822 ms |
272988 KB |
Output is correct |
31 |
Correct |
13 ms |
9848 KB |
Output is correct |
32 |
Correct |
524 ms |
121468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9976 KB |
Output is correct |
2 |
Correct |
17 ms |
11300 KB |
Output is correct |
3 |
Correct |
13 ms |
10104 KB |
Output is correct |
4 |
Correct |
13 ms |
10232 KB |
Output is correct |
5 |
Correct |
17 ms |
11512 KB |
Output is correct |
6 |
Correct |
11 ms |
9720 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
11 ms |
9724 KB |
Output is correct |
9 |
Correct |
11 ms |
9720 KB |
Output is correct |
10 |
Correct |
11 ms |
9720 KB |
Output is correct |
11 |
Correct |
14 ms |
10360 KB |
Output is correct |
12 |
Correct |
15 ms |
10872 KB |
Output is correct |
13 |
Correct |
17 ms |
12152 KB |
Output is correct |
14 |
Correct |
21 ms |
12664 KB |
Output is correct |
15 |
Correct |
11 ms |
9720 KB |
Output is correct |
16 |
Correct |
11 ms |
9720 KB |
Output is correct |
17 |
Correct |
11 ms |
9720 KB |
Output is correct |
18 |
Correct |
553 ms |
145452 KB |
Output is correct |
19 |
Correct |
115 ms |
19064 KB |
Output is correct |
20 |
Correct |
90 ms |
13980 KB |
Output is correct |
21 |
Correct |
94 ms |
14840 KB |
Output is correct |
22 |
Correct |
102 ms |
15992 KB |
Output is correct |
23 |
Correct |
114 ms |
18808 KB |
Output is correct |
24 |
Correct |
97 ms |
14512 KB |
Output is correct |
25 |
Correct |
98 ms |
15616 KB |
Output is correct |
26 |
Correct |
104 ms |
16504 KB |
Output is correct |
27 |
Correct |
483 ms |
119284 KB |
Output is correct |
28 |
Correct |
289 ms |
64248 KB |
Output is correct |
29 |
Correct |
445 ms |
110196 KB |
Output is correct |
30 |
Correct |
822 ms |
272988 KB |
Output is correct |
31 |
Correct |
13 ms |
9848 KB |
Output is correct |
32 |
Correct |
524 ms |
121468 KB |
Output is correct |
33 |
Correct |
1080 ms |
415992 KB |
Output is correct |
34 |
Correct |
1033 ms |
420152 KB |
Output is correct |
35 |
Correct |
1000 ms |
418992 KB |
Output is correct |
36 |
Correct |
790 ms |
317308 KB |
Output is correct |
37 |
Correct |
236 ms |
88824 KB |
Output is correct |
38 |
Correct |
447 ms |
164472 KB |
Output is correct |
39 |
Correct |
867 ms |
330544 KB |
Output is correct |
40 |
Correct |
786 ms |
287544 KB |
Output is correct |
41 |
Correct |
194 ms |
66296 KB |
Output is correct |
42 |
Correct |
522 ms |
184044 KB |
Output is correct |
43 |
Correct |
1096 ms |
415876 KB |
Output is correct |
44 |
Correct |
1020 ms |
420364 KB |
Output is correct |
45 |
Correct |
1008 ms |
419164 KB |
Output is correct |
46 |
Correct |
779 ms |
317252 KB |
Output is correct |
47 |
Correct |
208 ms |
73464 KB |
Output is correct |
48 |
Correct |
436 ms |
164472 KB |
Output is correct |
49 |
Correct |
971 ms |
417544 KB |
Output is correct |
50 |
Correct |
1045 ms |
421168 KB |
Output is correct |
51 |
Correct |
1063 ms |
421004 KB |
Output is correct |
52 |
Correct |
885 ms |
330528 KB |
Output is correct |
53 |
Correct |
846 ms |
287700 KB |
Output is correct |
54 |
Correct |
198 ms |
66324 KB |
Output is correct |
55 |
Correct |
526 ms |
184224 KB |
Output is correct |
56 |
Correct |
1180 ms |
416056 KB |
Output is correct |
57 |
Correct |
1020 ms |
420144 KB |
Output is correct |
58 |
Correct |
1050 ms |
418960 KB |
Output is correct |
59 |
Correct |
786 ms |
317384 KB |
Output is correct |
60 |
Correct |
210 ms |
73496 KB |
Output is correct |
61 |
Correct |
438 ms |
164436 KB |
Output is correct |
62 |
Correct |
964 ms |
417752 KB |
Output is correct |
63 |
Correct |
1060 ms |
421108 KB |
Output is correct |
64 |
Correct |
1052 ms |
420800 KB |
Output is correct |
65 |
Correct |
1059 ms |
334100 KB |
Output is correct |
66 |
Correct |
977 ms |
291112 KB |
Output is correct |
67 |
Correct |
326 ms |
69732 KB |
Output is correct |
68 |
Correct |
637 ms |
187508 KB |
Output is correct |
69 |
Correct |
1203 ms |
419396 KB |
Output is correct |
70 |
Correct |
1110 ms |
423736 KB |
Output is correct |
71 |
Correct |
1119 ms |
422648 KB |
Output is correct |
72 |
Correct |
884 ms |
320872 KB |
Output is correct |
73 |
Correct |
290 ms |
77048 KB |
Output is correct |
74 |
Correct |
519 ms |
167928 KB |
Output is correct |
75 |
Correct |
1038 ms |
421048 KB |
Output is correct |
76 |
Correct |
1189 ms |
424572 KB |
Output is correct |
77 |
Correct |
1180 ms |
424468 KB |
Output is correct |
78 |
Correct |
734 ms |
250824 KB |
Output is correct |
79 |
Correct |
1172 ms |
413560 KB |
Output is correct |
80 |
Correct |
1170 ms |
410312 KB |
Output is correct |
81 |
Correct |
937 ms |
318136 KB |
Output is correct |
82 |
Correct |
992 ms |
312820 KB |
Output is correct |
83 |
Correct |
93 ms |
10680 KB |
Output is correct |
84 |
Correct |
1156 ms |
413624 KB |
Output is correct |
85 |
Correct |
1181 ms |
410316 KB |
Output is correct |
86 |
Correct |
963 ms |
318132 KB |
Output is correct |
87 |
Correct |
1039 ms |
385352 KB |
Output is correct |
88 |
Correct |
1106 ms |
413508 KB |
Output is correct |
89 |
Correct |
1113 ms |
410216 KB |
Output is correct |
90 |
Correct |
926 ms |
318684 KB |
Output is correct |
91 |
Correct |
853 ms |
295008 KB |
Output is correct |