又是看了很久的题目。。。


题目链接:

http://codeforces.com/contest/635/problem/D

题意:

一家工厂生产维修之前每天生产b个,维修了k天之后每天生产a个,维修期间不生产。

若干操作:

1. 1 d aa 第d天要求aa个订单,一个订单对应一个物品,必须在这一天中完成。

2. 2 d 第d天开始维修,最终能得到多少订单。

分析:

树状数组分别维护维修前和维修后得到的订单数,这样对于不同的维修日期,把这两种相加即可。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define pr(x) cout << #x << ": " << x << " "
#define pl(x) cout << #x << ": " << x << endl;
#define sa(x) scanf("%d",&(x))
#define mdzz cout<<"mdzz"<<endl;
const int maxn = 2e5 + 5, oo =0x3f3f3f3f;
typedef long long ll;
int bita[maxn], bitb[maxn], cnt[maxn];//a维修后b维修前
int n;
int suma(int i)
{
int ans = 0;
while(i){
ans += bita[i];
i -= i & -i;
}
return ans;
}
int sumb(int i)
{
int ans = 0;
while(i){
ans += bitb[i];
i -= i & -i;
}
return ans;
}
void adda(int i, int x)
{
while(i <= n){
bita[i] += x;
i += i &-i;
}
}
void addb(int i, int x)
{
while(i <= n){
bitb[i] += x;
i += i &-i;
}
}
int main (void)
{
int k, a, b, q;sa(n);sa(k);sa(a);sa(b);sa(q);
int aa, d;
int ans = 0;
for(int i = 0; i < q; i++){
int type;sa(type);
if(type == 1){
scanf("%d%d", &d, &aa);
adda(d, -min(cnt[d], a)); addb(d, -min(cnt[d], b));//复原
cnt[d] += aa;
adda(d, min(cnt[d], a)); addb(d, min(cnt[d], b));
}else{
sa(d);
ans += sumb(d - 1) + suma(n) - suma(d + k - 1);
printf("%d\n", ans);
ans = 0;
}
}
return 0;
}

Codeforces 635D Factory Repairs【树状数组】的更多相关文章

  1. 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 ...

  2. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

  3. Codeforces 650D - Zip-line(树状数组)

    Codeforces 题目传送门 & 洛谷题目传送门 我怕不是个 nt--一开始忽略了"询问独立"这个条件--然后就一直在想有什么办法维护全局 LIS--心态爆炸 首先离散 ...

  4. Codeforces 1139F Dish Shopping 树状数组套平衡树 || 平衡树

    Dish Shopping 将每个物品拆成p 和 s 再加上人排序. 然后问题就变成了, 对于一个线段(L - R), 问有多少个(li, ri)满足  L >= li && R ...

  5. Codeforces 830B - Cards Sorting 树状数组

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  6. CodeForces 522D Closest Equals 树状数组

    题意: 给出一个序列\(A\),有若干询问. 每次询问某个区间中值相等且距离最短的两个数,输出该距离,没有则输出-1. 分析: 令\(pre_i = max\{j| A_j = A_i, j < ...

  7. codeforces 589G G. Hiring(树状数组+二分)

    题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard inp ...

  8. CodeForces–830B--模拟,树状数组||线段树

    B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. Codeforces 960F Pathwalks ( LIS && 树状数组 )

    题意 : 给出若干个边,每条边按照给出的顺序编号,问你找到一条最长的边权以及边的编号同时严格升序的一条路径,要使得这条路径包含的边尽可能多,最后输出边的条数 分析 :  这题和 LIS 很相似,不同的 ...

随机推荐

  1. 【linux】【rpm】确定程序是否 rpm 安装

    执行 rpm -qf 文件名如果结果显示出安装包那就说明是rpm (或者yum)安装 详情参看 rpm -v  (或者 man rpm) ​

  2. Python学习笔记:configparser(INI格式配置文件解析)

    在平时的开发中感觉INI格式的配置文件使用还是挺需要的,有时会使用一个单独的py来存放一些常量或者配置项,大多时候这样倒是挺好用的,但是如果某些配置项需要在运行时由用户来修改指定,比如很多app在关闭 ...

  3. linux中的部分宏

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  4. configurationChanges

    在Android中每次屏幕的切换动会重启Activity,所以应该在Activity销毁前保存当前活动的状态,在Activity再次Create的时候载入配置.在activity加上android:c ...

  5. 一个通用的分页存储过程实现-SqlServer(附上sql源码,一键执行即刻搭建运行环境)

    使用前提 查询表必须有ID字段,且该字段不能重复,建议为自增主键 背景 如果使用ADO.NET进行开发,在查询分页数据的时候一般都是使用分页存储过程来实现的,本文提供一种通用的分页存储过程,只需要传入 ...

  6. 使用代码生成器“代码工厂”快速生成B/S程序代码

    开发目的: 自动生成C#.HTML.JS.Ajax 代码 .可以节省大量的时间来做业务逻辑的代码,那些重复的代码就不需要....了 环境支持: 硬件环境:window .VS2010+.支持SQLSe ...

  7. 如何安装mongodb.msi

    到MongoDB官网下载MongoDB软件:mongodb-win32-x86_64-2008plus-ssl-3.0.2-signed.msi, 放在想要安装的地方: 如:d:\MongoDB\ 2 ...

  8. 缓存淘汰算法之LFU

    1. LFU类 1.1. LFU 1.1.1. 原理 LFU(Least Frequently Used)算法根据数据的历史访问频率来淘汰数据,其核心思想是“如果数据过去被访问多次,那么将来被访问的频 ...

  9. js时间格式化工具,时间戳格式化,字符串转时间戳

    在开发中经常会用到时间格式化,有时候在网上搜索一大堆但不是自己想要的,自己总结一下,写一个时间格式化工具方便以后直接使用,欢迎大家来吐槽…… 1 2 3 4 5 6 7 8 9 10 11 12 13 ...

  10. jQuery 样式操作、文档操作、属性操作的方法总结

    文档操作: addClass()             向匹配的元素添加指定的类名.after()                    在匹配的元素之后插入内容.append()         ...