ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

noip模拟59(待补)

2021-09-23 21:35:59  阅读:172  来源: 互联网

标签:59 noip 待补 ll back que inline void define


A. 柱状图

B. 应急棍

C. 擒敌拳

考场上测试点分治切了,单调队列 \(+\) 斜率优化.

每次枚举队列里的所有元素就行了.

正解是李超线段树.

C_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS {
	#define ll long long int
	#define ull unsigned ll
	#define lf double
	#define lbt(x) (x&(-x))
	#define mp(x,y) make_pair(x,y)
	#define lb lower_bound 
	#define ub upper_bound
	#define Fill(x,y) memset(x,y,sizeof x)
	#define Copy(x,y) memcpy(x,y,sizeof x)
	#define File(x,y) freopen(#x,"r",stdin),freopen(#y,"w",stdout)
	#define FILE(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	inline ll read() {
		int ss=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0; 
		while(isdigit(ch)) ss=(ss<<3)+(ss<<1)+(ch^48),ch=getchar();
		return cit?ss:-ss;
	}
} using namespace BSS;

const ll N=2e5+21;

namespace DEQUE{
	struct Deque{
		ll l,r; ll q[N<<2];
		inline bool empty(){ return l>r; }
		inline ll size(){ return r-l+1; }
		inline ll front(){ return q[l]; }
		inline ll back(){ return q[r]; }
		inline void pop_front(){ l++; }
		inline void pop_back(){ r--; }
		inline void push_front(ll x){ q[--l]=x; }
		inline void push_back(ll x){ q[++r]=x; }
	} que;
} using namespace DEQUE;

ll m,n,maxh,ans,flag;
ll H[N];
struct I { ll h,id,lc; } p[N];
inline void Work1(){
	ll now;
	for(int i=1;i<=n;i++){
		maxh=max(maxh,p[i].h),p[i].lc=i;
		if(que.empty()) que.push_back(i),ans=max(ans,p[i].h);
		else{
			if(p[que.back()].h<p[i].h) que.push_back(i);
			else{
				while(que.size() and p[que.back()].h>=p[i].h){
					now=que.back(),que.pop_back();
					p[i].lc=min(p[now].lc,p[i].lc);
				}
				que.push_back(i);
			}
			for(int j=que.l;j<=que.r;j++){
				ans=max(ans,(i-p[que.q[j]].lc+1)*p[que.q[j]].h);
			}
		}
		printf("%lld ",max(ans,maxh));
	}	
}
inline ll caly(ll x){ return x*H[x]-H[x]; }
inline lf getxl(ll a,ll b){ return 1.0*(caly(a)-caly(b))/(H[a]-H[b]); }
inline void Work2(){
	for(int i=1;i<=n;i++) H[i]=p[i].h;
	que.push_back(1); ll res=0; printf("%lld ",H[1]);
	for(int i=2;i<=n;i++){
		while(que.l<que.r and getxl(que.q[que.l+1],que.front())<=i) que.pop_front();
		res=max(H[i],H[que.front()]*i-caly(que.front()));
		while(que.l<que.r and getxl(i,que.back())<=getxl(que.back(),que.q[que.r-1])) que.pop_back();
		que.push_back(i);
		printf("%lld ",res);
	}
}
signed main(){
	FILE(b);
	n=read(),que.l=n+1,que.r=n;flag=1;
	for(int i=1;i<=n;i++) p[i].h=read(),flag&=(p[i].h>=p[i-1].h);
	if(flag) Work2();
	else Work1();
	
	exit(0);
}

D. 边数

标签:59,noip,待补,ll,back,que,inline,void,define
来源: https://www.cnblogs.com/AaMuXiiiiii/p/15327523.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有