[ 线段树 单调队列 ] Codeforces859F Ordering T-Shirts
来源:互联网 发布:网络专题排版设计 编辑:程序博客网 时间:2024/04/30 05:56
假设前
令
从左到右枚举
若
否则,用线段树或单调队列记一下
#include<bits/stdc++.h>using namespace std;#define ll long longinline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline void Read(int& x){ char c=nc(); for(;c<'0'||c>'9';c=nc()); for(x=0;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=nc());}inline void Read(ll& x){ char c=nc(); for(;c<'0'||c>'9';c=nc()); for(x=0;c>='0'&&c<='9';x=(x<<3)+(x<<1)+c-48,c=nc());}#define N 200010ll s[N<<1],t[N],m,Ans,c[N<<2];int i,j,k,n,x;inline void Update(int x,int l,int r,int y,ll z){ if(l==r){ c[x]=z; return; } int Mid=l+r>>1; if(y<=Mid)Update(x<<1,l,Mid,y,z);else Update(x<<1|1,Mid+1,r,y,z); c[x]=max(c[x<<1],c[x<<1|1]);}inline ll Query(int x,int l,int r,int L,int R){ if(l>R||r<L)return -1e18; if(l>=L&&r<=R)return c[x]; int Mid=l+r>>1; return max(Query(x<<1,l,Mid,L,R),Query(x<<1|1,Mid+1,r,L,R));}int main(){ Read(n);Read(m); for(i=1;i<=n*2-1;i++)Read(x),s[i]=s[i-1]+x; for(i=1;i<=n;i++){ for(;j<i&&s[2*i-1]-s[2*j]>m;j++); if(j>0)t[i]=t[j-1]+m; if(j<i)t[i]=max(t[i],s[i*2-1]+Query(1,0,n,j,i-1)); Update(1,0,n,i,t[i]-s[i<<1]); } cout<<t[n]<<endl; return 0;}
阅读全文
0 0
- [ 线段树 单调队列 ] Codeforces859F Ordering T-Shirts
- pku 2823(单调队列、线段树)
- POJ2823:Sliding Window(单调队列||线段树)
- POJ2823 线段树OR单调队列
- 线段树和单调队列优化DP
- poj2823--Sliding Window--线段树||单调队列
- BZOJ 1012 线段树||单调队列
- 物理( 线段树套单调队列 )
- 【bzoj4262】Sum 线段树+单调队列
- hdu 4122 单调队列或线段树
- POJ 2823 线段树 Or 单调队列
- bzoj1012(线段树或单调队列)
- bzoj 1012 最大数(线段树|单调队列|单调栈)
- XDU-1156 等待队列 (线段树||单调队列)
- Codeforces702F. T-Shirts
- 线段树和单调队列优化DP---POJ2373解题报告
- Poj 2823 Sliding Window (单调队列 or 线段树)
- 线段树和单调队列优化DP---POJ2373解题报告
- java.lang.IllegalStateException:Unable to create schema compiler
- JAVA中去掉空格
- windows进程的相关概念
- JDK源码ScheduledExecutorService解读
- 大话设计模式总结2-策略模式
- [ 线段树 单调队列 ] Codeforces859F Ordering T-Shirts
- JAVA是引用传递还是值传递
- 数据库指令集合
- 系统安全性之十大措施
- VIM的使用总结
- Unity 对接友盟与TalkingData数据平台(简易版)
- 用短短地人生阅历看待房价,看完你或许觉得房价并不高
- 远程windows服务器上运行解压版tomcat失败解决方法
- Linux系统教程:Linux下如何安装软件