#include "rainbow.h"
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
namespace perst{
int root[4][200005],son[5000005][2],sum[500005],tsz;
void modify(int&x,int f,int l,int r,int p,int v){
x=++tsz; son[x][0]=son[f][0]; son[x][1]=son[f][1]; sum[x]=sum[f]+v;
if(l==r) return;
int mid=(l+r)/2;
if(p<=mid) modify(son[x][0],son[f][0],l,mid,p,v);
else modify(son[x][1],son[f][1],mid+1,r,p,v);
}
void modify(int t,int x,int y,int v){modify(root[t][x],root[t][x],1,200000,y,v);}
int ask(int x,int l,int r,int ql,int qr){
if(ql<=l&&r<=qr) return sum[x];
int mid=(l+r)/2;
if(qr<=mid) return ask(son[x][0],l,mid,ql,qr);
else if(ql>mid) return ask(son[x][1],mid+1,r,ql,qr);
else return ask(son[x][0],l,mid,ql,qr)+ask(son[x][1],mid+1,r,ql,qr);
}
int query(int t,int x1,int x2,int y1,int y2){
if(x1>x2||y1>y2) return 0;
return ask(root[t][x2],1,200000,y1,y2)-ask(root[t][x1-1],1,200000,y1,y2);
}
};
int lx,ly,rx,ry;
vector<int> qs[4][55];
void init(int r,int c,int sc,int sr,int m,char* s){
lx=rx=sc;
ly=ry=sr;
qs[0][sc].pb(sr);
qs[1][sc].pb(sr);
qs[1][sc].pb(sr-1);
qs[2][sc].pb(sr);
qs[2][sc-1].pb(sr);
qs[3][sc].pb(sr);
qs[3][sc].pb(sr-1);
qs[3][sc-1].pb(sr);
qs[3][sc-1].pb(sr-1);
for(int i=0;i<m;i++){
if(s[i]=='N') sc--;
if(s[i]=='S') sc++;
if(s[i]=='E') sr++;
if(s[i]=='W') sr--;
lx=min(lx,sc);
rx=max(rx,sc);
ly=min(ly,sr);
ry=max(ry,sr);
qs[0][sc].pb(sr);
qs[1][sc].pb(sr);
qs[1][sc].pb(sr-1);
qs[2][sc].pb(sr);
qs[2][sc-1].pb(sr);
qs[3][sc].pb(sr);
qs[3][sc].pb(sr-1);
qs[3][sc-1].pb(sr);
qs[3][sc-1].pb(sr-1);
}
for(int i=1;i<=r;i++){
for(int t=0;t<4;t++){
perst::root[t][i]=perst::root[t][i-1];
sort(qs[t][i].begin(),qs[t][i].end());
qs[t][i].erase(unique(qs[t][i].begin(),qs[t][i].end()),qs[t][i].end());
for(int j:qs[t][i]) if(1<=j&&j<=c) perst::modify(t,i,j,1);
}
}
}
int colour(int x1,int y1,int x2,int y2){
ll res=0;
if(x1<lx&&rx<x2&&y1<ly&&ry<y2) res=1;
res+=(x2-x1+1)*1ll*(y2-y1+1)-perst::query(0,x1,x2,y1,y2);
res-=(x2-x1+1)*1ll*(y2-y1)-perst::query(1,x1,x2,y1,y2-1);
res-=(x2-x1)*1ll*(y2-y1+1)-perst::query(2,x1,x2-1,y1,y2);
res+=(x2-x1)*1ll*(y2-y1)-perst::query(3,x1,x2-1,y1,y2-1);
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
3164 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
3 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3676 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
86 ms |
96332 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
8 ms |
8876 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
3164 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
3 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3676 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
3164 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
2 ms |
2908 KB |
Output is correct |
13 |
Correct |
3 ms |
3420 KB |
Output is correct |
14 |
Correct |
4 ms |
3676 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Runtime error |
2 ms |
860 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |