8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组
D. Factory Repairs
题目连接:
http://www.codeforces.com/contest/635/problem/D
Description
A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.
Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.
As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.
Input
The first line contains five integers n, k, a, b, and q (1 ≤ k ≤ n ≤ 200 000, 1 ≤ b < a ≤ 10 000, 1 ≤ q ≤ 200 000) — the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:
1 di ai (1 ≤ di ≤ n, 1 ≤ ai ≤ 10 000), representing an update of ai orders on day di, or
2 pi (1 ≤ pi ≤ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?
It's guaranteed that the input will contain at least one query of the second type.
Output
For each query of the second type, print a line containing a single integer — the maximum number of orders that the factory can fill over all n days.
Sample Input
5 2 2 1 8
1 1 2
1 5 3
1 2 1
2 2
1 4 2
1 3 2
2 1
2 3
Sample Output
3
6
4
Hint
题意
最多n天,然后你每天普通情况下可以产生b个东西,好的情况下可以产生b个东西
由普通的情况到好的情况需要k天的休息,就这k天啥也干不了
q次询问
现在你有两个操作
1 x y,第x天需要y个东西(不独立)
2 x 在第x天进行休息,然后问你最多能够满足多少个东西的需求(独立的)
题解:
树状数组就好了
k天以前的,我就每个点的最大值就是b
k天以后,每个点的最大值是a
然后维护一下区间和就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+7;
int n,k,a,b,q;
int c[maxn][2];
int A[maxn];
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int y,int z)
{
for(int i=x;i<maxn;i+=lowbit(i))
c[i][z]+=y;
}
int getsum(int x,int z)
{
int ans = 0;
for(int i=x;i;i-=lowbit(i))
ans+=c[i][z];
return ans;
}
int main()
{
scanf("%d%d%d%d%d",&n,&k,&a,&b,&q);
for(int i=1;i<=q;i++)
{
int op;scanf("%d",&op);
if(op==1)
{
int x,y;
scanf("%d%d",&x,&y);
int p1 = A[x];A[x]+=y;
update(x,min(b,A[x])-min(b,p1),0);
update(x,min(a,A[x])-min(a,p1),1);
}
else
{
int x;scanf("%d",&x);
printf("%d\n",getsum(x-1,0)+getsum(n,1)-getsum(x+k-1,1));
}
}
}
8VC Venture Cup 2016 - Final Round (Div. 2 Edition) D. Factory Repairs 树状数组的更多相关文章
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)
暴力 A - Orchestra import java.io.*; import java.util.*; public class Main { public static void main(S ...
- 8VC Venture Cup 2016 - Final Round (Div. 1 Edition) E - Preorder Test 树形dp
E - Preorder Test 思路:想到二分答案了之后就不难啦, 对于每个答案用树形dp取check, 如果二分的值是val, dp[ i ]表示 i 这棵子树答案不低于val的可以访问的 最多 ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A
A. Orchestra time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) C. XOR Equation 数学
C. XOR Equation 题目连接: http://www.codeforces.com/contest/635/problem/C Description Two positive integ ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition)B. sland Puzzle 水题
B. sland Puzzle 题目连接: http://www.codeforces.com/contest/635/problem/B Description A remote island ch ...
- 8VC Venture Cup 2016 - Final Round (Div. 2 Edition) A. Orchestra 水题
A. Orchestra 题目连接: http://www.codeforces.com/contest/635/problem/A Description Paul is at the orches ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题
http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card
D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #de ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)A 水 B 二分 C并查集
A. Petr and a calendar time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
随机推荐
- 第一章: 文件句柄转化为 typeglob/glob 与文件句柄检测
#为了使在子例程中传递文件句柄不出问题 #我们要把文件句柄转为glob或typeglob #转为glob $fd = *MY_FILE; #转为typeblog $fd = \*MY_FILE; #两 ...
- mysql之数据库操作进阶(三)
环境信息 数据库:mysql-5.7.20 操作系统:Ubuntu-16.04.3 查询 条件查询 # 使用where关键字 select * from 表名 where 条件 # 比较运算符 > ...
- Oracle 表连接方式
1.嵌套循环联结(NESTED LOOPS)2.哈希联结(HASH JOIN)3.排序合并联结(MERGE JOIN)4.半联结(in/exists)5.反联结(not in/not exists)6 ...
- 一个朋友 js图表开发问题 用 c和 js 解决
引言 不求知道一切, 只求发现一件 -- 乔治·西蒙·欧姆 附注:那些存在于梦幻中的事迹,那些儿时梦中的人物,每每看起,都觉得 .哎 .... 岁月 ... 一直在努力 ... ...
- 网站服务器压力Web性能测试(1):Apache Bench:Apache自带服务器压力测试工具
一个网站或者博客到底能够承受多大的用户访问量经常是我们在用VPS或者独立服务器搭建网站了最关心的问题,还有不少人喜欢对LNMP或者LAMP进行一些优化以便提高Web性能,而优化后到底有多大的效果,就需 ...
- 3.Python3标准库--数据结构
(一)enum:枚举类型 import enum ''' enum模块定义了一个提供迭代和比较功能的枚举类型.可以用这个为值创建明确定义的符号,而不是使用字面量整数或字符串 ''' 1.创建枚举 im ...
- HIbernate学习笔记5 之 查询
一.HQL查询 * 按条件查询,条件中写的是属性名,之后在query对象为添加赋值,如: String hql = " from User where uid=?"; Sessio ...
- 深入理解python多进程编程
1.python多进程编程背景 python中的多进程最大的好处就是充分利用多核cpu的资源,不像python中的多线程,受制于GIL的限制,从而只能进行cpu分配,在python的多进程中,适合于所 ...
- Run Rancher server on windows
软件环境:WIN 10 一.首先安装Docker for Windows,Cmder(我用这个执行Docker 命令) 二.右键右下角Docker 图标--> Daemon ,在Registry ...
- python学习第一天_环境的搭建
Python linux环境的安装: 1.https://www.python.org/ftp/python/ 大家可以在这里下载自己所需的linux下的版本 ,这里我下载的2.6.6版本: 2.在C ...