[HNOI/AHOI2018] Game, the third simulation competition, violence + optimization? metaphysics

The subject

      [HNOI/AHOI2018] Games

      We can know that the area that the point between the two doors can reach is the same, so we can make the point between the two doors an interval, and then we do what it asks.

      Each interval is desperately expanding outward. We know that the left and right sides of the interval are doors, so there is an interval on the left and right sides, then the interval can be expanded if and only if the key of their door is in the current interval.

      It is easy to know that we pull an interval into the current interval, indicating that the points that can be traversed by that interval can also be traversed in the current interval, so update the leftmost and rightmost endpoints of the current interval.

#include<cstdio>
#include<cstdlib>
#include<cstring>

int min (int x, int y) {
	return x<y?x:y;
}

int max(int x,int y){
	return x>y?x:y;
}

int tf[1000010];
int n,m,p;
int tot = 0;
int where[1000010];
bool find[1000010];
int l [1000010], r [1000010];

bool findip(int x,int y){
	if(find[where[x]]) return l[where[x]]<=y && y<=r[where[x]];
	find[where[x]]=true;
	int ll=l[where[x]],rr=r[where[x]];
	while(1){
		bool qq=false;
		if(ll!=1 && ll<=tf[ll-1] && tf[ll-1]<=rr){
			qq=true;
			ll=min(l[where[ll-1]],ll);
			rr=max(r[where[ll-1]],rr);
		}
		else if(rr!=n && ll<=tf[rr] && tf[rr]<=rr){
			qq=true;
			ll=min(l[where[rr+1]],ll);
			rr=max(r[where[rr+1]],rr);
		}
		if(!qq) break;
	}
	l[where[x]]=ll,r[where[x]]=rr;
	return l[where[x]]<=y && y<=r[where[x]];
}

int main(){
	scanf("%d %d %d",&n,&m,&p);
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		tf[x]=y;
	}
	int now=1;
	while(now<=n){
		to++;
		l [tot] = r [tot] = now;
		where[now]=tot;
		while(tf[now]==0 && now+1<=n){
			now++;
			where[now]=tot;
			r[tot]=now;
		}
		now++;
	}
	// random_shuffle(p+1,p+n+1);
	for(int i=1;i<=p;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		if(findip(x,y)) printf("YES\n");
		else printf("NO\n");
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325977866&siteId=291194637