#include "rainbow.h"
#include <bits/stdc++.h>
using namespace std;
const int mxN=2e5, mxSTS=(6e5+9)*19+1;
int sts, st[mxSTS], lc[mxSTS], rc[mxSTS];
struct dat {
set<int> ta[mxN+1];
int rt[mxN+2];
void a(array<int, 2> a) {
ta[a[0]].insert(a[1]);
}
void bld() {
for(int i=0; i<=mxN; ++i) {
rt[i+1]=rt[i];
for(int j : ta[i])
upd(j, rt[i+1]);
}
}
void upd(int l1, int &i, int l2=0, int r2=mxN) {
st[sts]=st[i]+1;
lc[sts]=lc[i];
rc[sts]=rc[i];
i=sts++;
if(l2==r2)
return;
int m2=(l2+r2)/2;
if(l1<=m2)
upd(l1, lc[i], l2, m2);
else
upd(l1, rc[i], m2+1, r2);
}
int qry(int l1, int r1, int l2, int r2) {
return l2>r2?0:qry(l2, r2, rt[r1+1], 0, mxN)-qry(l2, r2, rt[l1], 0, mxN);
}
int qry(int l1, int r1, int i, int l2, int r2) {
if(l1<=l2&&r2<=r1)
return st[i];
int m2=(l2+r2)/2;
return (l1<=m2?qry(l1, r1, lc[i], l2, m2):0)+(m2<r1?qry(l1, r1, rc[i], m2+1, r2):0);
}
} sv, ser, sec, ss;
void init(int r, int c, int sr, int sc, int m, char *s) {
set<array<int, 2>> cs{{--sr, --sc}};
for(int i=0; i<m; ++i) {
if(s[i]=='N')
--sr;
else if(s[i]=='S')
++sr;
else if(s[i]=='E')
++sc;
else
--sc;
cs.insert({sr, sc});
}
for(auto a : cs) {
sv.a(a);
sv.a({a[0], a[1]+1});
sv.a({a[0]+1, a[1]});
sv.a({a[0]+1, a[1]+1});
ser.a(a);
ser.a({a[0]+1, a[1]});
sec.a(a);
sec.a({a[0], a[1]+1});
ss.a(a);
}
sv.bld();
ser.bld();
sec.bld();
ss.bld();
}
int colour(int ar, int ac, int br, int bc) {
--ar, --ac, --br, --bc;
int e=2*(br-ar+bc-ac+2)+ser.qry(ar+1, br, ac, bc)+sec.qry(ar, br, ac+1, bc);
int v=2*(br-ar+bc-ac+2)+sv.qry(ar+1, br, ac+1, bc);
int c=!sv.qry(ar+1, br, ac+1, bc)||sv.qry(ar+1, br, ac+1, bc)-sv.qry(ar+2, br-1, ac+2, bc-1)?1:2;
int s=ss.qry(ar, br, ac, bc);
return e-v+c-s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
41336 KB |
Output is correct |
2 |
Correct |
47 ms |
42488 KB |
Output is correct |
3 |
Incorrect |
44 ms |
41464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
41080 KB |
Output is correct |
2 |
Incorrect |
41 ms |
41080 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
41088 KB |
Output is correct |
2 |
Correct |
533 ms |
205916 KB |
Output is correct |
3 |
Correct |
281 ms |
205560 KB |
Output is correct |
4 |
Correct |
295 ms |
205688 KB |
Output is correct |
5 |
Correct |
266 ms |
164560 KB |
Output is correct |
6 |
Correct |
109 ms |
72312 KB |
Output is correct |
7 |
Incorrect |
183 ms |
103252 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
41336 KB |
Output is correct |
2 |
Correct |
47 ms |
42488 KB |
Output is correct |
3 |
Incorrect |
44 ms |
41464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
41336 KB |
Output is correct |
2 |
Correct |
47 ms |
42488 KB |
Output is correct |
3 |
Incorrect |
44 ms |
41464 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |