HDU 4553
来源:互联网 发布:乐视for mac客户端 编辑:程序博客网 时间:2024/06/18 15:00
/*HDU 4553约会安排线段树区间合并线段树最左子区间*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson (pos<<1)#define rson (pos<<1|1)const int maxn = 122222;struct Node{ int l,r; int lx1,rx1,mx1,col1; int lx2,rx2,mx2,col2; int mid(){ return (l + r) >> 1; } int len(){ return (r - l + 1); } void change1(int t){ if(t == 0){ col1 = 0; lx1 = rx1 = mx1 = 0; } else{ col1 = 1; lx1 = rx1 = mx1 = len(); } } void change2(int t){ if(t == 0){ col2 = 0; lx2 = rx2 = mx2 = 0; } else{ col2 = 1; lx2 = rx2 = mx2 = len(); } }}node[maxn << 2];void pushdown(int pos){ if(node[pos].col1 != -1){ node[lson].change1(node[pos].col1); node[rson].change1(node[pos].col1); node[pos].col1 = -1; } if(node[pos].col2 != -1){ node[lson].change2(node[pos].col2); node[rson].change2(node[pos].col2); node[pos].col2 = -1; }}void pushup(int pos){ //包含屌丝的区间 node[pos].lx1 = node[lson].lx1; node[pos].rx1 = node[rson].rx1; if(node[pos].lx1 == node[lson].len()) node[pos].lx1 += node[rson].lx1; if(node[pos].rx1 == node[rson].len()) node[pos].rx1 += node[lson].rx1; node[pos].mx1 = node[lson].rx1 + node[rson].lx1; node[pos].mx1 = max(node[pos].mx1,max(node[lson].mx1,node[rson].mx1)); //不包含屌丝的区间 node[pos].lx2 = node[lson].lx2; node[pos].rx2 = node[rson].rx2; if(node[pos].lx2 == node[lson].len()) node[pos].lx2 += node[rson].lx2; if(node[pos].rx2 == node[rson].len()) node[pos].rx2 += node[lson].rx2; node[pos].mx2 = node[lson].rx2 + node[rson].lx2; node[pos].mx2 = max(node[pos].mx2,max(node[lson].mx2,node[rson].mx2));}void build(int l,int r,int pos){ node[pos].l = l; node[pos].r = r; node[pos].col1 = node[pos].col2 = -1; if(l == r){ node[pos].lx1 = node[pos].rx1 = node[pos].mx1 = 1; node[pos].lx2 = node[pos].rx2 = node[pos].mx2 = 1; return; } int mid = node[pos].mid(); build(l,mid,lson); build(mid + 1,r,rson); pushup(pos);}void update(int l,int r,int pos,int d){ if(l <= node[pos].l && node[pos].r <= r){ if(d == 0){ //清0 node[pos].change1(1); node[pos].change2(1); } else if(d == 1){//放进来屌丝 node[pos].change1(0); } else if(d == 2){//放进来女神 node[pos].change1(0); node[pos].change2(0); } return; } pushdown(pos); int mid = node[pos].mid(); if(l <= mid) update(l,r,lson,d); if(r > mid) update(l,r,rson,d); pushup(pos);}int query(int l,int r,int pos,int d){ if(node[pos].len() == node[pos].mx1) return node[pos].l; pushdown(pos); int ans; if(node[lson].mx1 >= d) ans = query(l,r,lson,d); else if(node[lson].rx1 + node[rson].lx1 >= d){ int rr = node[pos].mid() + node[rson].lx1; int v1 = node[lson].rx1 + node[rson].lx1 - d; ans = rr - v1 - d + 1; } else ans = query(l,r,rson,d); pushup(pos); return ans;}int query2(int l,int r,int pos,int d){ if(node[pos].len() == node[pos].mx2) return node[pos].l; pushdown(pos); int ans; if(node[lson].mx2 >= d) ans = query2(l,r,lson,d); else if(node[lson].rx2 + node[rson].lx2 >= d){ int rr = node[pos].mid() + node[rson].lx2; int v1 = node[lson].rx2 + node[rson].lx2 - d; ans = rr - v1 - d + 1; } else ans = query2(l,r,rson,d); pushup(pos); return ans;}int main(){ int T,Case = 1; char op[10]; scanf("%d",&T); while(T--){ int n,m,x,y; scanf("%d%d",&n,&m); build(1,n,1); printf("Case %d:\n",Case++); for(int i = 0; i < m; i++){ scanf("%s",op); if(op[0] == 'D'){ scanf("%d",&x); if(node[1].mx1 >= x){ int v = query(1,n,1,x); printf("%d,let's fly\n",v); update(v,v + x - 1,1,1); } else printf("fly with yourself\n"); } else if(op[0] == 'N'){ scanf("%d",&x); if(node[1].mx1 >= x){ int v = query(1,n,1,x); printf("%d,don't put my gezi\n",v); update(v,v + x - 1,1,2); } else if(node[1].mx2 >= x){ int v = query2(1,n,1,x); printf("%d,don't put my gezi\n",v); update(v,v + x - 1,1,2); } else printf("wait for me\n"); } else if(op[0] == 'S'){ scanf("%d%d",&x,&y); update(x,y,1,0); printf("I am the hope of chinese chengxuyuan!!\n"); } //printf("%d %d\n",node[1].mx1,node[1].mx2); } } return 0;}/*DS 10NS 50*/
0 0
- HDU 4553
- HDU 4553 约会安排
- hdu 4553 约会安排
- HDU 4553 约会安排
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- Android构建系统
- JfreeChart画图折线
- 探索并发编程(五)------Java多线程开发技巧
- 八大排序算法总结
- http://blog.sina.com.cn/s/blog_6683e49d0100o18j.html
- HDU 4553
- 实用网站
- 《python学习手册》读书笔记(2015.4.29-30)
- The Eclipse executable launcher was unable to 。。。。
- css写一个简单的三角形,绿色的哦
- 习近平五一讲话传递正能量
- android TabHost使用(二)
- 各种网站就是没有H
- qt多媒体