[BZOJ1067][SCOI2007]降雨量
2015-07-20 00:25
330 查看
原题地址
线段树.分类讨论很恶心…
AC code:
线段树.分类讨论很恶心…
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; }
相关文章推荐
- Factorial Trailing Zeroes
- maven中如何打包源代码
- mvc路由特性学习1
- 大一暑假计划2015.7.20
- Week—schedule 2
- CSS组件化思考
- Excel Sheet Column Number
- Android Studio 左右括号无法 自动匹配解决办法
- [leetcode] 206.Reverse Linked List
- linux $@和$*区别
- [BZOJ1500][NOI2005]维修数列
- host文件的用途和用法
- Majority Element
- hdu1102(prime)
- WebApi的一种集成测试写法(in-memory)
- HDU 3123 GCC
- Excel Sheet Column Title
- openjdk源码下载
- Javascript 多浏览器兼容性问题及解决方案
- 上周总结1