#include<bits/stdc++.h>
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=2e5+3;
const int mod=1e9+7;
const int INF=1e9+7;
int R,C,m,q,Q;
string s;
struct node
{
int val1,val2,val3;
node *l,*r;
node(): val1(0),val2(0),val3(0),l(NULL),r(NULL){};
}*rootc[maxn],*rootr[maxn];
node* cons(node* kk,int cl,int cr)
{
if(cl==cr) return new node();
int mid=(cl+cr)/2;
kk=new node();
kk->l=cons(kk->l,cl,mid);
kk->r=cons(kk->r,mid+1,cr);
return kk;
}
node* update(node* kk,int cl,int cr,int pos,int val,int type)
{
node* kkk=new node();
kkk->val1=kk->val1;
kkk->val2=kk->val2;
kkk->val3=kk->val3;
kkk->l=kk->l;
kkk->r=kk->r;
if(cl==cr)
{
if(type==1) kkk->val1+=val;
else if(type==2) kkk->val2+=val;
else kkk->val3+=val;
return kkk;
}
int mid=(cl+cr)/2;
if(pos<=mid) kkk->l=update(kk->l,cl,mid,pos,val,type);
else kkk->r=update(kk->r,mid+1,cr,pos,val,type);
kkk->val1=kkk->l->val1+kkk->r->val1;
kkk->val2=kkk->l->val2+kkk->r->val2;
kkk->val3=kkk->l->val3+kkk->r->val3;
return kkk;
}
int get(node* kk,int cl,int cr,int l,int r,int type)
{
if(cl>r||cr<l) return 0;
if(cl>=l&&cr<=r)
{
if(type==1) return kk->val1;
else if(type==2) return kk->val2;
else return kk->val3;
}
int mid=(cl+cr)/2;
return get(kk->l,cl,mid,l,r,type)+get(kk->r,mid+1,cr,l,r,type);
}
set<pii> path;
set<int> row[maxn],col[maxn],blc[maxn],blr[maxn];
void init(int32_t _R,int32_t _C,int32_t SR,int32_t SC,int32_t M,char* t)
{
R=_R;
C=_C;
m=M;
path.insert({SR,SC});
for(int i=0;i<M;i++)
{
char x=t[i];
if(x=='N') SR--;
if(x=='S') SR++;
if(x=='E') SC++;
if(x=='W') SC--;
path.insert({SR,SC});
}
for( pii x:path)
{
row[x.fi].insert(x.sc);
row[x.fi-1].insert(x.sc);
col[x.sc].insert(x.fi);
col[x.sc-1].insert(x.fi);
blr[x.fi].insert(x.sc);
blr[x.fi-1].insert(x.sc);
blr[x.fi].insert(x.sc-1);
blr[x.fi-1].insert(x.sc-1);
blc[x.fi].insert(x.sc);
}
rootr[0]=cons(rootr[0],0,C);
for(int i=1;i<=R;i++)
{
rootr[i]=rootr[i-1];
for(int x:row[i])
{
rootr[i]=update(rootr[i],0,C,x,1,1);
}
for(int x:blc[i])
{
rootr[i]=update(rootr[i],0,C,x,1,2);
}
for(int x:blr[i])
{
rootr[i]=update(rootr[i],0,C,x,1,3);
}
}
rootc[0]=cons(rootc[0],0,R);
for(int i=1;i<=C;i++)
{
rootc[i]=rootc[i-1];
for(int x:col[i])
{
rootc[i]=update(rootc[i],0,R,x,1,1);
}
}
}
int32_t colour(int32_t ar,int32_t ac,int32_t br,int32_t bc)
{
int rr=get(rootr[br-1],0,C,ac,bc,1)-get(rootr[ar-1],0,C,ac,bc,1);
int cc=get(rootc[bc-1],0,R,ar,br,1)-get(rootc[ac-1],0,R,ar,br,1);
int block=get(rootr[br],0,C,ac,bc,2)-get(rootr[ar-1],0,C,ac,bc,2);
int block2=get(rootr[br-1],0,C,ac+1,bc-1,2)-get(rootr[ar],0,C,ac+1,bc-1,2);
int vert=get(rootr[br-1],0,C,ac,bc-1,3)-get(rootr[ar-1],0,C,ac,bc-1,3);
return rr+cc+2-block-vert-1+((block==block2)&&block);
return 0;
}
//signed main()
//{
// if (fopen(taskname".INP","r"))
// {
// freopen(taskname".INP","r",stdin);
// freopen(taskname".OUT","w",stdout);
// }
// Faster
// int _R,_C,M,sr,sc;
// cin>>_R>>_C>>M>>Q>>sr>>sc;
// char SS[M];
// for(int i=0;i<M;i++)
// {
// char x;
// cin>>x;
// SS[i]=x;
// }
// init(_R,_C,sr,sc,M,SS);
// while(Q--)
// {
// int ar,ac,br,bc;
// cin>>ar>>ac>>br>>bc;
// cout<<colour(ar,ac,br,bc)<<"\n";
// }
//
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
39768 KB |
Output is correct |
2 |
Correct |
8 ms |
41308 KB |
Output is correct |
3 |
Correct |
7 ms |
39912 KB |
Output is correct |
4 |
Correct |
7 ms |
40028 KB |
Output is correct |
5 |
Correct |
9 ms |
41696 KB |
Output is correct |
6 |
Correct |
6 ms |
39512 KB |
Output is correct |
7 |
Correct |
6 ms |
39588 KB |
Output is correct |
8 |
Correct |
6 ms |
39516 KB |
Output is correct |
9 |
Correct |
6 ms |
39620 KB |
Output is correct |
10 |
Correct |
6 ms |
39516 KB |
Output is correct |
11 |
Correct |
7 ms |
40284 KB |
Output is correct |
12 |
Correct |
8 ms |
40892 KB |
Output is correct |
13 |
Correct |
10 ms |
42524 KB |
Output is correct |
14 |
Correct |
11 ms |
43096 KB |
Output is correct |
15 |
Correct |
6 ms |
39516 KB |
Output is correct |
16 |
Correct |
6 ms |
39512 KB |
Output is correct |
17 |
Correct |
5 ms |
39516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
39512 KB |
Output is correct |
2 |
Correct |
5 ms |
39516 KB |
Output is correct |
3 |
Correct |
562 ms |
304840 KB |
Output is correct |
4 |
Correct |
866 ms |
457564 KB |
Output is correct |
5 |
Correct |
789 ms |
445524 KB |
Output is correct |
6 |
Correct |
624 ms |
340304 KB |
Output is correct |
7 |
Correct |
600 ms |
319316 KB |
Output is correct |
8 |
Correct |
238 ms |
62292 KB |
Output is correct |
9 |
Correct |
772 ms |
454996 KB |
Output is correct |
10 |
Correct |
772 ms |
444240 KB |
Output is correct |
11 |
Correct |
639 ms |
340748 KB |
Output is correct |
12 |
Correct |
593 ms |
448620 KB |
Output is correct |
13 |
Correct |
616 ms |
456788 KB |
Output is correct |
14 |
Correct |
637 ms |
446032 KB |
Output is correct |
15 |
Correct |
495 ms |
340820 KB |
Output is correct |
16 |
Correct |
584 ms |
321104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
39516 KB |
Output is correct |
2 |
Correct |
653 ms |
636752 KB |
Output is correct |
3 |
Correct |
551 ms |
631632 KB |
Output is correct |
4 |
Correct |
517 ms |
639828 KB |
Output is correct |
5 |
Correct |
436 ms |
494556 KB |
Output is correct |
6 |
Correct |
142 ms |
184092 KB |
Output is correct |
7 |
Correct |
257 ms |
289024 KB |
Output is correct |
8 |
Correct |
418 ms |
364768 KB |
Output is correct |
9 |
Correct |
365 ms |
327128 KB |
Output is correct |
10 |
Correct |
105 ms |
131924 KB |
Output is correct |
11 |
Correct |
272 ms |
294736 KB |
Output is correct |
12 |
Correct |
656 ms |
636700 KB |
Output is correct |
13 |
Correct |
531 ms |
631640 KB |
Output is correct |
14 |
Correct |
515 ms |
639828 KB |
Output is correct |
15 |
Correct |
444 ms |
494744 KB |
Output is correct |
16 |
Correct |
134 ms |
162896 KB |
Output is correct |
17 |
Correct |
258 ms |
289240 KB |
Output is correct |
18 |
Correct |
604 ms |
638840 KB |
Output is correct |
19 |
Correct |
543 ms |
597332 KB |
Output is correct |
20 |
Correct |
555 ms |
596820 KB |
Output is correct |
21 |
Correct |
420 ms |
364624 KB |
Output is correct |
22 |
Correct |
367 ms |
327008 KB |
Output is correct |
23 |
Correct |
102 ms |
131924 KB |
Output is correct |
24 |
Correct |
283 ms |
294768 KB |
Output is correct |
25 |
Correct |
655 ms |
636608 KB |
Output is correct |
26 |
Correct |
530 ms |
631752 KB |
Output is correct |
27 |
Correct |
517 ms |
640084 KB |
Output is correct |
28 |
Correct |
451 ms |
494676 KB |
Output is correct |
29 |
Correct |
135 ms |
162860 KB |
Output is correct |
30 |
Correct |
251 ms |
289180 KB |
Output is correct |
31 |
Correct |
603 ms |
638880 KB |
Output is correct |
32 |
Correct |
554 ms |
597328 KB |
Output is correct |
33 |
Correct |
560 ms |
596964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
39768 KB |
Output is correct |
2 |
Correct |
8 ms |
41308 KB |
Output is correct |
3 |
Correct |
7 ms |
39912 KB |
Output is correct |
4 |
Correct |
7 ms |
40028 KB |
Output is correct |
5 |
Correct |
9 ms |
41696 KB |
Output is correct |
6 |
Correct |
6 ms |
39512 KB |
Output is correct |
7 |
Correct |
6 ms |
39588 KB |
Output is correct |
8 |
Correct |
6 ms |
39516 KB |
Output is correct |
9 |
Correct |
6 ms |
39620 KB |
Output is correct |
10 |
Correct |
6 ms |
39516 KB |
Output is correct |
11 |
Correct |
7 ms |
40284 KB |
Output is correct |
12 |
Correct |
8 ms |
40892 KB |
Output is correct |
13 |
Correct |
10 ms |
42524 KB |
Output is correct |
14 |
Correct |
11 ms |
43096 KB |
Output is correct |
15 |
Correct |
6 ms |
39516 KB |
Output is correct |
16 |
Correct |
6 ms |
39512 KB |
Output is correct |
17 |
Correct |
5 ms |
39516 KB |
Output is correct |
18 |
Correct |
461 ms |
215888 KB |
Output is correct |
19 |
Correct |
165 ms |
50772 KB |
Output is correct |
20 |
Correct |
118 ms |
44012 KB |
Output is correct |
21 |
Correct |
142 ms |
45396 KB |
Output is correct |
22 |
Correct |
147 ms |
46672 KB |
Output is correct |
23 |
Correct |
169 ms |
50280 KB |
Output is correct |
24 |
Correct |
120 ms |
44748 KB |
Output is correct |
25 |
Correct |
138 ms |
46160 KB |
Output is correct |
26 |
Correct |
154 ms |
47188 KB |
Output is correct |
27 |
Correct |
355 ms |
183976 KB |
Output is correct |
28 |
Correct |
258 ms |
110936 KB |
Output is correct |
29 |
Correct |
344 ms |
172116 KB |
Output is correct |
30 |
Correct |
626 ms |
386384 KB |
Output is correct |
31 |
Correct |
8 ms |
39768 KB |
Output is correct |
32 |
Correct |
395 ms |
185808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
39768 KB |
Output is correct |
2 |
Correct |
8 ms |
41308 KB |
Output is correct |
3 |
Correct |
7 ms |
39912 KB |
Output is correct |
4 |
Correct |
7 ms |
40028 KB |
Output is correct |
5 |
Correct |
9 ms |
41696 KB |
Output is correct |
6 |
Correct |
6 ms |
39512 KB |
Output is correct |
7 |
Correct |
6 ms |
39588 KB |
Output is correct |
8 |
Correct |
6 ms |
39516 KB |
Output is correct |
9 |
Correct |
6 ms |
39620 KB |
Output is correct |
10 |
Correct |
6 ms |
39516 KB |
Output is correct |
11 |
Correct |
7 ms |
40284 KB |
Output is correct |
12 |
Correct |
8 ms |
40892 KB |
Output is correct |
13 |
Correct |
10 ms |
42524 KB |
Output is correct |
14 |
Correct |
11 ms |
43096 KB |
Output is correct |
15 |
Correct |
6 ms |
39516 KB |
Output is correct |
16 |
Correct |
6 ms |
39512 KB |
Output is correct |
17 |
Correct |
5 ms |
39516 KB |
Output is correct |
18 |
Correct |
461 ms |
215888 KB |
Output is correct |
19 |
Correct |
165 ms |
50772 KB |
Output is correct |
20 |
Correct |
118 ms |
44012 KB |
Output is correct |
21 |
Correct |
142 ms |
45396 KB |
Output is correct |
22 |
Correct |
147 ms |
46672 KB |
Output is correct |
23 |
Correct |
169 ms |
50280 KB |
Output is correct |
24 |
Correct |
120 ms |
44748 KB |
Output is correct |
25 |
Correct |
138 ms |
46160 KB |
Output is correct |
26 |
Correct |
154 ms |
47188 KB |
Output is correct |
27 |
Correct |
355 ms |
183976 KB |
Output is correct |
28 |
Correct |
258 ms |
110936 KB |
Output is correct |
29 |
Correct |
344 ms |
172116 KB |
Output is correct |
30 |
Correct |
626 ms |
386384 KB |
Output is correct |
31 |
Correct |
8 ms |
39768 KB |
Output is correct |
32 |
Correct |
395 ms |
185808 KB |
Output is correct |
33 |
Correct |
653 ms |
636752 KB |
Output is correct |
34 |
Correct |
551 ms |
631632 KB |
Output is correct |
35 |
Correct |
517 ms |
639828 KB |
Output is correct |
36 |
Correct |
436 ms |
494556 KB |
Output is correct |
37 |
Correct |
142 ms |
184092 KB |
Output is correct |
38 |
Correct |
257 ms |
289024 KB |
Output is correct |
39 |
Correct |
418 ms |
364768 KB |
Output is correct |
40 |
Correct |
365 ms |
327128 KB |
Output is correct |
41 |
Correct |
105 ms |
131924 KB |
Output is correct |
42 |
Correct |
272 ms |
294736 KB |
Output is correct |
43 |
Correct |
656 ms |
636700 KB |
Output is correct |
44 |
Correct |
531 ms |
631640 KB |
Output is correct |
45 |
Correct |
515 ms |
639828 KB |
Output is correct |
46 |
Correct |
444 ms |
494744 KB |
Output is correct |
47 |
Correct |
134 ms |
162896 KB |
Output is correct |
48 |
Correct |
258 ms |
289240 KB |
Output is correct |
49 |
Correct |
604 ms |
638840 KB |
Output is correct |
50 |
Correct |
543 ms |
597332 KB |
Output is correct |
51 |
Correct |
555 ms |
596820 KB |
Output is correct |
52 |
Correct |
420 ms |
364624 KB |
Output is correct |
53 |
Correct |
367 ms |
327008 KB |
Output is correct |
54 |
Correct |
102 ms |
131924 KB |
Output is correct |
55 |
Correct |
283 ms |
294768 KB |
Output is correct |
56 |
Correct |
655 ms |
636608 KB |
Output is correct |
57 |
Correct |
530 ms |
631752 KB |
Output is correct |
58 |
Correct |
517 ms |
640084 KB |
Output is correct |
59 |
Correct |
451 ms |
494676 KB |
Output is correct |
60 |
Correct |
135 ms |
162860 KB |
Output is correct |
61 |
Correct |
251 ms |
289180 KB |
Output is correct |
62 |
Correct |
603 ms |
638880 KB |
Output is correct |
63 |
Correct |
554 ms |
597328 KB |
Output is correct |
64 |
Correct |
560 ms |
596964 KB |
Output is correct |
65 |
Correct |
562 ms |
304840 KB |
Output is correct |
66 |
Correct |
866 ms |
457564 KB |
Output is correct |
67 |
Correct |
789 ms |
445524 KB |
Output is correct |
68 |
Correct |
624 ms |
340304 KB |
Output is correct |
69 |
Correct |
600 ms |
319316 KB |
Output is correct |
70 |
Correct |
238 ms |
62292 KB |
Output is correct |
71 |
Correct |
772 ms |
454996 KB |
Output is correct |
72 |
Correct |
772 ms |
444240 KB |
Output is correct |
73 |
Correct |
639 ms |
340748 KB |
Output is correct |
74 |
Correct |
593 ms |
448620 KB |
Output is correct |
75 |
Correct |
616 ms |
456788 KB |
Output is correct |
76 |
Correct |
637 ms |
446032 KB |
Output is correct |
77 |
Correct |
495 ms |
340820 KB |
Output is correct |
78 |
Correct |
584 ms |
321104 KB |
Output is correct |
79 |
Correct |
713 ms |
368472 KB |
Output is correct |
80 |
Correct |
646 ms |
330832 KB |
Output is correct |
81 |
Correct |
311 ms |
135248 KB |
Output is correct |
82 |
Correct |
550 ms |
298320 KB |
Output is correct |
83 |
Correct |
1002 ms |
640340 KB |
Output is correct |
84 |
Correct |
871 ms |
635220 KB |
Output is correct |
85 |
Correct |
828 ms |
643488 KB |
Output is correct |
86 |
Correct |
755 ms |
498208 KB |
Output is correct |
87 |
Correct |
432 ms |
166276 KB |
Output is correct |
88 |
Correct |
556 ms |
292688 KB |
Output is correct |
89 |
Correct |
871 ms |
642436 KB |
Output is correct |
90 |
Correct |
896 ms |
600656 KB |
Output is correct |
91 |
Correct |
848 ms |
600524 KB |
Output is correct |