BZOJ4293: [PA2015]Siano
Description
Input
Output
Sample Input
1 2 4 3
1 1
2 2
3 0
4 4
Sample Output
6
18
0
HINT
#include<cstdio>
#include<cctype>
#include<queue>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
typedef long long ll;
inline ll read() {
ll x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
const int maxn=500010;
int n,m,A[maxn];
ll setv[maxn<<2],sett[maxn<<2],suma[maxn<<2],sumv[maxn<<2],maxv[maxn<<2],maxt[maxn<<2];
void maintain(int o,int l,int r) {
int lc=o<<1,rc=lc|1;
if(setv[o]>=0) {
sumv[o]=setv[o]*(r-l+1)-sett[o]*suma[o];
maxv[o]=setv[o];maxt[o]=sett[o];
}
else if(l<r) {
sumv[o]=sumv[lc]+sumv[rc];
maxv[o]=maxv[rc];maxt[o]=maxt[rc];
}
}
void pushdown(int o,int l,int r) {
int lc=o<<1,rc=lc|1,mid=l+r>>1;
if(setv[o]>=0) {
setv[lc]=setv[rc]=setv[o];
sett[lc]=sett[rc]=sett[o];
maxt[lc]=maxt[rc]=sett[o];
sumv[lc]=setv[o]*(mid-l+1)-sett[o]*suma[lc];
sumv[rc]=setv[o]*(r-mid)-sett[o]*suma[rc];
maxv[lc]=maxv[rc]=setv[o];
setv[o]=sett[o]=-1;
}
}
void build(int o,int l,int r) {
if(l==r) suma[o]=A[l];
else {
setv[o]=-1;
int mid=l+r>>1,lc=o<<1,rc=lc|1;
build(lc,l,mid);build(rc,mid+1,r);
suma[o]=suma[lc]+suma[rc];
}
}
ll ans,d,b;
int findst(int o,int l,int r) {
if(l==r) return l;
else {
pushdown(o,l,r);
int mid=l+r>>1,lc=o<<1,rc=lc|1;
if(maxv[lc]+(d-maxt[lc])*A[mid]>b) return findst(lc,l,mid);
return findst(rc,mid+1,r);
}
}
void update(int o,int l,int r,int ql,int qr) {
if(ql<=l&&r<=qr) {
ans+=sumv[o]+d*suma[o]-b*(r-l+1);
setv[o]=b;sett[o]=d;
}
else {
pushdown(o,l,r);
int mid=l+r>>1,lc=o<<1,rc=lc|1;
if(ql<=mid) update(lc,l,mid,ql,qr);
if(qr>mid) update(rc,mid+1,r,ql,qr);
}
maintain(o,l,r);
}
int main() {
n=read();m=read();
rep(i,1,n) A[i]=read();
sort(A+1,A+n+1);
build(1,1,n);
rep(i,1,m) {
d=read();b=read();
if(maxv[1]+(d-maxt[1])*A[n]<=b) puts("0");
else {
int s=findst(1,1,n);ans=0;
update(1,1,n,s,n);printf("%lld\n",ans);
}
}
return 0;
}
BZOJ4293: [PA2015]Siano的更多相关文章
- BZOJ4293 [PA2015]Siano(线段树)
传送门 这Seg确实不好写,不过因为它与ai的相对顺序无关,所以,我们在对ai排序之后,就可做了.维护一个区间最大值,维护一个和,维护一个区间赋值的懒标记,再维护一个时间变化的标记就可以了. 因为不论 ...
- 【BZOJ4293】[PA2015]Siano 线段树
[BZOJ4293][PA2015]Siano Description 农夫Byteasar买了一片n亩的土地,他要在这上面种草. 他在每一亩土地上都种植了一种独一无二的草,其中,第i亩土地的草每天会 ...
- 2018.07.23[PA2015]Siano(线段树)
[PA2015]Siano 描述 Description 农夫Byteasar买了一片n亩的土地,他要在这上面种草. 他在每一亩土地上都种植了一种独一无二的草,其中,第i亩土地的草每天会长高a[i]厘 ...
- BZOJ.4293.[PA2015]Siano(线段树)
题目链接 \(Description\) 有一片n亩的土地,要在这上面种草. 在每一亩土地上都种植了一种独一无二的草,其中,第\(i\)亩土地的草每天会长高\(a[i]\)厘米. 一共会进行\(m\) ...
- 【BZOJ】4293: [PA2015]Siano 线段树上二分
[题意]给定n棵高度初始为0的草,每天每棵草会长高a[i],m次收割,每次在d[i]天将所有>b[i]的草收割到b[i],求每次收割量.n<=500000. [算法]线段树上二分 [题解] ...
- [PA2015]Siano 单调栈
由于某人找了个单调栈的题解但是没研究透所以让我们来研究............ 首先先来考虑下面一种情况,假设第\(k\)次切割时,天数为\(d_k\),高度为\(b_k\),第\(k+1\)次切割时 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 【bzoj4293】【PA2015】Siano
如题,首先可以考虑相对大小是不变的. 那么先sort,之后每次在线段树上二分即可. #include<bits/stdc++.h> typedef long long ll; using ...
- BZOJ 4291: [PA2015]Kieszonkowe 水题
4291: [PA2015]Kieszonkowe Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnli ...
随机推荐
- How the problem solved about " Dealing with non-fast-forward errors"
Recently ,I got confused When I use git to push one of my project. The problem is below: And I Foun ...
- 微信小程序导航:官方工具+精品教程+DEMO集合(1月7更新)
1:官方工具:https://mp.weixin.qq.com/debug/w ... tml?t=14764346784612:简易教程:https://mp.weixin.qq.com/debug ...
- BeanUtils.populate(obj, map);
public static void populate(Object bean, Map<String, ? extends Object> properties) throws Ille ...
- Bill的挑战(bzoj 1879)
Description Input 本题包含多组数据. 第一行:一个整数T,表示数据的个数. 对于每组数据: 第一行:两个整数,N和K(含义如题目表述). 接下来N行:每行一个字符串. Output ...
- MySql触发器语法总结
经过昨天多次失败,今天终于将我要实现的触发器功能写成功了,触发器代码如下: -- use dbfortest; drop trigger if exists tg_before_insert_on_d ...
- IOS __ 面试题
1.下面四种内部排序算法中哪一种在最差的情况下时间复杂度最高:(B) A.快速排序 B.冒泡排序 C.堆排序 D.归并排序 2.Shell中,将command1的输出作为command2的输入应该 ...
- Python 判断字符串是否为数字
转载: http://www.runoob.com/python3/python3-check-is-number.html 以下实例通过创建自定义函数 is_number() 方法来判断字符串是否为 ...
- webpack
webpack 通过一个主文件 .js ,webpack把这个文件所有的依赖文件,都处理打包成js文件 webpack 可以干嘛?1.执行打包 (把require()模块化整合成一个js文件给html ...
- ROS学习(二)—— 配置ROS环境
一.管理环境 p { margin-bottom: 0.25cm; line-height: 120% } a:link { } 如果你在查找和使用ROS软件包方面遇到了问题,请确保你已经正确配置了脚 ...
- WooCommerce插件设置教程之设置主页
http://demo.themes4wp.com/documentation/homepage-setup/#videoimage-tutorial