Submission #930941

# Submission time Handle Problem Language Result Execution time Memory
930941 2024-02-20T21:03:45 Z amirhoseinfar1385 Land of the Rainbow Gold (APIO17_rainbow) C++17
100 / 100
782 ms 404816 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
int kaf=(1<<18);

struct segment{
	vector<int>all[maxn];
	void add(int r,int c){
		all[r].push_back(c);
	}	
	struct node{
		int lc,rc,sum;
		node(){
			lc=rc=sum=0;
		}
	};
	node seg[(1<<19)*15];
	int root[maxn],rt=0,nx=1;
	void calc(int i){
		seg[i].sum=seg[seg[i].lc].sum+seg[seg[i].rc].sum;
	}
	int ins(int i,int l,int r,int tl,int tr,int w){
		if(l>r||l>tr||r<tl||tl>tr){
			return i;
		}
		int now=nx;
		seg[nx]=seg[i];
		nx++;
		if(l>=tl&&r<=tr){
			seg[nx-1].sum+=w;
			return nx-1;
		}
		int m=(l+r)>>1;
		seg[now].lc=ins(seg[now].lc,l,m,tl,tr,w);
		seg[now].rc=ins(seg[now].rc,m+1,r,tl,tr,w);
		calc(now);
		return now;
	}
	int get(int i,int l,int r,int tl,int tr){
		if(l>r||l>tr||r<tl||tl>tr){
			return 0;
		}
		if(l>=tl&&r<=tr){
			return seg[i].sum;
		}
		int m=(l+r)>>1;
		return get(seg[i].lc,l,m,tl,tr)+get(seg[i].rc,m+1,r,tl,tr);
	}
	int pors(int top,int bot,int tr,int tl){
		//cout<<"get: "<<get(root[top],0,kaf-1,tl,tr)<<" hehe "<<get(root[bot-1],0,kaf-1,tl,tr)<<endl;	
		return get(root[top],0,kaf-1,tl,tr)-get(root[bot-1],0,kaf-1,tl,tr);
	}
	void build(){
		for(int i=0;i<maxn;i++){
			sort(all[i].begin(),all[i].end());
			all[i].resize(unique(all[i].begin(),all[i].end())-all[i].begin());
			for(auto x:all[i]){
				rt=ins(rt,0,kaf-1,x,x,1);
			}
			root[i]=rt;
		}
	}
}segv,segeo,segea,segr;
int mxr=-1,mxc=-1,mnr=maxn+10,mnc=maxn+10;

void add(int r,int c){
	//cout<<"addy: "<<r<<" "<<c<<endl;
	mnr=min(mnr,r);
	mxr=max(mxr,r);
	mnc=min(mnc,c);
	mxc=max(mxc,c);
	segv.add(r,c);
	segv.add(r,c+1);
	segv.add(r+1,c);
	segv.add(r+1,c+1);
	segeo.add(r,c);
	segeo.add(r+1,c);
	segea.add(r,c);
	segea.add(r,c+1);
	segr.add(r,c);
}

void build(){
	segv.build();
	segeo.build();
	segea.build();
	segr.build();
}

void init(int R, int C, int sr, int sc, int M, char *S) {
	add(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--;
		}
		add(sr,sc);
	}
	build();
}

int colour(int ar, int ac, int br, int bc) {
   	int v=segv.pors(br,ar+1,bc,ac+1)+(br-ar+2)*2+(bc-ac)*2;
   	int c=1;
   	int e=segeo.pors(br,ar+1,bc,ac)+segea.pors(br,ar,bc,ac+1)+(br-ar+1)*2+(bc-ac+1)*2;
   	int r=segr.pors(br,ar,bc,ac);
   	if(mnr>ar&&mxr<br&&mnc>ac&&mxc<bc){
   		c++;
   	}
   	int res=e-v+1+c-r-1;
   	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 136 ms 391508 KB Output is correct
2 Correct 139 ms 391772 KB Output is correct
3 Correct 140 ms 391656 KB Output is correct
4 Correct 138 ms 391500 KB Output is correct
5 Correct 162 ms 391764 KB Output is correct
6 Correct 137 ms 391696 KB Output is correct
7 Correct 147 ms 391796 KB Output is correct
8 Correct 138 ms 391504 KB Output is correct
9 Correct 140 ms 391508 KB Output is correct
10 Correct 136 ms 391508 KB Output is correct
11 Correct 139 ms 391756 KB Output is correct
12 Correct 140 ms 391764 KB Output is correct
13 Correct 140 ms 391608 KB Output is correct
14 Correct 145 ms 391968 KB Output is correct
15 Correct 136 ms 391504 KB Output is correct
16 Correct 139 ms 391536 KB Output is correct
17 Correct 137 ms 391624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 391536 KB Output is correct
2 Correct 137 ms 391624 KB Output is correct
3 Correct 481 ms 395112 KB Output is correct
4 Correct 576 ms 396904 KB Output is correct
5 Correct 568 ms 396732 KB Output is correct
6 Correct 524 ms 396724 KB Output is correct
7 Correct 551 ms 397048 KB Output is correct
8 Correct 358 ms 396776 KB Output is correct
9 Correct 568 ms 396524 KB Output is correct
10 Correct 587 ms 396900 KB Output is correct
11 Correct 521 ms 396620 KB Output is correct
12 Correct 414 ms 396768 KB Output is correct
13 Correct 439 ms 396432 KB Output is correct
14 Correct 418 ms 396340 KB Output is correct
15 Correct 395 ms 396900 KB Output is correct
16 Correct 500 ms 395852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 391504 KB Output is correct
2 Correct 280 ms 395988 KB Output is correct
3 Correct 289 ms 404084 KB Output is correct
4 Correct 258 ms 398672 KB Output is correct
5 Correct 246 ms 399408 KB Output is correct
6 Correct 182 ms 397136 KB Output is correct
7 Correct 200 ms 396668 KB Output is correct
8 Correct 274 ms 396236 KB Output is correct
9 Correct 275 ms 396436 KB Output is correct
10 Correct 175 ms 393808 KB Output is correct
11 Correct 220 ms 396220 KB Output is correct
12 Correct 271 ms 396072 KB Output is correct
13 Correct 263 ms 404308 KB Output is correct
14 Correct 264 ms 398676 KB Output is correct
15 Correct 256 ms 399308 KB Output is correct
16 Correct 176 ms 396624 KB Output is correct
17 Correct 202 ms 397072 KB Output is correct
18 Correct 264 ms 396496 KB Output is correct
19 Correct 269 ms 399804 KB Output is correct
20 Correct 268 ms 399672 KB Output is correct
21 Correct 274 ms 396244 KB Output is correct
22 Correct 261 ms 396412 KB Output is correct
23 Correct 175 ms 393820 KB Output is correct
24 Correct 220 ms 396352 KB Output is correct
25 Correct 269 ms 395944 KB Output is correct
26 Correct 263 ms 404304 KB Output is correct
27 Correct 262 ms 398788 KB Output is correct
28 Correct 246 ms 399288 KB Output is correct
29 Correct 175 ms 396460 KB Output is correct
30 Correct 206 ms 397220 KB Output is correct
31 Correct 265 ms 396372 KB Output is correct
32 Correct 265 ms 399792 KB Output is correct
33 Correct 263 ms 399736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 391508 KB Output is correct
2 Correct 139 ms 391772 KB Output is correct
3 Correct 140 ms 391656 KB Output is correct
4 Correct 138 ms 391500 KB Output is correct
5 Correct 162 ms 391764 KB Output is correct
6 Correct 137 ms 391696 KB Output is correct
7 Correct 147 ms 391796 KB Output is correct
8 Correct 138 ms 391504 KB Output is correct
9 Correct 140 ms 391508 KB Output is correct
10 Correct 136 ms 391508 KB Output is correct
11 Correct 139 ms 391756 KB Output is correct
12 Correct 140 ms 391764 KB Output is correct
13 Correct 140 ms 391608 KB Output is correct
14 Correct 145 ms 391968 KB Output is correct
15 Correct 136 ms 391504 KB Output is correct
16 Correct 139 ms 391536 KB Output is correct
17 Correct 137 ms 391624 KB Output is correct
18 Correct 623 ms 397964 KB Output is correct
19 Correct 298 ms 392524 KB Output is correct
20 Correct 268 ms 392604 KB Output is correct
21 Correct 278 ms 392272 KB Output is correct
22 Correct 287 ms 392544 KB Output is correct
23 Correct 298 ms 392272 KB Output is correct
24 Correct 283 ms 392328 KB Output is correct
25 Correct 283 ms 392528 KB Output is correct
26 Correct 290 ms 392500 KB Output is correct
27 Correct 384 ms 397436 KB Output is correct
28 Correct 350 ms 397652 KB Output is correct
29 Correct 382 ms 397664 KB Output is correct
30 Correct 507 ms 397492 KB Output is correct
31 Correct 166 ms 391508 KB Output is correct
32 Correct 503 ms 397176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 391508 KB Output is correct
2 Correct 139 ms 391772 KB Output is correct
3 Correct 140 ms 391656 KB Output is correct
4 Correct 138 ms 391500 KB Output is correct
5 Correct 162 ms 391764 KB Output is correct
6 Correct 137 ms 391696 KB Output is correct
7 Correct 147 ms 391796 KB Output is correct
8 Correct 138 ms 391504 KB Output is correct
9 Correct 140 ms 391508 KB Output is correct
10 Correct 136 ms 391508 KB Output is correct
11 Correct 139 ms 391756 KB Output is correct
12 Correct 140 ms 391764 KB Output is correct
13 Correct 140 ms 391608 KB Output is correct
14 Correct 145 ms 391968 KB Output is correct
15 Correct 136 ms 391504 KB Output is correct
16 Correct 139 ms 391536 KB Output is correct
17 Correct 137 ms 391624 KB Output is correct
18 Correct 623 ms 397964 KB Output is correct
19 Correct 298 ms 392524 KB Output is correct
20 Correct 268 ms 392604 KB Output is correct
21 Correct 278 ms 392272 KB Output is correct
22 Correct 287 ms 392544 KB Output is correct
23 Correct 298 ms 392272 KB Output is correct
24 Correct 283 ms 392328 KB Output is correct
25 Correct 283 ms 392528 KB Output is correct
26 Correct 290 ms 392500 KB Output is correct
27 Correct 384 ms 397436 KB Output is correct
28 Correct 350 ms 397652 KB Output is correct
29 Correct 382 ms 397664 KB Output is correct
30 Correct 507 ms 397492 KB Output is correct
31 Correct 166 ms 391508 KB Output is correct
32 Correct 503 ms 397176 KB Output is correct
33 Correct 280 ms 395988 KB Output is correct
34 Correct 289 ms 404084 KB Output is correct
35 Correct 258 ms 398672 KB Output is correct
36 Correct 246 ms 399408 KB Output is correct
37 Correct 182 ms 397136 KB Output is correct
38 Correct 200 ms 396668 KB Output is correct
39 Correct 274 ms 396236 KB Output is correct
40 Correct 275 ms 396436 KB Output is correct
41 Correct 175 ms 393808 KB Output is correct
42 Correct 220 ms 396220 KB Output is correct
43 Correct 271 ms 396072 KB Output is correct
44 Correct 263 ms 404308 KB Output is correct
45 Correct 264 ms 398676 KB Output is correct
46 Correct 256 ms 399308 KB Output is correct
47 Correct 176 ms 396624 KB Output is correct
48 Correct 202 ms 397072 KB Output is correct
49 Correct 264 ms 396496 KB Output is correct
50 Correct 269 ms 399804 KB Output is correct
51 Correct 268 ms 399672 KB Output is correct
52 Correct 274 ms 396244 KB Output is correct
53 Correct 261 ms 396412 KB Output is correct
54 Correct 175 ms 393820 KB Output is correct
55 Correct 220 ms 396352 KB Output is correct
56 Correct 269 ms 395944 KB Output is correct
57 Correct 263 ms 404304 KB Output is correct
58 Correct 262 ms 398788 KB Output is correct
59 Correct 246 ms 399288 KB Output is correct
60 Correct 175 ms 396460 KB Output is correct
61 Correct 206 ms 397220 KB Output is correct
62 Correct 265 ms 396372 KB Output is correct
63 Correct 265 ms 399792 KB Output is correct
64 Correct 263 ms 399736 KB Output is correct
65 Correct 481 ms 395112 KB Output is correct
66 Correct 576 ms 396904 KB Output is correct
67 Correct 568 ms 396732 KB Output is correct
68 Correct 524 ms 396724 KB Output is correct
69 Correct 551 ms 397048 KB Output is correct
70 Correct 358 ms 396776 KB Output is correct
71 Correct 568 ms 396524 KB Output is correct
72 Correct 587 ms 396900 KB Output is correct
73 Correct 521 ms 396620 KB Output is correct
74 Correct 414 ms 396768 KB Output is correct
75 Correct 439 ms 396432 KB Output is correct
76 Correct 418 ms 396340 KB Output is correct
77 Correct 395 ms 396900 KB Output is correct
78 Correct 500 ms 395852 KB Output is correct
79 Correct 782 ms 397476 KB Output is correct
80 Correct 740 ms 396996 KB Output is correct
81 Correct 373 ms 394576 KB Output is correct
82 Correct 472 ms 397232 KB Output is correct
83 Correct 609 ms 396716 KB Output is correct
84 Correct 515 ms 404816 KB Output is correct
85 Correct 518 ms 399428 KB Output is correct
86 Correct 496 ms 400140 KB Output is correct
87 Correct 397 ms 397160 KB Output is correct
88 Correct 432 ms 398160 KB Output is correct
89 Correct 483 ms 397236 KB Output is correct
90 Correct 567 ms 400676 KB Output is correct
91 Correct 521 ms 401128 KB Output is correct