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


题目链接:

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. 如何用纯 CSS 创作一个方块旋转动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/gjgyWm 可交互视频 ...

  2. java 的多态(2013-10-11-163 写的日志迁移

    java 的多态性:(所谓多态--就是指一个引用(类型)在不同情况下的多种状态)   1.方法的多态:    重载(overload)   重写(覆盖 override)   2.对象的多态性:(本人 ...

  3. Python头脑风暴1

    发个致富脑洞:我就在想本人虽然单身,但本人恋爱经历很多,追女生技术十足,女朋友漂亮又贤惠.如果本人开个平台帮人诚心介绍女朋友,男女成男女朋友经男方同意我收2.5万(IT界平均月收入的1.5倍不到),双 ...

  4. SolrCloud下DIH实践

    创建Collection 在/usr/local/solrcloud/solr/server/solr文件夹下创建coreTest文件夹 将/usr/local/solrcloud/solr/serv ...

  5. Nordic Collegiate Programming Contest 2015​ D. Disastrous Downtime

    You're investigating what happened when one of your computer systems recently broke down. So far you ...

  6. 用Comparator排序和分组

    Test实体 import java.util.Objects; /** * @author gallen * @description * @date 2018/11/16 * @time 18:5 ...

  7. luogu2951 noip2017 小凯的疑惑

    在考场上我们可以打表发现规律是 $ ab-a-b $ .下面给出证明(看的网上的). 若有正数 $ x $ 不能被 $ a $ , $ b $ 组合出,假设 $ a>b $ ,则存在 \[ x= ...

  8. 全链路spring cloud sleuth+zipkin

    http://blog.csdn.net/qq_15138455/article/details/72956232 版权声明:@入江之鲸 一.About ZipKin please google 二. ...

  9. Mysql 安装及MySQL-python 问题

    今天遇到了个低级问题: EnvironmentError:mysql_config not found 网上谷歌了一圈发现没用,静下来想的时候才发现新电脑没安装Mysql,吐血 后面再去官网上下载My ...

  10. 深度学习:Sigmoid函数与损失函数求导

    1.sigmoid函数 ​ sigmoid函数,也就是s型曲线函数,如下: 函数: 导数: ​ 上面是我们常见的形式,虽然知道这样的形式,也知道计算流程,不够感觉并不太直观,下面来分析一下. 1.1 ...