Gym 100851L Landscape Improved(二分+脑洞)
来源:互联网 发布:长沙app软件开发公司 编辑:程序博客网 时间:2024/06/05 00:13
代码:
#include <map>#include <set>#include <ctime>#include <stack>#include <queue>#include <cmath>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <cstring>#include <sstream>#include <cstdlib>#include <iostream>#include <algorithm>#pragma comment(linker,"/STACK:102400000,102400000")using namespace std;#define MAX 100005#define MAXN 1000005#define maxnode 205#define sigma_size 26#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define LL long long#define ull unsigned long long#define mem(x,v) memset(x,v,sizeof(x))#define lowbit(x) (x&-x)#define pii pair<int,int>#define bits(a) __builtin_popcount(a)#define mk make_pair#define limit 10000//const int prime = 999983;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f;const double pi = acos(-1.0);const double inf = 1e18;const double eps = 1e-4;const LL mod = 772002;const ull mx = 133333331;/*****************************************************/inline void RI(int &x) { char c; while((c=getchar())<'0' || c>'9'); x=c-'0'; while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0'; }/*****************************************************/int a[MAX];LL sum[MAX];int L[MAX],R[MAX];int n;LL w;bool check(int h){ mem(L,0); mem(R,INF); for(int i=1;i<=n;i++){ int t1=i+h-a[i]; int t2=i-(h-a[i]); //cout<<t1<<" "<<t2<<endl; if(t1<=n) L[t1]=max(L[t1],i); if(t2>=1) R[t2]=min(R[t2],i); } for(int i=1;i<=n;i++) L[i]=max(L[i-1],L[i]); for(int i=n;i>0;i--) R[i]=min(R[i],R[i+1]); for(int i=1;i<=n;i++){ if(L[i]==0||R[i]==INF) continue; LL tmp=(1+i-(LL)R[i]+2LL*h)*((LL)R[i]-i)/2; tmp+=((LL)2*h-i+(LL)L[i]+1)*((LL)i-L[i])/2; tmp-=h; tmp-=sum[R[i]-1]-sum[L[i]]; if(tmp<=w) return true; } return false;}int main(){ freopen("landscape.in","r",stdin); freopen("landscape.out","w",stdout); cin>>n>>w; sum[0]=0; int maxn=0; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); maxn=max(a[i],maxn); sum[i]=sum[i-1]+a[i]; } int l=maxn,r=2e9; while(l<=r){ int mid=(l+r)/2; //cout<<1; if(check(mid)) l=mid+1; else r=mid-1; } cout<<r<<endl; return 0;}
0 0
- Gym 100851L Landscape Improved(二分+脑洞)
- 【二分】NEERC15 L Landscape Improved (Codeforces GYM 100851)
- Gym 100187L - Ministry of Truth
- Gym 100703L Many questions 水题
- Gym 100814L Candy Jars 博弈论
- Gym 101149L Right Build[BFS]
- GYM 100090 L.Hard Problem(水~)
- GYM 100827 L.Wormhole(Floyd)
- GYM 101149 L.Right Build(SPFA)
- GYM 101173 L.Lost Logic(构造)
- GYM 100971 L.Chess Match(贪心)
- GYM 101086 L.Chance(水~)
- Codeforces gym 101149 L 最短路
- Gym 101064L The Knapsack problem 题解
- gym 101137 L Lazy Coordinator(概率)
- Gym 101612L Little Difference 因子分解
- Gym 100886J Sockets(二分+贪心)
- GYM 100247 F. Battle Fury(二分)
- opencv--convexHull()用法
- Theano Tutorial文档翻译(八) - 怎样标准化Theano的信息
- 深入理解linux内核手记
- HDU 3823 Prime Friend 线性筛选素数
- jQuery中$(this)和this的区别
- Gym 100851L Landscape Improved(二分+脑洞)
- POJ 2485 Highways 最小生成树的最大边
- Linux_transplanation_NOTE_1
- 创建应用的快捷方式
- 扫盲贴(一)——JDK8新特性:Lambda表达式入门
- JZOJ8.16(C组)最短路
- 多线程通讯之Handler实现
- 构造器的真正调用顺序
- hiho1079 : 离散化(线段树+区间离散化)