ZOJ 3745 Salary Increasing
Description
Edward has established a company with n staffs. He is such a kind man that he did Q times salary increasing for his staffs. Each salary increasing was described by three integers (l, r, c). That means Edward will add c units money for the staff whose salaxy is in range [l, r] now. Edward wants to know the amount of total money he should pay to staffs after Q times salary increasing.
Input
The input file contains multiple test cases.
Each case begin with two integers : n -- which indicate the amount of staff; Q -- which indicate Q times salary increasing. The following nintegers each describes the initial salary of a staff(mark as ai). After that, there are Q triples of integers (li, ri, ci) (i=1..Q) which describe the salary increasing in chronological.
1 ≤ n ≤ 105 , 1 ≤ Q ≤ 105 , 1 ≤ ai ≤ 105 , 1 ≤ li ≤ ri ≤ 105 , 1 ≤ ci ≤ 105 , ri < li+1
Process to the End Of File.
Output
Output the total salary in a line for each case.
Sample Input
4 1
1 2 3 4
2 3 4
Sample Output
18
Hint
{1, 2, 3, 4} → {1, 4, 6, 7}.
这绝对是个水题,但同时又是个不折不扣的大坑题,一开始没注意ri < li+1 ,差点用线段树做。
#include <iostream>
#include <cstring>
using namespace std; long long num[],n,m,l,r,add;//坑!开100005不够,因为工资一开始最高为100000,但后面可以涨工资。
int main()
{ while (cin>>n>>m)
{
memset(num,,sizeof(num));
for (int i=;i<=n;i++)
{
cin>>add;
num[add]++;
}
for (int i=;i<=m;i++)
{
cin>>l>>r>>add;
for (int j=r;j>=l;j--)//坑!应该从大到小计算,不然会对后面产生影响。
{
if (num[j])
{
num[j+add]+=num[j];
num[j]=;
}
}
}
add=;
for (int i=;i<;i++)//坑!一开始只从1算到100000,wrong了好几次,后来发现工资可能超过100000.
add=add+num[i]*i;
cout <<add<<endl;
}
return ;
}
#include <iostream>#include <cstring>using namespace std;
long long num[600100],n,m,l,r,add;//坑!开100005不够,因为工资一开始最高为100000,但后面可以涨工资。 int main(){ while (cin>>n>>m) { memset(num,0,sizeof(num)); for (int i=1;i<=n;i++) { cin>>add; num[add]++; } for (int i=1;i<=m;i++) { cin>>l>>r>>add; for (int j=r;j>=l;j--)//坑!应该从大到小计算,不然会对后面产生影响。 { if (num[j]) { num[j+add]+=num[j]; num[j]=0; } } } add=0; for (int i=1;i<600100;i++)//坑!一开始只从1算到100000,wrong了好几次,后来发现工资可能超过100000. add=add+num[i]*i; cout <<add<<endl; } return 0;}
ZOJ 3745 Salary Increasing的更多相关文章
- zoj 3745 Salary Increasing(坑爹的细节题!)
题目 注意题目中的,引用绝望的乐园中的进一步解释如下: 这是一道浙大月赛的题,一如既往的坑爹,好好一道水题,被搞成一道坑题!!! //注意:r(i) < l(i+1) !细节啊细节! #incl ...
- zoj3745 Salary Increasing
OJ Problem Set - 3745 Salary Increasing Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has ...
- ZOJ 2432 Greatest Common Increasing Subsequence(最长公共上升子序列+路径打印)
Greatest Common Increasing Subsequence 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...
- $ZOJ\ 2432\ Greatest\ Common\ Increasing\ Subsequence$
传送门 $Description$ 求两个序列的最长公共上升子序列 $Solution$ $f[i][j]$表示$a$序列匹配到$i$和$b$序列匹配到$j$的最长上升序列的长度,这里并不要求$a[i ...
- HDU 1423 Greatest Common Increasing Subsequence LCIS
题目链接: 题目 Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2 ...
- HDU1423:Greatest Common Increasing Subsequence(LICS)
Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...
- Greatest Common Increasing Subsequence hdu1423
Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
随机推荐
- Discuz!提取文章标签
<?php //强制使用字符集 @header('Content-Type: text/html; charset=gbk'); $subjectenc ='title'; //这是 ...
- Android Development Tools 发生checkAndLoadTargetData错误
之前使用时没有出现任何问题的,我把D:\IDE\ADT\adt-bundle-windows-x86_64-20140321\eclipse目录下面的 eclipse.exe重名名为adt.exe并设 ...
- 使用PULL方式解析XML资源文件下面的xml文件
public class MainActivity extends Activity { private Button btn = null; private List<Map<Strin ...
- final关键字的作用
final 可以修饰类.方法.变量. (1):final修饰的变量是一个常量,只能被赋值一次. 常量一般使用final声明,如: public static final String CHINA = ...
- BZOJ 1063 道路设计NOI2008
http://www.lydsy.com/JudgeOnline/problem.php?id=1063 题意:给你一棵树,也有可能是不连通的,把树分成几个链,求每个点到根经过的最大链数最小,而且要输 ...
- 通过实现Comparable接口结合TreeSet来对对象自动排序
经过会遇到这样的情况,对于某个对象数组或者链表要按照一定的规则进行排序,那么我们该怎么做呢? 如遇到这样的需求: 1.需求1 对于学生对象按照年龄进行排序,年龄小的排在前面. 单单看到这样的需求,实现 ...
- cf448B Suffix Structures
B. Suffix Structures time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Gym 100570E : Palindrome Query
De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to i ...
- Duff策略
Tom Duff首先在C语言中提出了展开循环的构想,所以这种模式被称之为Duff策略.Duff策略背后的思想是每一次循环完成标准循环的1-8次.首先通过数组值得总数除以8来取定循环次数.Duff发现对 ...
- Linux系统启动流程及grub重建(1)
日志系统 Linux系统启动流程 PC: OS(Linux) POST-->BIOS(Boot Sequence)-->MBR(bootloader,446)-->Kernel--& ...