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 ...
随机推荐
- js基础小总结之string&array&object
一.数据类型之间的转换 string--->number :parseInt(string)/parseFloat(string); 注:在Date中,因为返回值date为单位为ms的字符串,将 ...
- Xcode中C、C++、Object-C3种语言的混编
转自: http://hi.baidu.com/onejw/item/f34390c997cdc226a1b50ae http://www.cocoachina.com/ask/questions/s ...
- 如何在异步请求时设置RequestHeader
一.为何要用到setRequestHeader 通常在HTTP协议里,客户端像服务器取得某个网页的时候,必须发送一个HTTP协议的头文件,告诉服务器客户端要下载什么信息以及相关的参数.而 XMLHTT ...
- cf C. Cupboard and Balloons
http://codeforces.com/contest/342/problem/C #include <cstdio> #include <cstring> #includ ...
- wikioi1369 xth 砍树
题目描述 Description 在一个凉爽的夏夜,xth 和 rabbit 来到花园里砍树.为啥米要砍树呢?是这样滴, 小菜儿的儿子窄森要出生了.Xth这个做伯伯的自然要做点什么.于是他决定带着 r ...
- UESTC_排名表 2015 UESTC Training for Graph Theory<Problem I>
I - 排名表 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- 精通find命令
一.前言 find命令是linux使用过程中经常用到的命令,但可能大家只会如下使用find find ./ 或者这样使用 find ./ | grep str 上述命令等同于 find ./ -nam ...
- poj2196
Specialized Four-Digit Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7238 A ...
- Java遍历Map对象的四种方法
在java中遍历Map有不少的方法.我们看一下最常用的方法及其优缺点. 既然java中的所有map都实现了Map接口,以下方法适用于任何map实现(HashMap, TreeMap, LinkedHa ...
- python实现二叉树和它的七种遍历
介绍: 树是数据结构中很重要的一种,基本的用途是用来提高查找效率,对于要反复查找的情况效果更佳,如二叉排序树.FP-树. 另外能够用来提高编码效率,如哈弗曼树. 代码: 用python实现树的构造和几 ...