#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(),[](pll A,pll B){
if(A.Y!=B.Y)return A.Y<B.Y;
return A.X<B.X;
}),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=1;
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;
}
//*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
75776 KB |
Output is correct |
2 |
Correct |
53 ms |
76652 KB |
Output is correct |
3 |
Correct |
51 ms |
75776 KB |
Output is correct |
4 |
Correct |
52 ms |
75884 KB |
Output is correct |
5 |
Correct |
56 ms |
77104 KB |
Output is correct |
6 |
Correct |
47 ms |
75500 KB |
Output is correct |
7 |
Correct |
47 ms |
75500 KB |
Output is correct |
8 |
Correct |
47 ms |
75500 KB |
Output is correct |
9 |
Correct |
46 ms |
75500 KB |
Output is correct |
10 |
Correct |
48 ms |
75500 KB |
Output is correct |
11 |
Correct |
58 ms |
76012 KB |
Output is correct |
12 |
Correct |
52 ms |
76396 KB |
Output is correct |
13 |
Correct |
60 ms |
77164 KB |
Output is correct |
14 |
Correct |
64 ms |
77928 KB |
Output is correct |
15 |
Correct |
47 ms |
75520 KB |
Output is correct |
16 |
Correct |
46 ms |
75500 KB |
Output is correct |
17 |
Correct |
47 ms |
75500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
75500 KB |
Output is correct |
2 |
Correct |
47 ms |
75500 KB |
Output is correct |
3 |
Correct |
340 ms |
142140 KB |
Output is correct |
4 |
Correct |
442 ms |
195008 KB |
Output is correct |
5 |
Correct |
482 ms |
195492 KB |
Output is correct |
6 |
Correct |
401 ms |
182820 KB |
Output is correct |
7 |
Correct |
428 ms |
174756 KB |
Output is correct |
8 |
Correct |
254 ms |
91568 KB |
Output is correct |
9 |
Correct |
470 ms |
196772 KB |
Output is correct |
10 |
Correct |
450 ms |
196900 KB |
Output is correct |
11 |
Correct |
437 ms |
183716 KB |
Output is correct |
12 |
Correct |
368 ms |
190372 KB |
Output is correct |
13 |
Correct |
383 ms |
195876 KB |
Output is correct |
14 |
Correct |
377 ms |
195236 KB |
Output is correct |
15 |
Correct |
392 ms |
181924 KB |
Output is correct |
16 |
Correct |
373 ms |
176548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
75520 KB |
Output is correct |
2 |
Correct |
262 ms |
196004 KB |
Output is correct |
3 |
Correct |
502 ms |
209572 KB |
Output is correct |
4 |
Correct |
379 ms |
211792 KB |
Output is correct |
5 |
Correct |
315 ms |
174508 KB |
Output is correct |
6 |
Correct |
193 ms |
109348 KB |
Output is correct |
7 |
Correct |
218 ms |
128932 KB |
Output is correct |
8 |
Correct |
318 ms |
188580 KB |
Output is correct |
9 |
Correct |
316 ms |
180644 KB |
Output is correct |
10 |
Correct |
145 ms |
105404 KB |
Output is correct |
11 |
Correct |
251 ms |
145188 KB |
Output is correct |
12 |
Correct |
260 ms |
195996 KB |
Output is correct |
13 |
Correct |
458 ms |
209552 KB |
Output is correct |
14 |
Correct |
381 ms |
211584 KB |
Output is correct |
15 |
Correct |
326 ms |
174500 KB |
Output is correct |
16 |
Correct |
190 ms |
106276 KB |
Output is correct |
17 |
Correct |
211 ms |
129328 KB |
Output is correct |
18 |
Correct |
297 ms |
201380 KB |
Output is correct |
19 |
Correct |
363 ms |
202660 KB |
Output is correct |
20 |
Correct |
356 ms |
203300 KB |
Output is correct |
21 |
Correct |
317 ms |
188580 KB |
Output is correct |
22 |
Correct |
327 ms |
180624 KB |
Output is correct |
23 |
Correct |
161 ms |
105404 KB |
Output is correct |
24 |
Correct |
244 ms |
145188 KB |
Output is correct |
25 |
Correct |
254 ms |
195876 KB |
Output is correct |
26 |
Correct |
513 ms |
209700 KB |
Output is correct |
27 |
Correct |
377 ms |
211748 KB |
Output is correct |
28 |
Correct |
317 ms |
174500 KB |
Output is correct |
29 |
Correct |
195 ms |
106448 KB |
Output is correct |
30 |
Correct |
212 ms |
129316 KB |
Output is correct |
31 |
Correct |
282 ms |
201380 KB |
Output is correct |
32 |
Correct |
405 ms |
202660 KB |
Output is correct |
33 |
Correct |
354 ms |
203300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
75776 KB |
Output is correct |
2 |
Correct |
53 ms |
76652 KB |
Output is correct |
3 |
Correct |
51 ms |
75776 KB |
Output is correct |
4 |
Correct |
52 ms |
75884 KB |
Output is correct |
5 |
Correct |
56 ms |
77104 KB |
Output is correct |
6 |
Correct |
47 ms |
75500 KB |
Output is correct |
7 |
Correct |
47 ms |
75500 KB |
Output is correct |
8 |
Correct |
47 ms |
75500 KB |
Output is correct |
9 |
Correct |
46 ms |
75500 KB |
Output is correct |
10 |
Correct |
48 ms |
75500 KB |
Output is correct |
11 |
Correct |
58 ms |
76012 KB |
Output is correct |
12 |
Correct |
52 ms |
76396 KB |
Output is correct |
13 |
Correct |
60 ms |
77164 KB |
Output is correct |
14 |
Correct |
64 ms |
77928 KB |
Output is correct |
15 |
Correct |
47 ms |
75520 KB |
Output is correct |
16 |
Correct |
46 ms |
75500 KB |
Output is correct |
17 |
Correct |
47 ms |
75500 KB |
Output is correct |
18 |
Correct |
1532 ms |
147364 KB |
Output is correct |
19 |
Correct |
277 ms |
79328 KB |
Output is correct |
20 |
Correct |
293 ms |
76780 KB |
Output is correct |
21 |
Correct |
284 ms |
77452 KB |
Output is correct |
22 |
Correct |
349 ms |
77980 KB |
Output is correct |
23 |
Correct |
266 ms |
79068 KB |
Output is correct |
24 |
Correct |
313 ms |
77188 KB |
Output is correct |
25 |
Correct |
320 ms |
77908 KB |
Output is correct |
26 |
Correct |
356 ms |
78388 KB |
Output is correct |
27 |
Correct |
702 ms |
135972 KB |
Output is correct |
28 |
Correct |
614 ms |
110116 KB |
Output is correct |
29 |
Correct |
689 ms |
128676 KB |
Output is correct |
30 |
Correct |
1197 ms |
201380 KB |
Output is correct |
31 |
Correct |
53 ms |
75500 KB |
Output is correct |
32 |
Correct |
1158 ms |
137636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
75776 KB |
Output is correct |
2 |
Correct |
53 ms |
76652 KB |
Output is correct |
3 |
Correct |
51 ms |
75776 KB |
Output is correct |
4 |
Correct |
52 ms |
75884 KB |
Output is correct |
5 |
Correct |
56 ms |
77104 KB |
Output is correct |
6 |
Correct |
47 ms |
75500 KB |
Output is correct |
7 |
Correct |
47 ms |
75500 KB |
Output is correct |
8 |
Correct |
47 ms |
75500 KB |
Output is correct |
9 |
Correct |
46 ms |
75500 KB |
Output is correct |
10 |
Correct |
48 ms |
75500 KB |
Output is correct |
11 |
Correct |
58 ms |
76012 KB |
Output is correct |
12 |
Correct |
52 ms |
76396 KB |
Output is correct |
13 |
Correct |
60 ms |
77164 KB |
Output is correct |
14 |
Correct |
64 ms |
77928 KB |
Output is correct |
15 |
Correct |
47 ms |
75520 KB |
Output is correct |
16 |
Correct |
46 ms |
75500 KB |
Output is correct |
17 |
Correct |
47 ms |
75500 KB |
Output is correct |
18 |
Correct |
1532 ms |
147364 KB |
Output is correct |
19 |
Correct |
277 ms |
79328 KB |
Output is correct |
20 |
Correct |
293 ms |
76780 KB |
Output is correct |
21 |
Correct |
284 ms |
77452 KB |
Output is correct |
22 |
Correct |
349 ms |
77980 KB |
Output is correct |
23 |
Correct |
266 ms |
79068 KB |
Output is correct |
24 |
Correct |
313 ms |
77188 KB |
Output is correct |
25 |
Correct |
320 ms |
77908 KB |
Output is correct |
26 |
Correct |
356 ms |
78388 KB |
Output is correct |
27 |
Correct |
702 ms |
135972 KB |
Output is correct |
28 |
Correct |
614 ms |
110116 KB |
Output is correct |
29 |
Correct |
689 ms |
128676 KB |
Output is correct |
30 |
Correct |
1197 ms |
201380 KB |
Output is correct |
31 |
Correct |
53 ms |
75500 KB |
Output is correct |
32 |
Correct |
1158 ms |
137636 KB |
Output is correct |
33 |
Correct |
262 ms |
196004 KB |
Output is correct |
34 |
Correct |
502 ms |
209572 KB |
Output is correct |
35 |
Correct |
379 ms |
211792 KB |
Output is correct |
36 |
Correct |
315 ms |
174508 KB |
Output is correct |
37 |
Correct |
193 ms |
109348 KB |
Output is correct |
38 |
Correct |
218 ms |
128932 KB |
Output is correct |
39 |
Correct |
318 ms |
188580 KB |
Output is correct |
40 |
Correct |
316 ms |
180644 KB |
Output is correct |
41 |
Correct |
145 ms |
105404 KB |
Output is correct |
42 |
Correct |
251 ms |
145188 KB |
Output is correct |
43 |
Correct |
260 ms |
195996 KB |
Output is correct |
44 |
Correct |
458 ms |
209552 KB |
Output is correct |
45 |
Correct |
381 ms |
211584 KB |
Output is correct |
46 |
Correct |
326 ms |
174500 KB |
Output is correct |
47 |
Correct |
190 ms |
106276 KB |
Output is correct |
48 |
Correct |
211 ms |
129328 KB |
Output is correct |
49 |
Correct |
297 ms |
201380 KB |
Output is correct |
50 |
Correct |
363 ms |
202660 KB |
Output is correct |
51 |
Correct |
356 ms |
203300 KB |
Output is correct |
52 |
Correct |
317 ms |
188580 KB |
Output is correct |
53 |
Correct |
327 ms |
180624 KB |
Output is correct |
54 |
Correct |
161 ms |
105404 KB |
Output is correct |
55 |
Correct |
244 ms |
145188 KB |
Output is correct |
56 |
Correct |
254 ms |
195876 KB |
Output is correct |
57 |
Correct |
513 ms |
209700 KB |
Output is correct |
58 |
Correct |
377 ms |
211748 KB |
Output is correct |
59 |
Correct |
317 ms |
174500 KB |
Output is correct |
60 |
Correct |
195 ms |
106448 KB |
Output is correct |
61 |
Correct |
212 ms |
129316 KB |
Output is correct |
62 |
Correct |
282 ms |
201380 KB |
Output is correct |
63 |
Correct |
405 ms |
202660 KB |
Output is correct |
64 |
Correct |
354 ms |
203300 KB |
Output is correct |
65 |
Correct |
340 ms |
142140 KB |
Output is correct |
66 |
Correct |
442 ms |
195008 KB |
Output is correct |
67 |
Correct |
482 ms |
195492 KB |
Output is correct |
68 |
Correct |
401 ms |
182820 KB |
Output is correct |
69 |
Correct |
428 ms |
174756 KB |
Output is correct |
70 |
Correct |
254 ms |
91568 KB |
Output is correct |
71 |
Correct |
470 ms |
196772 KB |
Output is correct |
72 |
Correct |
450 ms |
196900 KB |
Output is correct |
73 |
Correct |
437 ms |
183716 KB |
Output is correct |
74 |
Correct |
368 ms |
190372 KB |
Output is correct |
75 |
Correct |
383 ms |
195876 KB |
Output is correct |
76 |
Correct |
377 ms |
195236 KB |
Output is correct |
77 |
Correct |
392 ms |
181924 KB |
Output is correct |
78 |
Correct |
373 ms |
176548 KB |
Output is correct |
79 |
Correct |
646 ms |
188580 KB |
Output is correct |
80 |
Correct |
719 ms |
180644 KB |
Output is correct |
81 |
Correct |
578 ms |
105532 KB |
Output is correct |
82 |
Correct |
743 ms |
145188 KB |
Output is correct |
83 |
Correct |
755 ms |
196220 KB |
Output is correct |
84 |
Correct |
1394 ms |
209572 KB |
Output is correct |
85 |
Correct |
940 ms |
211620 KB |
Output is correct |
86 |
Correct |
934 ms |
174500 KB |
Output is correct |
87 |
Correct |
614 ms |
106404 KB |
Output is correct |
88 |
Correct |
635 ms |
129316 KB |
Output is correct |
89 |
Correct |
739 ms |
201272 KB |
Output is correct |
90 |
Correct |
1114 ms |
202660 KB |
Output is correct |
91 |
Correct |
1088 ms |
203300 KB |
Output is correct |