#include "rainbow.h"
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef pair<int64_t,int64_t> pii;
typedef vector<int64_t> VI;
#define REP(i,j,k) for(int64_t i=(j);i<(k);++i)
#define ALL(a) a.begin(),a.end()
#define pb push_back
#define de(...) cerr<<__VA_ARGS__
#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
// default
const int64_t maxn=2e5+9,inf=1ll<<60;
struct FW{
int64_t n;
VI dat[maxn];
void init(int64_t _n){
n=_n;
REP(i,0,n+1)dat[i].clear();
}
void add(int64_t x,int64_t y){
for(int64_t i=x;i<=n;i+=i&-i){
dat[i].pb(y);
}
}
void proc(){
REP(i,0,n+1)sort(ALL(dat[i]));
}
int64_t sum(int64_t x,int64_t y){
int64_t re=0;
for(int64_t i=x;i>0;i-=i&-i){
re+=upper_bound(ALL(dat[i]),y)-dat[i].begin();
}
return re;
}
}be1,be2,bf,bv;
set<pii>st,vt;
int64_t mxx=-inf,mxy=-inf,mnx=inf,mny=inf;
void init(int n,int m,int curx,int cury,int len,char*s){
be1.init(n);
be2.init(n+1);
bf.init(n);
bv.init(n+1);
REP(i,0,len+1){
if(!st.count(pii(curx,cury))){
mxx=max(mxx,(int64_t)curx);
mxy=max(mxy,(int64_t)cury);
mnx=min(mnx,(int64_t)curx);
mny=min(mny,(int64_t)cury);
if(!st.count(pii(curx-1,cury)))be1.add(curx,cury);
if(!st.count(pii(curx+1,cury)))be1.add(curx+1,cury);
if(!st.count(pii(curx,cury-1)))be2.add(curx,cury);
if(!st.count(pii(curx,cury+1)))be2.add(curx,cury+1);
REP(x,curx,curx+2)REP(y,cury,cury+2){
if(!vt.count(pii(x,y))){
bv.add(x,y);
vt.insert(pii(x,y));
}
}
bf.add(curx,cury);
st.insert(pii(curx,cury));
}
if(i<len){
if(s[i]=='N')--curx;
else if(s[i]=='E')++cury;
else if(s[i]=='W')--cury;
else ++curx; // S
}
}
be1.proc();
be2.proc();
bf.proc();
bv.proc();
}
int64_t calc(FW&fw,int64_t sx,int64_t sy,int64_t tx,int64_t ty){
return fw.sum(tx,ty)-fw.sum(sx,ty)-fw.sum(tx,sy)+fw.sum(sx,sy);
}
int colour(int sx,int sy,int tx,int ty){
int64_t e=calc(be1,sx,sy-1,tx,ty)+calc(be2,sx-1,sy,tx,ty)+2*(tx-sx+ty-sy+2);
int64_t v=calc(bv,sx,sy,tx,ty)+2*(tx-sx+ty-sy+2);
int64_t ff=calc(bf,sx-1,sy-1,tx,ty);
// de("e = "<<e<<" , "<<"v = "<<v<<" , "<<"ff = "<<ff<<endl);
return e-v+2-ff-1+(sx<mnx&&mxx<tx&&sy<mny&&mxy<ty);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
19200 KB |
Output is correct |
2 |
Correct |
23 ms |
19456 KB |
Output is correct |
3 |
Correct |
21 ms |
19200 KB |
Output is correct |
4 |
Correct |
22 ms |
19196 KB |
Output is correct |
5 |
Correct |
25 ms |
19584 KB |
Output is correct |
6 |
Correct |
19 ms |
19072 KB |
Output is correct |
7 |
Correct |
20 ms |
19044 KB |
Output is correct |
8 |
Correct |
22 ms |
19072 KB |
Output is correct |
9 |
Correct |
24 ms |
19072 KB |
Output is correct |
10 |
Correct |
21 ms |
19072 KB |
Output is correct |
11 |
Correct |
28 ms |
19328 KB |
Output is correct |
12 |
Correct |
26 ms |
19456 KB |
Output is correct |
13 |
Correct |
27 ms |
19704 KB |
Output is correct |
14 |
Correct |
29 ms |
19840 KB |
Output is correct |
15 |
Correct |
20 ms |
19200 KB |
Output is correct |
16 |
Correct |
20 ms |
19072 KB |
Output is correct |
17 |
Correct |
20 ms |
19072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
19072 KB |
Output is correct |
2 |
Correct |
20 ms |
19072 KB |
Output is correct |
3 |
Correct |
378 ms |
34932 KB |
Output is correct |
4 |
Correct |
442 ms |
44908 KB |
Output is correct |
5 |
Correct |
440 ms |
44740 KB |
Output is correct |
6 |
Correct |
330 ms |
39008 KB |
Output is correct |
7 |
Correct |
384 ms |
39096 KB |
Output is correct |
8 |
Correct |
81 ms |
20124 KB |
Output is correct |
9 |
Correct |
461 ms |
45088 KB |
Output is correct |
10 |
Correct |
414 ms |
44732 KB |
Output is correct |
11 |
Correct |
347 ms |
39064 KB |
Output is correct |
12 |
Correct |
326 ms |
42864 KB |
Output is correct |
13 |
Correct |
285 ms |
44728 KB |
Output is correct |
14 |
Correct |
288 ms |
44584 KB |
Output is correct |
15 |
Correct |
259 ms |
39240 KB |
Output is correct |
16 |
Correct |
348 ms |
38080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
19200 KB |
Output is correct |
2 |
Correct |
437 ms |
83556 KB |
Output is correct |
3 |
Correct |
430 ms |
88936 KB |
Output is correct |
4 |
Correct |
439 ms |
94696 KB |
Output is correct |
5 |
Correct |
386 ms |
71264 KB |
Output is correct |
6 |
Correct |
131 ms |
33088 KB |
Output is correct |
7 |
Correct |
235 ms |
41732 KB |
Output is correct |
8 |
Correct |
260 ms |
43816 KB |
Output is correct |
9 |
Correct |
262 ms |
43344 KB |
Output is correct |
10 |
Correct |
110 ms |
26192 KB |
Output is correct |
11 |
Correct |
193 ms |
36308 KB |
Output is correct |
12 |
Correct |
453 ms |
83632 KB |
Output is correct |
13 |
Correct |
450 ms |
89068 KB |
Output is correct |
14 |
Correct |
474 ms |
94720 KB |
Output is correct |
15 |
Correct |
399 ms |
71264 KB |
Output is correct |
16 |
Correct |
114 ms |
30160 KB |
Output is correct |
17 |
Correct |
248 ms |
48596 KB |
Output is correct |
18 |
Correct |
702 ms |
107040 KB |
Output is correct |
19 |
Correct |
536 ms |
89928 KB |
Output is correct |
20 |
Correct |
510 ms |
96488 KB |
Output is correct |
21 |
Correct |
260 ms |
43676 KB |
Output is correct |
22 |
Correct |
264 ms |
43328 KB |
Output is correct |
23 |
Correct |
92 ms |
26092 KB |
Output is correct |
24 |
Correct |
207 ms |
36280 KB |
Output is correct |
25 |
Correct |
451 ms |
83672 KB |
Output is correct |
26 |
Correct |
447 ms |
88908 KB |
Output is correct |
27 |
Correct |
442 ms |
94700 KB |
Output is correct |
28 |
Correct |
369 ms |
71364 KB |
Output is correct |
29 |
Correct |
103 ms |
30284 KB |
Output is correct |
30 |
Correct |
268 ms |
48544 KB |
Output is correct |
31 |
Correct |
816 ms |
106872 KB |
Output is correct |
32 |
Correct |
480 ms |
90092 KB |
Output is correct |
33 |
Correct |
510 ms |
96304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
19200 KB |
Output is correct |
2 |
Correct |
23 ms |
19456 KB |
Output is correct |
3 |
Correct |
21 ms |
19200 KB |
Output is correct |
4 |
Correct |
22 ms |
19196 KB |
Output is correct |
5 |
Correct |
25 ms |
19584 KB |
Output is correct |
6 |
Correct |
19 ms |
19072 KB |
Output is correct |
7 |
Correct |
20 ms |
19044 KB |
Output is correct |
8 |
Correct |
22 ms |
19072 KB |
Output is correct |
9 |
Correct |
24 ms |
19072 KB |
Output is correct |
10 |
Correct |
21 ms |
19072 KB |
Output is correct |
11 |
Correct |
28 ms |
19328 KB |
Output is correct |
12 |
Correct |
26 ms |
19456 KB |
Output is correct |
13 |
Correct |
27 ms |
19704 KB |
Output is correct |
14 |
Correct |
29 ms |
19840 KB |
Output is correct |
15 |
Correct |
20 ms |
19200 KB |
Output is correct |
16 |
Correct |
20 ms |
19072 KB |
Output is correct |
17 |
Correct |
20 ms |
19072 KB |
Output is correct |
18 |
Correct |
1446 ms |
46980 KB |
Output is correct |
19 |
Correct |
307 ms |
23608 KB |
Output is correct |
20 |
Correct |
236 ms |
22756 KB |
Output is correct |
21 |
Correct |
300 ms |
22972 KB |
Output is correct |
22 |
Correct |
322 ms |
23288 KB |
Output is correct |
23 |
Correct |
306 ms |
23436 KB |
Output is correct |
24 |
Correct |
284 ms |
23032 KB |
Output is correct |
25 |
Correct |
328 ms |
23260 KB |
Output is correct |
26 |
Correct |
318 ms |
23416 KB |
Output is correct |
27 |
Correct |
557 ms |
40424 KB |
Output is correct |
28 |
Correct |
415 ms |
32112 KB |
Output is correct |
29 |
Correct |
526 ms |
38484 KB |
Output is correct |
30 |
Correct |
1269 ms |
72168 KB |
Output is correct |
31 |
Correct |
24 ms |
19200 KB |
Output is correct |
32 |
Correct |
1048 ms |
42176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
19200 KB |
Output is correct |
2 |
Correct |
23 ms |
19456 KB |
Output is correct |
3 |
Correct |
21 ms |
19200 KB |
Output is correct |
4 |
Correct |
22 ms |
19196 KB |
Output is correct |
5 |
Correct |
25 ms |
19584 KB |
Output is correct |
6 |
Correct |
19 ms |
19072 KB |
Output is correct |
7 |
Correct |
20 ms |
19044 KB |
Output is correct |
8 |
Correct |
22 ms |
19072 KB |
Output is correct |
9 |
Correct |
24 ms |
19072 KB |
Output is correct |
10 |
Correct |
21 ms |
19072 KB |
Output is correct |
11 |
Correct |
28 ms |
19328 KB |
Output is correct |
12 |
Correct |
26 ms |
19456 KB |
Output is correct |
13 |
Correct |
27 ms |
19704 KB |
Output is correct |
14 |
Correct |
29 ms |
19840 KB |
Output is correct |
15 |
Correct |
20 ms |
19200 KB |
Output is correct |
16 |
Correct |
20 ms |
19072 KB |
Output is correct |
17 |
Correct |
20 ms |
19072 KB |
Output is correct |
18 |
Correct |
1446 ms |
46980 KB |
Output is correct |
19 |
Correct |
307 ms |
23608 KB |
Output is correct |
20 |
Correct |
236 ms |
22756 KB |
Output is correct |
21 |
Correct |
300 ms |
22972 KB |
Output is correct |
22 |
Correct |
322 ms |
23288 KB |
Output is correct |
23 |
Correct |
306 ms |
23436 KB |
Output is correct |
24 |
Correct |
284 ms |
23032 KB |
Output is correct |
25 |
Correct |
328 ms |
23260 KB |
Output is correct |
26 |
Correct |
318 ms |
23416 KB |
Output is correct |
27 |
Correct |
557 ms |
40424 KB |
Output is correct |
28 |
Correct |
415 ms |
32112 KB |
Output is correct |
29 |
Correct |
526 ms |
38484 KB |
Output is correct |
30 |
Correct |
1269 ms |
72168 KB |
Output is correct |
31 |
Correct |
24 ms |
19200 KB |
Output is correct |
32 |
Correct |
1048 ms |
42176 KB |
Output is correct |
33 |
Correct |
437 ms |
83556 KB |
Output is correct |
34 |
Correct |
430 ms |
88936 KB |
Output is correct |
35 |
Correct |
439 ms |
94696 KB |
Output is correct |
36 |
Correct |
386 ms |
71264 KB |
Output is correct |
37 |
Correct |
131 ms |
33088 KB |
Output is correct |
38 |
Correct |
235 ms |
41732 KB |
Output is correct |
39 |
Correct |
260 ms |
43816 KB |
Output is correct |
40 |
Correct |
262 ms |
43344 KB |
Output is correct |
41 |
Correct |
110 ms |
26192 KB |
Output is correct |
42 |
Correct |
193 ms |
36308 KB |
Output is correct |
43 |
Correct |
453 ms |
83632 KB |
Output is correct |
44 |
Correct |
450 ms |
89068 KB |
Output is correct |
45 |
Correct |
474 ms |
94720 KB |
Output is correct |
46 |
Correct |
399 ms |
71264 KB |
Output is correct |
47 |
Correct |
114 ms |
30160 KB |
Output is correct |
48 |
Correct |
248 ms |
48596 KB |
Output is correct |
49 |
Correct |
702 ms |
107040 KB |
Output is correct |
50 |
Correct |
536 ms |
89928 KB |
Output is correct |
51 |
Correct |
510 ms |
96488 KB |
Output is correct |
52 |
Correct |
260 ms |
43676 KB |
Output is correct |
53 |
Correct |
264 ms |
43328 KB |
Output is correct |
54 |
Correct |
92 ms |
26092 KB |
Output is correct |
55 |
Correct |
207 ms |
36280 KB |
Output is correct |
56 |
Correct |
451 ms |
83672 KB |
Output is correct |
57 |
Correct |
447 ms |
88908 KB |
Output is correct |
58 |
Correct |
442 ms |
94700 KB |
Output is correct |
59 |
Correct |
369 ms |
71364 KB |
Output is correct |
60 |
Correct |
103 ms |
30284 KB |
Output is correct |
61 |
Correct |
268 ms |
48544 KB |
Output is correct |
62 |
Correct |
816 ms |
106872 KB |
Output is correct |
63 |
Correct |
480 ms |
90092 KB |
Output is correct |
64 |
Correct |
510 ms |
96304 KB |
Output is correct |
65 |
Correct |
673 ms |
47188 KB |
Output is correct |
66 |
Correct |
841 ms |
46400 KB |
Output is correct |
67 |
Correct |
414 ms |
29404 KB |
Output is correct |
68 |
Correct |
526 ms |
39956 KB |
Output is correct |
69 |
Correct |
903 ms |
87212 KB |
Output is correct |
70 |
Correct |
1225 ms |
92312 KB |
Output is correct |
71 |
Correct |
947 ms |
98128 KB |
Output is correct |
72 |
Correct |
859 ms |
74860 KB |
Output is correct |
73 |
Correct |
431 ms |
33632 KB |
Output is correct |
74 |
Correct |
528 ms |
51980 KB |
Output is correct |
75 |
Correct |
1018 ms |
110436 KB |
Output is correct |
76 |
Correct |
1093 ms |
93452 KB |
Output is correct |
77 |
Correct |
855 ms |
99988 KB |
Output is correct |
78 |
Correct |
378 ms |
34932 KB |
Output is correct |
79 |
Correct |
442 ms |
44908 KB |
Output is correct |
80 |
Correct |
440 ms |
44740 KB |
Output is correct |
81 |
Correct |
330 ms |
39008 KB |
Output is correct |
82 |
Correct |
384 ms |
39096 KB |
Output is correct |
83 |
Correct |
81 ms |
20124 KB |
Output is correct |
84 |
Correct |
461 ms |
45088 KB |
Output is correct |
85 |
Correct |
414 ms |
44732 KB |
Output is correct |
86 |
Correct |
347 ms |
39064 KB |
Output is correct |
87 |
Correct |
326 ms |
42864 KB |
Output is correct |
88 |
Correct |
285 ms |
44728 KB |
Output is correct |
89 |
Correct |
288 ms |
44584 KB |
Output is correct |
90 |
Correct |
259 ms |
39240 KB |
Output is correct |
91 |
Correct |
348 ms |
38080 KB |
Output is correct |