#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
vector<ll> seg[4][4*N];
void ins(ll sid,ll id,ll l,ll r,ll tox,ll toy){
seg[sid][id].pb(toy);
if(l==r-1)return ;
ll mid=(l+r)>>1;
if(tox<mid){
ins(sid,id*2,l,mid,tox,toy);
}else{
ins(sid,id*2+1,mid,r,tox,toy);
}
}
ll query(ll sid,ll id,ll l,ll r,ll fl,ll fr,ll bl,ll br){
if(l>=fl&&r<=fr){
return -1*(lwb(seg[sid][id].begin(),seg[sid][id].end(),br)-lwb(seg[sid][id].begin(),seg[sid][id].end(),bl));
}
if(l>=fr||r<=fl)return 0;
ll mid=(l+r)>>1;
return query(sid,id*2,l,mid,fl,fr,bl,br)+query(sid,id*2+1,mid,r,fl,fr,bl,br);
}
//for [ar,br] [ac,bc]
//sid=0 V : [ar,br] [ac,bc]
//sid=1 VE : [ar,br) [ac,bc]
//sid=2 HE : [ar,br] [ac,bc)
//sid=3 F : [ar,br) [ac,bc)
int mir,mxr,mic,mxc;
void init(int R,int C,int sr,int sc,int M,char *S){
vector<pll> v[4];
mic=mxc=sc;
mir=mxr=sr;
for(int i=0;i<=M;i++){
mic=min(mic,sc);mxc=max(mxc,sc);
mir=min(mir,sr);mxr=max(mxr,sr);
v[0].pb(mp(sr,sc));
v[1].pb(mp(sr,sc));v[1].pb(mp(sr-1,sc));
v[2].pb(mp(sr,sc));v[2].pb(mp(sr,sc-1));
v[3].pb(mp(sr,sc));v[3].pb(mp(sr-1,sc));v[3].pb(mp(sr,sc-1));v[3].pb(mp(sr-1,sc-1));
//
if(i==M)break;
if(S[i]=='N')--sr;
if(S[i]=='S')++sr;
if(S[i]=='W')--sc;
if(S[i]=='E')++sc;
}
//unique
for(int i=0;i<4;i++)sort(v[i].begin(),v[i].end()),v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
//
for(int sid=0;sid<4;sid++){
for(auto i:v[sid]){
ins(sid,1,0,N,i.X,i.Y);
}
REP(i,4*N)sort(seg[sid][i].begin(),seg[sid][i].end());
}
}
int colour(int ar,int ac,int br,int bc){
ll ans=(br-ar+1)*(bc-ac+1)-(br-ar)*(bc-ac+1)-(br-ar+1)*(bc-ac)+(br-ar)*(bc-ac);
ans+=query(0,1,0,N,ar,br+1,ac,bc+1);
ans-=query(1,1,0,N,ar,br,ac,bc+1);
ans-=query(2,1,0,N,ar,br+1,ac,bc);
ans+=query(3,1,0,N,ar,br,ac,bc);
ans+=(mxc<bc&&mic>ac&&mxr<br&&mir>ar?1:0);
return ans;
}
/*
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
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";
return 0;
}
//*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
75700 KB |
Output is correct |
2 |
Correct |
67 ms |
76652 KB |
Output is correct |
3 |
Correct |
57 ms |
75756 KB |
Output is correct |
4 |
Correct |
57 ms |
75884 KB |
Output is correct |
5 |
Correct |
63 ms |
77032 KB |
Output is correct |
6 |
Correct |
54 ms |
75628 KB |
Output is correct |
7 |
Correct |
54 ms |
75500 KB |
Output is correct |
8 |
Correct |
54 ms |
75628 KB |
Output is correct |
9 |
Correct |
55 ms |
75500 KB |
Output is correct |
10 |
Correct |
54 ms |
75500 KB |
Output is correct |
11 |
Correct |
62 ms |
76012 KB |
Output is correct |
12 |
Correct |
60 ms |
76396 KB |
Output is correct |
13 |
Correct |
64 ms |
77164 KB |
Output is correct |
14 |
Correct |
67 ms |
77928 KB |
Output is correct |
15 |
Correct |
53 ms |
75500 KB |
Output is correct |
16 |
Correct |
55 ms |
75500 KB |
Output is correct |
17 |
Correct |
60 ms |
75500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
75500 KB |
Output is correct |
2 |
Correct |
60 ms |
75500 KB |
Output is correct |
3 |
Correct |
757 ms |
142848 KB |
Output is correct |
4 |
Correct |
1076 ms |
195492 KB |
Output is correct |
5 |
Correct |
1103 ms |
195056 KB |
Output is correct |
6 |
Correct |
911 ms |
182564 KB |
Output is correct |
7 |
Correct |
848 ms |
175140 KB |
Output is correct |
8 |
Correct |
249 ms |
91684 KB |
Output is correct |
9 |
Correct |
954 ms |
195364 KB |
Output is correct |
10 |
Correct |
1059 ms |
194876 KB |
Output is correct |
11 |
Correct |
902 ms |
182436 KB |
Output is correct |
12 |
Correct |
1105 ms |
191316 KB |
Output is correct |
13 |
Correct |
956 ms |
195364 KB |
Output is correct |
14 |
Correct |
958 ms |
194980 KB |
Output is correct |
15 |
Correct |
857 ms |
182436 KB |
Output is correct |
16 |
Correct |
872 ms |
177444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
75500 KB |
Output is correct |
2 |
Correct |
1069 ms |
195536 KB |
Output is correct |
3 |
Correct |
527 ms |
208548 KB |
Output is correct |
4 |
Correct |
525 ms |
211732 KB |
Output is correct |
5 |
Correct |
535 ms |
172840 KB |
Output is correct |
6 |
Correct |
228 ms |
109604 KB |
Output is correct |
7 |
Correct |
352 ms |
129060 KB |
Output is correct |
8 |
Correct |
675 ms |
187300 KB |
Output is correct |
9 |
Correct |
630 ms |
183076 KB |
Output is correct |
10 |
Correct |
210 ms |
105352 KB |
Output is correct |
11 |
Correct |
422 ms |
144908 KB |
Output is correct |
12 |
Correct |
1080 ms |
195492 KB |
Output is correct |
13 |
Correct |
535 ms |
208548 KB |
Output is correct |
14 |
Correct |
521 ms |
211696 KB |
Output is correct |
15 |
Correct |
525 ms |
172964 KB |
Output is correct |
16 |
Correct |
225 ms |
106148 KB |
Output is correct |
17 |
Correct |
327 ms |
129316 KB |
Output is correct |
18 |
Correct |
625 ms |
201232 KB |
Output is correct |
19 |
Correct |
704 ms |
200740 KB |
Output is correct |
20 |
Correct |
724 ms |
203044 KB |
Output is correct |
21 |
Correct |
657 ms |
187172 KB |
Output is correct |
22 |
Correct |
624 ms |
182948 KB |
Output is correct |
23 |
Correct |
216 ms |
105276 KB |
Output is correct |
24 |
Correct |
421 ms |
144804 KB |
Output is correct |
25 |
Correct |
1066 ms |
195492 KB |
Output is correct |
26 |
Correct |
581 ms |
208656 KB |
Output is correct |
27 |
Correct |
522 ms |
211620 KB |
Output is correct |
28 |
Correct |
525 ms |
172836 KB |
Output is correct |
29 |
Correct |
212 ms |
106148 KB |
Output is correct |
30 |
Correct |
326 ms |
129188 KB |
Output is correct |
31 |
Correct |
611 ms |
201252 KB |
Output is correct |
32 |
Correct |
708 ms |
200612 KB |
Output is correct |
33 |
Correct |
749 ms |
203260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
75700 KB |
Output is correct |
2 |
Correct |
67 ms |
76652 KB |
Output is correct |
3 |
Correct |
57 ms |
75756 KB |
Output is correct |
4 |
Correct |
57 ms |
75884 KB |
Output is correct |
5 |
Correct |
63 ms |
77032 KB |
Output is correct |
6 |
Correct |
54 ms |
75628 KB |
Output is correct |
7 |
Correct |
54 ms |
75500 KB |
Output is correct |
8 |
Correct |
54 ms |
75628 KB |
Output is correct |
9 |
Correct |
55 ms |
75500 KB |
Output is correct |
10 |
Correct |
54 ms |
75500 KB |
Output is correct |
11 |
Correct |
62 ms |
76012 KB |
Output is correct |
12 |
Correct |
60 ms |
76396 KB |
Output is correct |
13 |
Correct |
64 ms |
77164 KB |
Output is correct |
14 |
Correct |
67 ms |
77928 KB |
Output is correct |
15 |
Correct |
53 ms |
75500 KB |
Output is correct |
16 |
Correct |
55 ms |
75500 KB |
Output is correct |
17 |
Correct |
60 ms |
75500 KB |
Output is correct |
18 |
Correct |
1560 ms |
148644 KB |
Output is correct |
19 |
Correct |
297 ms |
82016 KB |
Output is correct |
20 |
Correct |
277 ms |
79468 KB |
Output is correct |
21 |
Correct |
284 ms |
80108 KB |
Output is correct |
22 |
Correct |
304 ms |
80688 KB |
Output is correct |
23 |
Correct |
277 ms |
81812 KB |
Output is correct |
24 |
Correct |
321 ms |
80004 KB |
Output is correct |
25 |
Correct |
318 ms |
80608 KB |
Output is correct |
26 |
Correct |
320 ms |
81076 KB |
Output is correct |
27 |
Correct |
869 ms |
136100 KB |
Output is correct |
28 |
Correct |
673 ms |
110372 KB |
Output is correct |
29 |
Correct |
828 ms |
128548 KB |
Output is correct |
30 |
Correct |
1525 ms |
201636 KB |
Output is correct |
31 |
Correct |
64 ms |
75756 KB |
Output is correct |
32 |
Correct |
1259 ms |
139180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
75700 KB |
Output is correct |
2 |
Correct |
67 ms |
76652 KB |
Output is correct |
3 |
Correct |
57 ms |
75756 KB |
Output is correct |
4 |
Correct |
57 ms |
75884 KB |
Output is correct |
5 |
Correct |
63 ms |
77032 KB |
Output is correct |
6 |
Correct |
54 ms |
75628 KB |
Output is correct |
7 |
Correct |
54 ms |
75500 KB |
Output is correct |
8 |
Correct |
54 ms |
75628 KB |
Output is correct |
9 |
Correct |
55 ms |
75500 KB |
Output is correct |
10 |
Correct |
54 ms |
75500 KB |
Output is correct |
11 |
Correct |
62 ms |
76012 KB |
Output is correct |
12 |
Correct |
60 ms |
76396 KB |
Output is correct |
13 |
Correct |
64 ms |
77164 KB |
Output is correct |
14 |
Correct |
67 ms |
77928 KB |
Output is correct |
15 |
Correct |
53 ms |
75500 KB |
Output is correct |
16 |
Correct |
55 ms |
75500 KB |
Output is correct |
17 |
Correct |
60 ms |
75500 KB |
Output is correct |
18 |
Correct |
1560 ms |
148644 KB |
Output is correct |
19 |
Correct |
297 ms |
82016 KB |
Output is correct |
20 |
Correct |
277 ms |
79468 KB |
Output is correct |
21 |
Correct |
284 ms |
80108 KB |
Output is correct |
22 |
Correct |
304 ms |
80688 KB |
Output is correct |
23 |
Correct |
277 ms |
81812 KB |
Output is correct |
24 |
Correct |
321 ms |
80004 KB |
Output is correct |
25 |
Correct |
318 ms |
80608 KB |
Output is correct |
26 |
Correct |
320 ms |
81076 KB |
Output is correct |
27 |
Correct |
869 ms |
136100 KB |
Output is correct |
28 |
Correct |
673 ms |
110372 KB |
Output is correct |
29 |
Correct |
828 ms |
128548 KB |
Output is correct |
30 |
Correct |
1525 ms |
201636 KB |
Output is correct |
31 |
Correct |
64 ms |
75756 KB |
Output is correct |
32 |
Correct |
1259 ms |
139180 KB |
Output is correct |
33 |
Correct |
1069 ms |
195536 KB |
Output is correct |
34 |
Correct |
527 ms |
208548 KB |
Output is correct |
35 |
Correct |
525 ms |
211732 KB |
Output is correct |
36 |
Correct |
535 ms |
172840 KB |
Output is correct |
37 |
Correct |
228 ms |
109604 KB |
Output is correct |
38 |
Correct |
352 ms |
129060 KB |
Output is correct |
39 |
Correct |
675 ms |
187300 KB |
Output is correct |
40 |
Correct |
630 ms |
183076 KB |
Output is correct |
41 |
Correct |
210 ms |
105352 KB |
Output is correct |
42 |
Correct |
422 ms |
144908 KB |
Output is correct |
43 |
Correct |
1080 ms |
195492 KB |
Output is correct |
44 |
Correct |
535 ms |
208548 KB |
Output is correct |
45 |
Correct |
521 ms |
211696 KB |
Output is correct |
46 |
Correct |
525 ms |
172964 KB |
Output is correct |
47 |
Correct |
225 ms |
106148 KB |
Output is correct |
48 |
Correct |
327 ms |
129316 KB |
Output is correct |
49 |
Correct |
625 ms |
201232 KB |
Output is correct |
50 |
Correct |
704 ms |
200740 KB |
Output is correct |
51 |
Correct |
724 ms |
203044 KB |
Output is correct |
52 |
Correct |
657 ms |
187172 KB |
Output is correct |
53 |
Correct |
624 ms |
182948 KB |
Output is correct |
54 |
Correct |
216 ms |
105276 KB |
Output is correct |
55 |
Correct |
421 ms |
144804 KB |
Output is correct |
56 |
Correct |
1066 ms |
195492 KB |
Output is correct |
57 |
Correct |
581 ms |
208656 KB |
Output is correct |
58 |
Correct |
522 ms |
211620 KB |
Output is correct |
59 |
Correct |
525 ms |
172836 KB |
Output is correct |
60 |
Correct |
212 ms |
106148 KB |
Output is correct |
61 |
Correct |
326 ms |
129188 KB |
Output is correct |
62 |
Correct |
611 ms |
201252 KB |
Output is correct |
63 |
Correct |
708 ms |
200612 KB |
Output is correct |
64 |
Correct |
749 ms |
203260 KB |
Output is correct |
65 |
Correct |
757 ms |
142848 KB |
Output is correct |
66 |
Correct |
1076 ms |
195492 KB |
Output is correct |
67 |
Correct |
1103 ms |
195056 KB |
Output is correct |
68 |
Correct |
911 ms |
182564 KB |
Output is correct |
69 |
Correct |
848 ms |
175140 KB |
Output is correct |
70 |
Correct |
249 ms |
91684 KB |
Output is correct |
71 |
Correct |
954 ms |
195364 KB |
Output is correct |
72 |
Correct |
1059 ms |
194876 KB |
Output is correct |
73 |
Correct |
902 ms |
182436 KB |
Output is correct |
74 |
Correct |
1105 ms |
191316 KB |
Output is correct |
75 |
Correct |
956 ms |
195364 KB |
Output is correct |
76 |
Correct |
958 ms |
194980 KB |
Output is correct |
77 |
Correct |
857 ms |
182436 KB |
Output is correct |
78 |
Correct |
872 ms |
177444 KB |
Output is correct |
79 |
Correct |
994 ms |
187392 KB |
Output is correct |
80 |
Correct |
1006 ms |
183168 KB |
Output is correct |
81 |
Correct |
560 ms |
105532 KB |
Output is correct |
82 |
Correct |
932 ms |
145028 KB |
Output is correct |
83 |
Correct |
1644 ms |
195896 KB |
Output is correct |
84 |
Correct |
1448 ms |
208932 KB |
Output is correct |
85 |
Correct |
1085 ms |
211748 KB |
Output is correct |
86 |
Correct |
1173 ms |
173276 KB |
Output is correct |
87 |
Correct |
663 ms |
106276 KB |
Output is correct |
88 |
Correct |
807 ms |
129444 KB |
Output is correct |
89 |
Correct |
1036 ms |
201700 KB |
Output is correct |
90 |
Correct |
1413 ms |
200996 KB |
Output is correct |
91 |
Correct |
1489 ms |
203456 KB |
Output is correct |