B. Factory Repairs---cf627B(线段树)
题目链接:http://codeforces.com/problemset/problem/627/B
题意:有一个工厂生产零件,但是机器是不正常的,需要维修,维修时间是 k 天,在维修期间不能生产,如果是正常情况下每天可生产A个零件,不正常情况下也可以生产,但是只能生产B(B<A)件,
现有2个操作,1和2
1 x y 表示第x天分配的工作量是y;
2 x 表示假如在第x天进行维修机器,那么这n天共能生产多少个零件;
现在有q个这样的操作,问当2操作时当前的结果是多少;
由于数据范围比较大,所以不能暴力,用线段树
sum表示当前区间的所有工作量,sum1表示机器正常情况下所能生产的总工作量,sum2是不正常情况下的;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
#define PI 4*atan(1.0)
#define N 210500
#define met(a, b) memset(a, b, sizeof(a)) #define Lson r<<1
#define Rson r<<1|1 struct node
{
int L, R, sum, sum1, sum2;///sum1是好的情况下,sum2是坏的情况下;
int Mid(){ return (L+R)/; }
}a[N*]; int A, B; void Build(int r, int L, int R)
{
a[r].L = L, a[r].R = R;
a[r].sum = a[r].sum1 = a[r].sum2 = ; if(L == R)return ; Build(Lson, L, a[r].Mid());
Build(Rson, a[r].Mid()+, R);
} void Update(int r, int pos, int num)
{
if(a[r].L == a[r].R && a[r].L == pos)
{
a[r].sum += num;
if(a[r].sum >= A)
{
a[r].sum1 = A;
a[r].sum2 = B;
}
else if(a[r].sum < A && a[r].sum >= B)
{
a[r].sum1 = a[r].sum;
a[r].sum2 = B;
}
else
a[r].sum1 = a[r].sum2 = a[r].sum;
return;
}
if(pos<=a[r].Mid())
Update(Lson, pos, num);
else
Update(Rson, pos, num); a[r].sum = a[Lson].sum + a[Rson].sum;
a[r].sum1 = a[Lson].sum1 + a[Rson].sum1;
a[r].sum2 = a[Lson].sum2 + a[Rson].sum2;
} int Query(int r, int L, int R, int op)
{
if(L > R) return ; if(a[r].L == L && a[r].R == R)
{
if(op == )
return a[r].sum1;
return a[r].sum2;
}
if(R<=a[r].Mid())
return Query(Lson, L, R, op);
else if(L>a[r].Mid())
return Query(Rson, L, R, op);
else
{
int ans1 = Query(Lson, L, a[r].Mid(), op);
int ans2 = Query(Rson, a[r].Mid()+, R, op);
return ans1+ans2;
}
} int main()
{
int n, k, q, op, x, y;
while(scanf("%d %d %d %d %d", &n, &k, &A, &B, &q)!=EOF)
{
Build(, , n);
while(q--)
{
scanf("%d", &op);
if(op==)
{
scanf("%d %d", &x, &y);
Update(, x, y);
}
else
{
scanf("%d", &x); int ans1 = Query(, , x-, );///0没修好之前的;
int ans2 = Query(, x+k, n, );///1修好之后的; printf("%d\n", ans1 + ans2);
}
}
}
return ;
}
B. Factory Repairs---cf627B(线段树)的更多相关文章
- codeforces 627B B. Factory Repairs(线段树)
B. Factory Repairs time limit per test 4 seconds memory limit per test 256 megabytes input standard ...
- 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 produ ...
- Codeforces 777E Hanoi Factory(线段树维护DP)
题目链接 Hanoi Factory 很容易想到这是一个DAG模型,那么状态转移方程就出来了. 但是排序的时候有个小细节:b相同时看a的值. 因为按照惯例,堆塔的时候肯定是内半径大的在下面. 因为N有 ...
- B. Factory Repairs--cf627B(线段树)
http://codeforces.com/problemset/problem/627/B 题目大意: n代表天数 ,k代表每一次维修持续的天数,a代表维修过后每天能生产a件产品,b代表维修之前每 ...
- Codeforces 777E(离散化+dp+树状数组或线段树维护最大值)
E. Hanoi Factory time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- bzoj3932--可持久化线段树
题目大意: 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的 任务用三元组(Si,Ei,Pi)描述,(Si,Ei,Pi)表示任务从第Si秒开始,在第 ...
- codevs 1082 线段树练习 3(区间维护)
codevs 1082 线段树练习 3 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...
- codevs 1576 最长上升子序列的线段树优化
题目:codevs 1576 最长严格上升子序列 链接:http://codevs.cn/problem/1576/ 优化的地方是 1到i-1 中最大的 f[j]值,并且A[j]<A[i] .根 ...
- codevs 1080 线段树点修改
先来介绍一下线段树. 线段树是一个把线段,或者说一个区间储存在二叉树中.如图所示的就是一棵线段树,它维护一个区间的和. 蓝色数字的是线段树的节点在数组中的位置,它表示的区间已经在图上标出,它的值就是这 ...
随机推荐
- CentOS查看本机公网IP命令
icanhazip.com 使你在任何地方知道你的公网IP地址 icanhazip.com是一个网址,你在浏览器中输入这个网址,你就能得到你的公网IP地址了. 我在Linux下一般使用curl ica ...
- mysql5.7 编码统一utf-8
查看mysql数据库编码: show variables like 'character%'; mysql> show variables like 'character%'; +------- ...
- ini 文件操作记要(2): 使用 TMemIniFile
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Form ...
- HBase 1.3(NOSQL) 发布,性能大幅提升
Apache HBase 1.3.0版在2017年1月中旬正式发布了,新版本支持分层数据的压缩和多个方面的性能提升,像预写日志(WAL).一个新的RPC机制,等等.HBase 1.3.0一共修 ...
- mysql表无权限访问
当网页出现以上问题时的解决方法: 今天在两台服务器间转移网站,最后把域名解释设置好后等待...然后CMD查看DNS解释情况..解释成功-输入网址-却出现如上信息,首先用#ls -l查看mysql下的v ...
- Mongodb 与sql 语句对照
此处用mysql中的sql语句做例子,C# 驱动用的是samus,也就是上文中介绍的第一种. 引入项目MongoDB.dll //创建Mongo连接 var mongo = new Mongo(&qu ...
- Appium - WebView測试(Android)
Appium - WebView測试 作者: Max.Bai 时间: 2015/07 Appium - WebView測试(Android) 如今App都是混合型的.有原生的也包括WebView的,a ...
- 南京IT企业环境之最深心得体会
我是南京做嵌入式的. 之前搞过一年的PC平台Linux内核开发,Linux内核态的仅仅要不是非常复杂的BUG还是能修复的.一年的Linux用户态软件开发. 然后近期搞了两年ARM嵌入式开发. 做的CM ...
- Linux 下配置网卡的别名即网卡子IP的配置
what 什么是ip别名?用windows的话说,就是为一个网卡配置多个ip.when 什么场合增加ip别名能派上用场?布网需要.多ip访问测试.特定软件对多ip的需要...and so on. ho ...
- Unity3d 手机屏幕自动适配
我提到手机自动适配的一个方法中:postion和Scale,“比例”概念适配手机.原始资源是480*800 经过实际项目考验,个人感觉: 1,UICamera是自动适配分辨率,UI上也是拉伸.放大UI ...