#include <bits/stdc++.h>
#ifndef SKY
#include "rainbow.h"
#endif // SKY
using namespace std;
#define N 200010
#define ll long long
#define fs first
#define sc second
#define ii pair<ll,int>
#define pb push_back
int r,c,m;
struct BIT
{
unordered_map<int,int>bit[N];
map<int,int>mp[N];
void update(int x,int y,int val)
{
x=r-x+2;
y=c-y+2;
for(int u=x;u>0;u-=u&(-u))
for(int v=y;v>0;v-=v&(-v))
bit[u][v]+=val;
}
int get(int x,int y)
{
x=r-x+2;
y=c-y+2;
int res=0;
for(int u=x;u<=r+1;u+=u&(-u))
for(int v=y;v<=c+1;v+=v&(-v))
if(bit[u].find(v)!=bit[u].end())
res+=bit[u][v];
return res;
}
void init(int u,int v)
{
if(++mp[u][v]==1)
update(u,v,1);
}
int solve(int ar, int ac, int br, int bc)
{
if(ar>br||ac>bc)
return 0;
return get(br,bc)+get(ar-1,ac-1)-get(ar-1,bc)-get(br,ac-1);
}
}row,col,p,cell;
void build(int u,int v)
{
p.init(u,v);
p.init(u+1,v);
p.init(u,v+1);
p.init(u+1,v+1);
row.init(u,v);
row.init(u+1,v);
col.init(u,v);
col.init(u,v+1);
cell.init(u,v);
}
void init(int RRR, int CCC, int sr, int sc, int MMM, char *S)
{
r=RRR;
c=CCC;
m=MMM;
build(sr,sc);
for(int i=1;i<=m;i++)
{
char ch=*S;
if(i!=m)
S++;
if(ch=='N')
sr--;
if(ch=='S')
sr++;
if(ch=='E')
sc++;
if(ch=='W')
sc--;
build(sr,sc);
}
}
int colour(int ar, int ac, int br, int bc)
{
if(cell.solve(ar,ac,br,bc)==0)
return 1;
int res=0;
res+=row.solve(ar+1,ac,br,bc)+col.solve(ar,ac+1,br,bc);
// cout<<res<<endl;
res-=p.solve(ar+1,ac+1,br,bc);
// cout<<p.solve(ar+1,ac+1,br,bc)<<endl;
res-=cell.solve(ar,ac,br,bc);
if(cell.solve(ar,ac,ar,bc)>0||cell.solve(br,ac,br,bc)>0||cell.solve(ar,ac,br,ac)>0||cell.solve(ar,bc,br,bc)>0)
return res+1;
return res+2;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int r,c,sr,sc,m;
string S;
cin>>r>>c>>sr>>sc>>m>>S;
init(r,c,sr,sc,m,&S[0]);
int q;
cin>>q;
while(q--)
{
int ar,ac,br,bc;
cin>>ar>>ac>>br>>bc;
cout<<colour(ar,ac,br,bc)<<endl;
}
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
81748 KB |
Output is correct |
2 |
Correct |
52 ms |
82184 KB |
Output is correct |
3 |
Correct |
42 ms |
81748 KB |
Output is correct |
4 |
Correct |
43 ms |
81868 KB |
Output is correct |
5 |
Correct |
47 ms |
82252 KB |
Output is correct |
6 |
Correct |
41 ms |
81620 KB |
Output is correct |
7 |
Correct |
41 ms |
81704 KB |
Output is correct |
8 |
Correct |
41 ms |
81680 KB |
Output is correct |
9 |
Correct |
40 ms |
81632 KB |
Output is correct |
10 |
Correct |
42 ms |
81592 KB |
Output is correct |
11 |
Correct |
44 ms |
81876 KB |
Output is correct |
12 |
Correct |
45 ms |
81996 KB |
Output is correct |
13 |
Correct |
47 ms |
82472 KB |
Output is correct |
14 |
Correct |
49 ms |
82520 KB |
Output is correct |
15 |
Correct |
39 ms |
81628 KB |
Output is correct |
16 |
Correct |
41 ms |
81580 KB |
Output is correct |
17 |
Correct |
40 ms |
81700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
81580 KB |
Output is correct |
2 |
Correct |
40 ms |
81700 KB |
Output is correct |
3 |
Correct |
668 ms |
116804 KB |
Output is correct |
4 |
Correct |
940 ms |
142400 KB |
Output is correct |
5 |
Correct |
878 ms |
141968 KB |
Output is correct |
6 |
Correct |
665 ms |
125760 KB |
Output is correct |
7 |
Correct |
682 ms |
124784 KB |
Output is correct |
8 |
Correct |
213 ms |
82392 KB |
Output is correct |
9 |
Correct |
952 ms |
142368 KB |
Output is correct |
10 |
Correct |
920 ms |
141936 KB |
Output is correct |
11 |
Correct |
692 ms |
125796 KB |
Output is correct |
12 |
Correct |
606 ms |
136516 KB |
Output is correct |
13 |
Correct |
625 ms |
142320 KB |
Output is correct |
14 |
Correct |
639 ms |
142144 KB |
Output is correct |
15 |
Correct |
542 ms |
125832 KB |
Output is correct |
16 |
Correct |
734 ms |
124796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
81628 KB |
Output is correct |
2 |
Correct |
1588 ms |
244700 KB |
Output is correct |
3 |
Correct |
915 ms |
247840 KB |
Output is correct |
4 |
Correct |
1733 ms |
278116 KB |
Output is correct |
5 |
Correct |
981 ms |
220348 KB |
Output is correct |
6 |
Correct |
371 ms |
93772 KB |
Output is correct |
7 |
Correct |
662 ms |
104708 KB |
Output is correct |
8 |
Correct |
515 ms |
138140 KB |
Output is correct |
9 |
Correct |
505 ms |
134764 KB |
Output is correct |
10 |
Correct |
145 ms |
93372 KB |
Output is correct |
11 |
Correct |
498 ms |
124104 KB |
Output is correct |
12 |
Correct |
1588 ms |
244636 KB |
Output is correct |
13 |
Correct |
911 ms |
247820 KB |
Output is correct |
14 |
Correct |
1734 ms |
278296 KB |
Output is correct |
15 |
Correct |
975 ms |
220488 KB |
Output is correct |
16 |
Correct |
263 ms |
91408 KB |
Output is correct |
17 |
Correct |
635 ms |
104948 KB |
Output is correct |
18 |
Correct |
1431 ms |
140548 KB |
Output is correct |
19 |
Correct |
1018 ms |
229552 KB |
Output is correct |
20 |
Correct |
1204 ms |
251736 KB |
Output is correct |
21 |
Correct |
549 ms |
138124 KB |
Output is correct |
22 |
Correct |
504 ms |
134828 KB |
Output is correct |
23 |
Correct |
165 ms |
93428 KB |
Output is correct |
24 |
Correct |
518 ms |
124044 KB |
Output is correct |
25 |
Correct |
1589 ms |
244752 KB |
Output is correct |
26 |
Correct |
920 ms |
247972 KB |
Output is correct |
27 |
Correct |
1837 ms |
278284 KB |
Output is correct |
28 |
Correct |
999 ms |
220636 KB |
Output is correct |
29 |
Correct |
269 ms |
91436 KB |
Output is correct |
30 |
Correct |
629 ms |
104952 KB |
Output is correct |
31 |
Correct |
1356 ms |
140476 KB |
Output is correct |
32 |
Correct |
1012 ms |
229776 KB |
Output is correct |
33 |
Correct |
1190 ms |
251664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
81748 KB |
Output is correct |
2 |
Correct |
52 ms |
82184 KB |
Output is correct |
3 |
Correct |
42 ms |
81748 KB |
Output is correct |
4 |
Correct |
43 ms |
81868 KB |
Output is correct |
5 |
Correct |
47 ms |
82252 KB |
Output is correct |
6 |
Correct |
41 ms |
81620 KB |
Output is correct |
7 |
Correct |
41 ms |
81704 KB |
Output is correct |
8 |
Correct |
41 ms |
81680 KB |
Output is correct |
9 |
Correct |
40 ms |
81632 KB |
Output is correct |
10 |
Correct |
42 ms |
81592 KB |
Output is correct |
11 |
Correct |
44 ms |
81876 KB |
Output is correct |
12 |
Correct |
45 ms |
81996 KB |
Output is correct |
13 |
Correct |
47 ms |
82472 KB |
Output is correct |
14 |
Correct |
49 ms |
82520 KB |
Output is correct |
15 |
Correct |
39 ms |
81628 KB |
Output is correct |
16 |
Correct |
41 ms |
81580 KB |
Output is correct |
17 |
Correct |
40 ms |
81700 KB |
Output is correct |
18 |
Correct |
2734 ms |
125860 KB |
Output is correct |
19 |
Correct |
356 ms |
86876 KB |
Output is correct |
20 |
Correct |
254 ms |
85380 KB |
Output is correct |
21 |
Correct |
255 ms |
85736 KB |
Output is correct |
22 |
Correct |
283 ms |
86348 KB |
Output is correct |
23 |
Correct |
321 ms |
86860 KB |
Output is correct |
24 |
Correct |
409 ms |
85728 KB |
Output is correct |
25 |
Correct |
323 ms |
85964 KB |
Output is correct |
26 |
Correct |
311 ms |
86600 KB |
Output is correct |
27 |
Correct |
957 ms |
110284 KB |
Output is correct |
28 |
Correct |
831 ms |
97604 KB |
Output is correct |
29 |
Correct |
913 ms |
107224 KB |
Output is correct |
30 |
Correct |
1628 ms |
143264 KB |
Output is correct |
31 |
Correct |
45 ms |
81740 KB |
Output is correct |
32 |
Correct |
1460 ms |
109504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
81748 KB |
Output is correct |
2 |
Correct |
52 ms |
82184 KB |
Output is correct |
3 |
Correct |
42 ms |
81748 KB |
Output is correct |
4 |
Correct |
43 ms |
81868 KB |
Output is correct |
5 |
Correct |
47 ms |
82252 KB |
Output is correct |
6 |
Correct |
41 ms |
81620 KB |
Output is correct |
7 |
Correct |
41 ms |
81704 KB |
Output is correct |
8 |
Correct |
41 ms |
81680 KB |
Output is correct |
9 |
Correct |
40 ms |
81632 KB |
Output is correct |
10 |
Correct |
42 ms |
81592 KB |
Output is correct |
11 |
Correct |
44 ms |
81876 KB |
Output is correct |
12 |
Correct |
45 ms |
81996 KB |
Output is correct |
13 |
Correct |
47 ms |
82472 KB |
Output is correct |
14 |
Correct |
49 ms |
82520 KB |
Output is correct |
15 |
Correct |
39 ms |
81628 KB |
Output is correct |
16 |
Correct |
41 ms |
81580 KB |
Output is correct |
17 |
Correct |
40 ms |
81700 KB |
Output is correct |
18 |
Correct |
2734 ms |
125860 KB |
Output is correct |
19 |
Correct |
356 ms |
86876 KB |
Output is correct |
20 |
Correct |
254 ms |
85380 KB |
Output is correct |
21 |
Correct |
255 ms |
85736 KB |
Output is correct |
22 |
Correct |
283 ms |
86348 KB |
Output is correct |
23 |
Correct |
321 ms |
86860 KB |
Output is correct |
24 |
Correct |
409 ms |
85728 KB |
Output is correct |
25 |
Correct |
323 ms |
85964 KB |
Output is correct |
26 |
Correct |
311 ms |
86600 KB |
Output is correct |
27 |
Correct |
957 ms |
110284 KB |
Output is correct |
28 |
Correct |
831 ms |
97604 KB |
Output is correct |
29 |
Correct |
913 ms |
107224 KB |
Output is correct |
30 |
Correct |
1628 ms |
143264 KB |
Output is correct |
31 |
Correct |
45 ms |
81740 KB |
Output is correct |
32 |
Correct |
1460 ms |
109504 KB |
Output is correct |
33 |
Correct |
1588 ms |
244700 KB |
Output is correct |
34 |
Correct |
915 ms |
247840 KB |
Output is correct |
35 |
Correct |
1733 ms |
278116 KB |
Output is correct |
36 |
Correct |
981 ms |
220348 KB |
Output is correct |
37 |
Correct |
371 ms |
93772 KB |
Output is correct |
38 |
Correct |
662 ms |
104708 KB |
Output is correct |
39 |
Correct |
515 ms |
138140 KB |
Output is correct |
40 |
Correct |
505 ms |
134764 KB |
Output is correct |
41 |
Correct |
145 ms |
93372 KB |
Output is correct |
42 |
Correct |
498 ms |
124104 KB |
Output is correct |
43 |
Correct |
1588 ms |
244636 KB |
Output is correct |
44 |
Correct |
911 ms |
247820 KB |
Output is correct |
45 |
Correct |
1734 ms |
278296 KB |
Output is correct |
46 |
Correct |
975 ms |
220488 KB |
Output is correct |
47 |
Correct |
263 ms |
91408 KB |
Output is correct |
48 |
Correct |
635 ms |
104948 KB |
Output is correct |
49 |
Correct |
1431 ms |
140548 KB |
Output is correct |
50 |
Correct |
1018 ms |
229552 KB |
Output is correct |
51 |
Correct |
1204 ms |
251736 KB |
Output is correct |
52 |
Correct |
549 ms |
138124 KB |
Output is correct |
53 |
Correct |
504 ms |
134828 KB |
Output is correct |
54 |
Correct |
165 ms |
93428 KB |
Output is correct |
55 |
Correct |
518 ms |
124044 KB |
Output is correct |
56 |
Correct |
1589 ms |
244752 KB |
Output is correct |
57 |
Correct |
920 ms |
247972 KB |
Output is correct |
58 |
Correct |
1837 ms |
278284 KB |
Output is correct |
59 |
Correct |
999 ms |
220636 KB |
Output is correct |
60 |
Correct |
269 ms |
91436 KB |
Output is correct |
61 |
Correct |
629 ms |
104952 KB |
Output is correct |
62 |
Correct |
1356 ms |
140476 KB |
Output is correct |
63 |
Correct |
1012 ms |
229776 KB |
Output is correct |
64 |
Correct |
1190 ms |
251664 KB |
Output is correct |
65 |
Correct |
668 ms |
116804 KB |
Output is correct |
66 |
Correct |
940 ms |
142400 KB |
Output is correct |
67 |
Correct |
878 ms |
141968 KB |
Output is correct |
68 |
Correct |
665 ms |
125760 KB |
Output is correct |
69 |
Correct |
682 ms |
124784 KB |
Output is correct |
70 |
Correct |
213 ms |
82392 KB |
Output is correct |
71 |
Correct |
952 ms |
142368 KB |
Output is correct |
72 |
Correct |
920 ms |
141936 KB |
Output is correct |
73 |
Correct |
692 ms |
125796 KB |
Output is correct |
74 |
Correct |
606 ms |
136516 KB |
Output is correct |
75 |
Correct |
625 ms |
142320 KB |
Output is correct |
76 |
Correct |
639 ms |
142144 KB |
Output is correct |
77 |
Correct |
542 ms |
125832 KB |
Output is correct |
78 |
Correct |
734 ms |
124796 KB |
Output is correct |
79 |
Correct |
1530 ms |
141892 KB |
Output is correct |
80 |
Correct |
1761 ms |
138348 KB |
Output is correct |
81 |
Correct |
1556 ms |
96848 KB |
Output is correct |
82 |
Correct |
2657 ms |
127820 KB |
Output is correct |
83 |
Correct |
2451 ms |
248220 KB |
Output is correct |
84 |
Correct |
2005 ms |
251408 KB |
Output is correct |
85 |
Correct |
2600 ms |
281960 KB |
Output is correct |
86 |
Correct |
1757 ms |
224044 KB |
Output is correct |
87 |
Correct |
1012 ms |
95072 KB |
Output is correct |
88 |
Correct |
1096 ms |
108728 KB |
Output is correct |
89 |
Correct |
1742 ms |
143908 KB |
Output is correct |
90 |
Correct |
2458 ms |
233212 KB |
Output is correct |
91 |
Correct |
2308 ms |
255268 KB |
Output is correct |