bzoj 1067: [SCOI2007]降雨量 (离散化+线段树)

时间:2024-01-11 15:42:14

链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1067

思路: 毒瘤题,写的自闭,改了一晚上,注意要理清题目的逻辑 x小于等于y,x,y之间的数严格小于x,不能等于;

分类讨论懒得写的,很简单的分类讨论。

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid int m = (l + r) >> 1
const int M = 1e5+;
const int inf = 0x3f3f3f3f;
int vis[M];
int num[M<<],sum[M<<],x1[M],x2[M],yy[M],y2[M],cnt,a[M<<];
void pushup(int rt){
sum[rt] = max(sum[rt<<],sum[rt<<|]);
num[rt] = num[rt<<] + num[rt<<|];
} void update(int p,int c,int l,int r,int rt){
if(l == r){
sum[rt] = c;
num[rt] = ;
return ;
}
mid;
if(p <= m) update(p,c,lson);
else update(p,c,rson);
pushup(rt);
} int query(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
return sum[rt];
}
mid;
int ret = -inf;
if(L <= m) ret = max(ret,query(L,R,lson));
if(R > m) ret = max(ret,query(L,R,rson));
return ret;
} int ask(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r){
return num[rt];
}
mid;
int ret = ;
if(L <= m) ret += ask(L,R,lson);
if(R > m) ret += ask(L,R,rson);
return ret;
} int main()
{
int n,x,y,m;
scanf("%d",&n);
int cnt = ;
for(int i = ;i <= n;i ++){
scanf("%d%d",&x1[i],&yy[i]);
a[++cnt] = x1[i];
}
scanf("%d",&m);
for(int i = ;i <= m;i ++){
scanf("%d%d",&x2[i],&y2[i]);
a[++cnt] = x2[i];
a[++cnt] = y2[i];
}
sort(a+,a++cnt);
int nn = unique(a+,a++cnt)-(a+);
for(int i = ;i <= n;i ++){
x = lower_bound(a+,a+nn+,x1[i]) - a;
vis[x] = yy[i];
update(x,yy[i],,nn,);
}
for(int i = ;i <= m;i ++){
x = lower_bound(a+,a+nn+,x2[i]) - a;
y = lower_bound(a+,a+nn+,y2[i]) - a;
if(x > y){
printf("false\n");
continue;
}
if(!vis[x]&&!vis[y]) printf("maybe\n");
else if(vis[x]&&vis[y]){
int cnt = query(x+,y-,,nn,);
int flag = ask(x,y,,nn,);
if(cnt<vis[y]&&vis[y]<=vis[x]){
if(flag == y2[i]-x2[i]+) printf("true\n");
else printf("maybe\n");
}
else printf("false\n");
}
else if(!vis[x]&&vis[y]){
int cnt = query(x,y-,,nn,);
if(cnt >= vis[y]) printf("false\n");
else printf("maybe\n");
}
else{
int cnt = query(x+,y,,nn,);
if(cnt >= vis[x]) printf("false\n");
else printf("maybe\n");
}
}
return ;
}