Submission #930922

# Submission time Handle Problem Language Result Execution time Memory
930922 2024-02-20T19:52:14 Z amirhoseinfar1385 Land of the Rainbow Gold (APIO17_rainbow) C++17
36 / 100
862 ms 1019984 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+10;
int kaf=(1<<19);

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<<20)*20];
	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=min(mnc,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 737 ms 1007176 KB Output is correct
2 Correct 458 ms 1007176 KB Output is correct
3 Incorrect 427 ms 1007188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 429 ms 1007268 KB Output is correct
2 Correct 417 ms 1007244 KB Output is correct
3 Correct 729 ms 1013728 KB Output is correct
4 Correct 851 ms 1015276 KB Output is correct
5 Correct 845 ms 1014964 KB Output is correct
6 Correct 775 ms 1015480 KB Output is correct
7 Correct 839 ms 1015444 KB Output is correct
8 Correct 618 ms 1015104 KB Output is correct
9 Correct 862 ms 1015140 KB Output is correct
10 Correct 859 ms 1015144 KB Output is correct
11 Correct 789 ms 1014968 KB Output is correct
12 Correct 675 ms 1015228 KB Output is correct
13 Correct 687 ms 1014804 KB Output is correct
14 Correct 699 ms 1014896 KB Output is correct
15 Correct 670 ms 1015436 KB Output is correct
16 Correct 762 ms 1014196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 401 ms 1007176 KB Output is correct
2 Correct 543 ms 1011788 KB Output is correct
3 Correct 530 ms 1019984 KB Output is correct
4 Correct 528 ms 1014564 KB Output is correct
5 Correct 512 ms 1015400 KB Output is correct
6 Correct 450 ms 1012676 KB Output is correct
7 Correct 467 ms 1012728 KB Output is correct
8 Correct 551 ms 1012484 KB Output is correct
9 Correct 525 ms 1011908 KB Output is correct
10 Correct 442 ms 1009528 KB Output is correct
11 Correct 483 ms 1012004 KB Output is correct
12 Correct 537 ms 1011628 KB Output is correct
13 Correct 534 ms 1019908 KB Output is correct
14 Correct 530 ms 1014352 KB Output is correct
15 Correct 507 ms 1014968 KB Output is correct
16 Correct 445 ms 1012512 KB Output is correct
17 Correct 461 ms 1012816 KB Output is correct
18 Correct 534 ms 1012016 KB Output is correct
19 Correct 539 ms 1015788 KB Output is correct
20 Correct 538 ms 1015588 KB Output is correct
21 Correct 537 ms 1011968 KB Output is correct
22 Correct 531 ms 1011984 KB Output is correct
23 Correct 438 ms 1009492 KB Output is correct
24 Correct 479 ms 1012152 KB Output is correct
25 Correct 539 ms 1011712 KB Output is correct
26 Correct 544 ms 1019792 KB Output is correct
27 Correct 538 ms 1014352 KB Output is correct
28 Correct 519 ms 1015160 KB Output is correct
29 Correct 444 ms 1012304 KB Output is correct
30 Correct 464 ms 1012744 KB Output is correct
31 Correct 539 ms 1012308 KB Output is correct
32 Correct 547 ms 1015484 KB Output is correct
33 Correct 529 ms 1015524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 1007176 KB Output is correct
2 Correct 458 ms 1007176 KB Output is correct
3 Incorrect 427 ms 1007188 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 737 ms 1007176 KB Output is correct
2 Correct 458 ms 1007176 KB Output is correct
3 Incorrect 427 ms 1007188 KB Output isn't correct
4 Halted 0 ms 0 KB -