Submission #885877

# Submission time Handle Problem Language Result Execution time Memory
885877 2023-12-10T22:53:48 Z MilosMilutinovic Land of the Rainbow Gold (APIO17_rainbow) C++14
100 / 100
684 ms 171132 KB
#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[20000005][2],sum[20000005],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][200005];

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;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 6 ms 21852 KB Output is correct
3 Correct 5 ms 21356 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 7 ms 22108 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 5 ms 21084 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21180 KB Output is correct
11 Correct 6 ms 21336 KB Output is correct
12 Correct 7 ms 21592 KB Output is correct
13 Correct 7 ms 22288 KB Output is correct
14 Correct 8 ms 22620 KB Output is correct
15 Correct 5 ms 21112 KB Output is correct
16 Correct 4 ms 21080 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 246 ms 92024 KB Output is correct
4 Correct 291 ms 137132 KB Output is correct
5 Correct 308 ms 136964 KB Output is correct
6 Correct 248 ms 110624 KB Output is correct
7 Correct 295 ms 107024 KB Output is correct
8 Correct 156 ms 29360 KB Output is correct
9 Correct 339 ms 137052 KB Output is correct
10 Correct 318 ms 137460 KB Output is correct
11 Correct 269 ms 110424 KB Output is correct
12 Correct 140 ms 135200 KB Output is correct
13 Correct 149 ms 136976 KB Output is correct
14 Correct 141 ms 137008 KB Output is correct
15 Correct 129 ms 110832 KB Output is correct
16 Correct 247 ms 98996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21112 KB Output is correct
2 Correct 111 ms 159036 KB Output is correct
3 Correct 119 ms 167760 KB Output is correct
4 Correct 98 ms 162308 KB Output is correct
5 Correct 100 ms 127924 KB Output is correct
6 Correct 47 ms 55948 KB Output is correct
7 Correct 65 ms 80212 KB Output is correct
8 Correct 97 ms 126200 KB Output is correct
9 Correct 100 ms 116368 KB Output is correct
10 Correct 37 ms 51352 KB Output is correct
11 Correct 73 ms 92744 KB Output is correct
12 Correct 101 ms 159136 KB Output is correct
13 Correct 118 ms 167760 KB Output is correct
14 Correct 98 ms 162128 KB Output is correct
15 Correct 101 ms 127920 KB Output is correct
16 Correct 46 ms 49232 KB Output is correct
17 Correct 67 ms 80488 KB Output is correct
18 Correct 92 ms 159948 KB Output is correct
19 Correct 88 ms 144812 KB Output is correct
20 Correct 87 ms 144884 KB Output is correct
21 Correct 97 ms 126184 KB Output is correct
22 Correct 98 ms 115820 KB Output is correct
23 Correct 37 ms 51100 KB Output is correct
24 Correct 72 ms 92676 KB Output is correct
25 Correct 100 ms 159136 KB Output is correct
26 Correct 120 ms 167760 KB Output is correct
27 Correct 103 ms 162128 KB Output is correct
28 Correct 101 ms 127956 KB Output is correct
29 Correct 44 ms 49280 KB Output is correct
30 Correct 61 ms 80468 KB Output is correct
31 Correct 91 ms 160016 KB Output is correct
32 Correct 89 ms 144820 KB Output is correct
33 Correct 110 ms 144788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 6 ms 21852 KB Output is correct
3 Correct 5 ms 21356 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 7 ms 22108 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 5 ms 21084 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21180 KB Output is correct
11 Correct 6 ms 21336 KB Output is correct
12 Correct 7 ms 21592 KB Output is correct
13 Correct 7 ms 22288 KB Output is correct
14 Correct 8 ms 22620 KB Output is correct
15 Correct 5 ms 21112 KB Output is correct
16 Correct 4 ms 21080 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 456 ms 94804 KB Output is correct
19 Correct 146 ms 28240 KB Output is correct
20 Correct 113 ms 24900 KB Output is correct
21 Correct 122 ms 25248 KB Output is correct
22 Correct 122 ms 25684 KB Output is correct
23 Correct 138 ms 28244 KB Output is correct
24 Correct 114 ms 25120 KB Output is correct
25 Correct 131 ms 25756 KB Output is correct
26 Correct 126 ms 25940 KB Output is correct
27 Correct 246 ms 82668 KB Output is correct
28 Correct 194 ms 56032 KB Output is correct
29 Correct 218 ms 80688 KB Output is correct
30 Correct 338 ms 160608 KB Output is correct
31 Correct 7 ms 21084 KB Output is correct
32 Correct 395 ms 81964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Correct 6 ms 21852 KB Output is correct
3 Correct 5 ms 21356 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 7 ms 22108 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 5 ms 21084 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21180 KB Output is correct
11 Correct 6 ms 21336 KB Output is correct
12 Correct 7 ms 21592 KB Output is correct
13 Correct 7 ms 22288 KB Output is correct
14 Correct 8 ms 22620 KB Output is correct
15 Correct 5 ms 21112 KB Output is correct
16 Correct 4 ms 21080 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 456 ms 94804 KB Output is correct
19 Correct 146 ms 28240 KB Output is correct
20 Correct 113 ms 24900 KB Output is correct
21 Correct 122 ms 25248 KB Output is correct
22 Correct 122 ms 25684 KB Output is correct
23 Correct 138 ms 28244 KB Output is correct
24 Correct 114 ms 25120 KB Output is correct
25 Correct 131 ms 25756 KB Output is correct
26 Correct 126 ms 25940 KB Output is correct
27 Correct 246 ms 82668 KB Output is correct
28 Correct 194 ms 56032 KB Output is correct
29 Correct 218 ms 80688 KB Output is correct
30 Correct 338 ms 160608 KB Output is correct
31 Correct 7 ms 21084 KB Output is correct
32 Correct 395 ms 81964 KB Output is correct
33 Correct 111 ms 159036 KB Output is correct
34 Correct 119 ms 167760 KB Output is correct
35 Correct 98 ms 162308 KB Output is correct
36 Correct 100 ms 127924 KB Output is correct
37 Correct 47 ms 55948 KB Output is correct
38 Correct 65 ms 80212 KB Output is correct
39 Correct 97 ms 126200 KB Output is correct
40 Correct 100 ms 116368 KB Output is correct
41 Correct 37 ms 51352 KB Output is correct
42 Correct 73 ms 92744 KB Output is correct
43 Correct 101 ms 159136 KB Output is correct
44 Correct 118 ms 167760 KB Output is correct
45 Correct 98 ms 162128 KB Output is correct
46 Correct 101 ms 127920 KB Output is correct
47 Correct 46 ms 49232 KB Output is correct
48 Correct 67 ms 80488 KB Output is correct
49 Correct 92 ms 159948 KB Output is correct
50 Correct 88 ms 144812 KB Output is correct
51 Correct 87 ms 144884 KB Output is correct
52 Correct 97 ms 126184 KB Output is correct
53 Correct 98 ms 115820 KB Output is correct
54 Correct 37 ms 51100 KB Output is correct
55 Correct 72 ms 92676 KB Output is correct
56 Correct 100 ms 159136 KB Output is correct
57 Correct 120 ms 167760 KB Output is correct
58 Correct 103 ms 162128 KB Output is correct
59 Correct 101 ms 127956 KB Output is correct
60 Correct 44 ms 49280 KB Output is correct
61 Correct 61 ms 80468 KB Output is correct
62 Correct 91 ms 160016 KB Output is correct
63 Correct 89 ms 144820 KB Output is correct
64 Correct 110 ms 144788 KB Output is correct
65 Correct 246 ms 92024 KB Output is correct
66 Correct 291 ms 137132 KB Output is correct
67 Correct 308 ms 136964 KB Output is correct
68 Correct 248 ms 110624 KB Output is correct
69 Correct 295 ms 107024 KB Output is correct
70 Correct 156 ms 29360 KB Output is correct
71 Correct 339 ms 137052 KB Output is correct
72 Correct 318 ms 137460 KB Output is correct
73 Correct 269 ms 110424 KB Output is correct
74 Correct 140 ms 135200 KB Output is correct
75 Correct 149 ms 136976 KB Output is correct
76 Correct 141 ms 137008 KB Output is correct
77 Correct 129 ms 110832 KB Output is correct
78 Correct 247 ms 98996 KB Output is correct
79 Correct 647 ms 129644 KB Output is correct
80 Correct 684 ms 119360 KB Output is correct
81 Correct 248 ms 54640 KB Output is correct
82 Correct 295 ms 96116 KB Output is correct
83 Correct 424 ms 162608 KB Output is correct
84 Correct 317 ms 171132 KB Output is correct
85 Correct 358 ms 165716 KB Output is correct
86 Correct 309 ms 131508 KB Output is correct
87 Correct 232 ms 52908 KB Output is correct
88 Correct 230 ms 84052 KB Output is correct
89 Correct 277 ms 163504 KB Output is correct
90 Correct 357 ms 148436 KB Output is correct
91 Correct 301 ms 148304 KB Output is correct