BZOJ 1107 POI2007 驾驶考试egz LIS
来源:互联网 发布:my sql count 限制条件 编辑:程序博客网 时间:2024/04/29 06:35
题目大意:。。。不是很好叙述自己看吧。注意要剪掉初始就能到达所有终点的点的数量
http://blog.163.com/c_sunshine/blog/static/2439650542015028013488/
OTZ 这做法实在是太优雅了!
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 100100using namespace std;struct abcd{int pos,val;abcd() {}abcd(int _,int __):pos(_),val(__) {}}a1[M],a2[M];int tot1,tot2;int n,m,p,k,ans;int l[M],r[M];bool Compare1(const abcd &x,const abcd &y){if( x.pos != y.pos )return x.pos < y.pos ;return x.val < y.val ;}bool Compare2(const abcd &x,const abcd &y){if( x.pos != y.pos )return x.pos > y.pos ;return x.val < y.val ;}struct BIT{int c[M];void Update(int x,int y){for(;x;x-=x&-x)c[x]=max(c[x],y);}int Get_Ans(int x){int re=0;for(;x<=m;x+=x&-x)re=max(re,c[x]);return re;}}b1,b2;int main(){int i,j,x,y,z;cin>>n>>m>>p>>k;++m;for(i=1;i<=p;i++){scanf("%d%d%d",&x,&y,&z);++y;if(z)new (&a1[++tot1])abcd(x+1,y);elsenew (&a2[++tot2])abcd(x,y);}sort(a1+1,a1+tot1+1,Compare1);sort(a2+1,a2+tot2+1,Compare2);l[0]=r[n+1]=-1;for(j=1,i=1;i<=n;i++){l[i]=l[i-1]+1;for(;j<=tot1&&a1[j].pos==i;j++){int temp=b1.Get_Ans(a1[j].val)+1;l[i]=min(l[i],(i-1)-temp);b1.Update(a1[j].val,temp);}}for(j=1,i=n;i;i--){r[i]=r[i+1]+1;for(;j<=tot2&&a2[j].pos==i;j++){int temp=b2.Get_Ans(a2[j].val)+1;r[i]=min(r[i],(n-i)-temp);b2.Update(a2[j].val,temp);}}for(j=1,i=1;i<=n;i++){for(;i-j+1&&l[i]+r[j]>k;j++);ans=max(ans,i-j+1);}for(i=1;i<=n;i++)if(!l[i]&&!r[i])--ans;cout<<ans<<endl;return 0;}
0 0
- BZOJ 1107 POI2007 驾驶考试egz LIS
- bzoj1107[POI2007]驾驶考试egz LIS
- BZOJ1107: [POI2007]驾驶考试egz
- BZOJ 1109 POI2007 堆积木Klo LIS
- BZOJ 1109: [POI2007]堆积木Klo LIS
- bzoj 1109: [POI2007]堆积木Klo LIS
- 【BZOJ】【P1109】【POI2007】【堆积木Klo】【题解】【LIS】
- BZOJ 1109: [POI2007]堆积木Klo 神分析, LIS, BIT, 二分
- bzoj 1101: [POI2007]Zap
- BZOJ 1101: [POI2007]Zap
- 【BZOJ 1101】 [POI2007]Zap
- bzoj 1101: [POI2007]Zap
- BZOJ 1101: [POI2007]Zap
- BZOJ 1101 [POI2007] Zap
- BZOJ 1101 [POI2007]Zap
- [BZOJ]1101: [POI2007]Zap
- [bzoj 1101--Poi2007]Zap
- bzoj 1101: [POI2007]Zap
- 蓝桥杯 人员排日程 伪DFS
- 回文数
- POJ3358 Period of an Infinite Binary Expansion【欧拉函数】
- Hadoop2.6.0安装过程中出现的问题(一)
- ESXI5.5 添加本地磁盘出错
- BZOJ 1107 POI2007 驾驶考试egz LIS
- gcc下__attribute__ ((constructor))和__attribute__ ((destructor))的使用
- 量子力学第三弹——力学量
- jQuery源码之Callbacks详解
- java和.net,应该学哪个?
- QT+VTK显示图片
- java获取rcp工程的路径
- Error:No suitable device found: no device found for connection "System eth0"
- 黑马程序员_java常用技巧——对象的输出与排序