ural 1019 Line Painting
来源:互联网 发布:佳能打印机扫描软件 编辑:程序博客网 时间:2024/06/06 03:57
http://acm.timus.ru/problem.aspx?space=1&num=1019
#include <cstdio>#include <cstring>#include <algorithm>#define maxn 200100using namespace std;struct node{ int r,l,co;}tree[maxn*4];int co[maxn],l[maxn],r[maxn];struct node1{ int x,y,co;}p[maxn*4];void build(int i,int l,int r){ tree[i].l=l;tree[i].r=r; tree[i].co=1; if(l==r-1) return ; int mid=(l+r)>>1; build(i<<1,l,mid); build(i<<1|1,mid,r);}void update(int i,int l,int r,int co){ if(tree[i].l==l&&tree[i].r==r) { tree[i].co=co; return ; } if(tree[i].co>=0&&tree[i].co!=co) { tree[i<<1].co=tree[i<<1|1].co=tree[i].co; tree[i].co=-1; } int mid=(tree[i].l+tree[i].r)>>1; if(r<=mid) { update(i<<1,l,r,co); } else if(l>=mid) { update(i<<1|1,l,r,co); } else { update(i<<1,l,mid,co); update(i<<1|1,mid,r,co); }}void search1(int i,int l,int r){ if(tree[i].co>=0) { for(int j=tree[i].l; j<tree[i].r; j++) { co[j]=tree[i].co; } return ; } int mid=(tree[i].l+tree[i].r)>>1; if(r<=mid) { search1(i<<1,l,r); } else if(l>=mid) { search1(i<<1|1,l,r); } else { search1(i<<1,l,mid); search1(i<<1|1,mid,r); }}int bs(int key,int li,int ri){ int low=li,high=ri-1; while(low<=high) { int mid=(low+high)>>1; if(l[mid]==key) return mid; else if(l[mid]>key) high=mid-1; else low=mid+1; }}int main(){ int n; char ch; scanf("%d",&n); int cnt=0; for(int i=0; i<=maxn; i++) { co[i]=1; } p[0].x=0;p[0].y=1000000000; l[cnt++]=p[0].x; l[cnt++]=p[0].y; for(int i=0; i<n; i++) { scanf("%d%d %c",&p[i].x,&p[i].y,&ch); l[cnt++]=p[i].x; l[cnt++]=p[i].y; if(ch=='w') { p[i].co=1; } getchar(); } sort(l,l+cnt); int t=1; for(int i=1; i<cnt; i++) { if(l[i]!=l[i-1]) l[t++]=l[i]; } build(1,0,t); for(int i=0; i<n; i++) { int li=bs(p[i].x,0,t); int ri=bs(p[i].y,0,t); //printf("%d %d\n",li,ri); update(1,li,ri,p[i].co); } search1(1,0,t); int s=0,e=0,si,ei; co[t]=0; l[t]=1000000000; for(int i=0; i<t; i++) { si=l[i]; while(co[i]==1) i++; ei=l[i]; if(ei-si>e-s) { e=ei; s=si; } } printf("%d %d\n",s,e); return 0;}
0 0
- ural 1019 Line Painting
- Ural 1019 Line Painting
- URAL 1019 - Line Painting
- ural 1019 Line Painting
- URAL 1019 Line Painting(解题报告)
- ural 1019 Line Painting (线段树)
- URAL 1019 - Line Painting(线段树)
- ural 1019 Line Painting(线段树)
- ural 1019. Line Painting
- Ural 1019. Line Painting
- Ural 1019. Line Painting
- ural 1019 Line Painting 线段树 区间染色
- URAL - 1019 - Line Painting(离散化+线段树)
- URAL 1019. Line Painting (线段树)
- Ural 1019 A Line painting(线段树,成段更新离散化)
- URAL 1019. Line Painting 线段树 区间合并 离散化
- ural 1019. Line Painting 线段树 离散化
- URAL1019. Line Painting
- 学习JAVA的第一课——安装JDK+Eclipse
- apache 配置参考手册
- 一步一步在OEL5.5 64位Linux上安装Oracle 10gR2 RAC(6)
- 解析MySQL中mysqldump工具的基本用法
- Linux 内核网络协议栈 ------ TCP拥塞状态机 tcp_fastretrans_alert
- ural 1019 Line Painting
- 一步一步在OEL5.5 64位Linux上安装Oracle 10gR2 RAC(7)
- 20个代码生成器框架
- 一步一步在OEL5.5 64位Linux上安装Oracle 10gR2 RAC(8)
- 女子过马路遭男子精液洗脸 摩托男手淫性幻想猥亵过路女
- 一个共通的viewModel搞定所有的编辑页面
- 用maven创建基于wink的rest服务(二)-携带参数的get请求
- Sed 介绍和教程
- 一步一步在OEL5.5 64位Linux上安装Oracle 10gR2 RAC(附)