这是为什么呢。求大佬解答,玄关。
#include<bits/stdc++.h>
// #pragma G++ optimize(2)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define fi first
#define se second
const int N=50005;
int n,m,year[N],rain[N],tr[N*4];
int ls(int p) {return p*2;}
int rs(int p) {return p*2+1;}
void pushup(int p) {tr[p]=max(tr[ls(p)],tr[rs(p)]);}
void build(int p,int pl,int pr) {
if(pl==pr) {
tr[p]=rain[pl];
return;
}
tr[p]=-2e9;
int mid=(pl+pr)/2;
build(ls(p),pl,mid);
build(rs(p),mid+1,pr);
pushup(p);
}
int query(int p,int pl,int pr,int l,int r) {
if(l<=pl&&r>=pr) return tr[p];
int mid=(pl+pr)/2,res=-2e9;
if(l<=mid) res=max(res,query(ls(p),pl,mid,l,r));
if(r>mid) res=max(res,query(rs(p),mid+1,pr,l,r));
return res;
}
int binarySearch1(int val) {
int l=1,r=n,res=-1;
while(l<=r) {
int mid=(l+r)/2;
if(year[mid]>=val) {
res=mid;
r=mid-1;
}
else l=mid+1;
}
return res;
}
int binarySearch2(int val) {
int l=1,r=n,res=-1;
while(l<=r) {
int mid=(l+r)/2;
if(year[mid]<=val) {
res=mid;
l=mid+1;
}
else r=mid-1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>year[i]>>rain[i];
build(1,1,n);
cin>>m;
for(int i=1,x,y;i<=m;i++) {
cin>>y>>x;
int st=binarySearch1(y),ed=binarySearch2(x);
// cerr<<st<<' '<<ed<<'\n';
if(st==-1||ed==-1||st>ed) {
cout<<"maybe\n";
continue;
}
int tmp=query(1,1,n,y==year[st]?st+1:st,x==year[ed]?ed-1:ed);
// cerr<<tmp<<'\n';
if(y==year[st]&&x==year[ed]) {
if(rain[st]<rain[ed]||tmp>=rain[ed]) cout<<"false\n";
else if(ed-st==year[ed]-year[st]) cout<<"true\n";
else cout<<"maybe\n";
}
else if(y!=year[st]&&x==year[ed]) {
if(tmp>=rain[ed]) cout<<"false\n";
else cout<<"maybe\n";
}
else if(y==year[st]&&x!=year[ed]) {
if(tmp>=rain[st]) cout<<"false\n";
else cout<<"maybe\n";
}
else cout<<"maybe\n";
}
return 0;
}