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


题目链接:

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. PHP数组函数 array_multisort() ----对多个数组或多维数组进行排序

    PHP中array_multisort可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序. 关联(string)键名保持不变,但数字键名会被重新索引. 输入数组被当成一个表的列并以 ...

  2. proc_info_list

    内核中每种处理器架构抽象为一个proc_info_list结构体,在arch/arm/include/asm/procinfo.h中定义, struct proc_info_list { unsign ...

  3. LeetCode(173) Binary Search Tree Iterator

    题目 Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ...

  4. 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven

    131072K   One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...

  5. re--参考手册

    表达式全集 字符 描述 \ 将下一个字符标记为一个特殊字符.或一个原义字符.或一个向后引用.或一个八进制转义符.例如,“n”匹配字符“n”.“\n”匹配一个换行符.串行“\\”匹配“\”而“\(”则匹 ...

  6. Prolog&Epilog

    这篇博客会简单介绍一下Prolog&Epilog 然后再简单介绍下我对于程序在计算机中到底如何运行的一些理解(因为自己之前也从来没有接触过这些方面的知识,所以如果有讲的不对的地方希望大家能够帮 ...

  7. WPF触控程序开发(三)——类似IPhone相册的反弹效果

    用过IPhone的都知道,IPhone相册里,当图片放大到一定程度后,手指一放,会自动缩回,移动图片超出边框后手指一放,图片也会自动缩回,整个过程非常和谐.自然.精确,那么WPF能否做到呢,答案是肯定 ...

  8. luogu2765 魔术球问题

    发现好像没人来证明贪心啊--那我来写一下它的证明 欲证明:放一个数在已有的柱上(如果可以)总是比新开一个柱更优的 假如已经放了x1..x2....xu..xv..xw.... 现在我要放xx 我有两种 ...

  9. 基于 FPGA 的图像边缘检测

    本文主要内容是实现图像的边缘检测功能 目录 mif文件的制作 调用 ip 核生成rom以及在 questasim 仿真注意问题 灰度处理 均值滤波:重点是3*3 像素阵列的生成 sobel边缘检测 图 ...

  10. TensorFlow——小练习:counter

    下面的例子演示了如何使用变量实现一个 简单的计数器(counter) # _*_coding:utf-8_*_ import tensorflow as tf import numpy as np # ...