求助,,线段树9WA1RE,样例都过了
查看原帖
求助,,线段树9WA1RE,样例都过了
892979
liuenyin楼主2023/7/9 09:30

rt,代码如下:

评测记录

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll y[50005],rr[50005];
struct node{
	ll l,r,w;
};
node tree[200005];
void build(ll p,ll l, ll r){
	tree[p].l=l;
	tree[p].r=r;
	if(l==r){
		tree[p].w=rr[l];
		return;
	}
	ll mid=(l+r)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	tree[p].w=max(tree[p*2].w,tree[p*2+1].w);
} 
ll query(ll p,ll l,ll r){
	if(l<=tree[p].l and r>=tree[p].r){
		return tree[p].w;
	}
	ll mid=(tree[p].l+tree[p].r)/2;
	ll flag=0;
	if(l<=mid) flag=max(query(p*2,l,r),flag);
	if(r>=(mid+1)) flag=max(query(p*2+1,l,r),flag);
//	cout<<flag;
	return flag;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>y[i]>>rr[i];
	}
	build(1,1,n);
	cin>>m;
	for(int i=1;i<=m;i++){
		ll xx,yy;
		cin>>xx>>yy;
		int xpos=lower_bound(y+1,y+1+n,xx)-y,
			ypos=lower_bound(y+1,y+1+n,yy)-y;
		if(xx>yy)cout<<"false";
		else if(query(1,xpos,ypos)==rr[xpos] && query(1,xpos+1,ypos)==rr[ypos]){
			int fff=0;

			for(int i=xpos+1;i<=ypos;i++){
				if(y[i]-y[i-1]!=1){
					fff=1;
					break;
				}
			}
			if(fff or xpos==ypos)cout<<"maybe";
			else cout<<"true";
		}
		else cout<<"false";
		cout<<endl; 
	}
	return 0;
}

2023/7/9 09:30
加载中...