답안 #930939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930939 2024-02-20T21:01:28 Z amirhoseinfar1385 무지개나라 (APIO17_rainbow) C++17
12 / 100
639 ms 404132 KB
#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=min(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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 391504 KB Output is correct
2 Correct 126 ms 391764 KB Output is correct
3 Incorrect 124 ms 391508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 391748 KB Output is correct
2 Correct 122 ms 391524 KB Output is correct
3 Correct 455 ms 395140 KB Output is correct
4 Correct 639 ms 396620 KB Output is correct
5 Correct 613 ms 396420 KB Output is correct
6 Correct 525 ms 396828 KB Output is correct
7 Correct 552 ms 396972 KB Output is correct
8 Correct 350 ms 396948 KB Output is correct
9 Correct 568 ms 396504 KB Output is correct
10 Correct 617 ms 396704 KB Output is correct
11 Correct 514 ms 396712 KB Output is correct
12 Correct 403 ms 396876 KB Output is correct
13 Correct 430 ms 396376 KB Output is correct
14 Correct 423 ms 396728 KB Output is correct
15 Correct 384 ms 396860 KB Output is correct
16 Correct 497 ms 395580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 391692 KB Output is correct
2 Correct 256 ms 395876 KB Output is correct
3 Correct 249 ms 404132 KB Output is correct
4 Correct 251 ms 398672 KB Output is correct
5 Correct 228 ms 399512 KB Output is correct
6 Incorrect 164 ms 396940 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 391504 KB Output is correct
2 Correct 126 ms 391764 KB Output is correct
3 Incorrect 124 ms 391508 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 391504 KB Output is correct
2 Correct 126 ms 391764 KB Output is correct
3 Incorrect 124 ms 391508 KB Output isn't correct
4 Halted 0 ms 0 KB -