[BZOJ1067][SCOI2007]降雨量
来源:互联网 发布:javlib最新域名 编辑:程序博客网 时间:2024/06/12 01:14
原题地址
线段树.分类讨论很恶心…
AC code:
#include <cstdio>#include <algorithm>using namespace std;const int N=100010;int n,m,cnt;struct nod{ int l,r,mx,tot; nod *lc,*rc;}*NIL,pool[N<<3];struct Segtree{ nod *root; Segtree(){ NIL=&pool[cnt++]; root=&pool[cnt++]; root->lc=root->rc=NIL; root->l=-1000000000;root->r=1000000000; } void newnod(nod **p,int L,int R){ *p=&pool[cnt++]; (*p)->l=L;(*p)->r=R; (*p)->lc=(*p)->rc=NIL; } void insert(nod **p,int pos,int k){ if((*p)->l==(*p)->r){ (*p)->tot=1;(*p)->mx=k; return ; } int M=((*p)->l+(*p)->r)>>1; if(pos<=M){ if((*p)->lc==NIL) newnod(&(*p)->lc,(*p)->l,M); insert(&(*p)->lc,pos,k); } else{ if((*p)->rc==NIL) newnod(&(*p)->rc,M+1,(*p)->r); insert(&(*p)->rc,pos,k); } (*p)->tot=(*p)->lc->tot+(*p)->rc->tot; (*p)->mx=max((*p)->lc->mx,(*p)->rc->mx); } int get(nod *p,int L,int R){ if(p==NIL) return 0; if(p->l==L&&p->r==R) return p->mx; int M=(p->l+p->r)>>1; if(R<=M) return get(p->lc,L,R); else if(L>M) return get(p->rc,L,R); else return max(get(p->lc,L,M),get(p->rc,M+1,R)); } int total(nod *p,int L,int R){ if(p==NIL) return 0; if(p->l==L&&p->r==R) return p->tot; int M=(p->l+p->r)>>1; if(R<=M) return total(p->lc,L,R); else if(L>M) return total(p->rc,L,R); else return total(p->lc,L,M)+total(p->rc,M+1,R); }};int main(){ Segtree T; scanf("%d",&n); for(int i=1;i<=n;i++){ int a,b; scanf("%d%d",&a,&b); T.insert(&T.root,a,b); } scanf("%d",&m); for(int i=1;i<=m;i++){ int y,x,a,b,c; scanf("%d%d",&y,&x); a=T.get(T.root,y,y); b=T.get(T.root,y+1,x-1); c=T.get(T.root,x,x); if((!a)&&(!c)) printf("maybe\n"); else if(!c){ if(b>=a) printf("false\n"); else printf("maybe\n"); } else if(!a){ if(b>=c) printf("false\n"); else printf("maybe\n"); } else{ if(a>=c&&b<c&&T.total(T.root,y+1,x-1)==x-y-1) printf("true\n"); else if(a<c||b>=c) printf("false\n"); else printf("maybe\n"); } } return 0;}
0 0
- bzoj1067: [SCOI2007]降雨量
- 【SCOI2007】【BZOJ1067】降雨量
- [BZOJ1067][SCOI2007]降雨量
- 【bzoj1067】[SCOI2007]降雨量
- 【bzoj1067】[SCOI2007]降雨量
- BZOJ1067[SCOI2007]降雨量
- 【bzoj1067】[SCOI2007]降雨量 (RMQ)
- BZOJ1067 [SCOI2007]降雨量
- BZOJ1067(SCOI2007)[降雨量]--RMQ
- bzoj1067 scoi2007 降雨量 RMQ+讨论
- BZOJ1067 [SCOI2007]降雨量 RMQ+乱搞
- BZOJ1067 [SCOI2007]降雨量/POJ2647 WorstWeather Ever
- [BZOJ1067][SCOI2007]降雨量(线段树)
- 【bzoj1067】【SCOI2007】【降雨量】【线段树+分类讨论】
- BZOJ1067: [SCOI2007]降雨量 (RMQ或者线段树)
- bzoj1067 [SCOI2007]降雨量 (线段树)
- 【BZOJ1067】【POJ2637】WorstWeather Ever【SCOI2007】降雨量 线段树+恶心讨论
- 【SCOI2007】【BZOJ1067】【codevs2439】降雨量,分类讨论の线段树
- Android Studio 左右括号无法 自动匹配解决办法
- [leetcode] 206.Reverse Linked List
- Excel Sheet Column Number
- 大一暑假计划2015.7.20
- Factorial Trailing Zeroes
- [BZOJ1067][SCOI2007]降雨量
- 导航栏图标问题
- [Android UI界面] tab_Host页面跳转,传值,刷新等问题汇总。
- Rotate Array
- codeforces 399B Red and Blue Balls-数据-(模拟题找规律)
- [BZOJ1407][Noi2002]Savage
- UVa 140 Bandwidth 例题7-6
- 在代码中调用Xib
- 观察者模式