ZOJ3475解题报告
来源:互联网 发布:淘宝欠下贷款怎么协商 编辑:程序博客网 时间:2024/05/18 00:04
Edward has established a company with n staffs. He is such a kind man that he didQ 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 afterQ 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 followingn integers each describes the initial salary of a staff(mark as ai). After that, there areQ 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 11 2 3 42 3 4
Sample Output
18
Hint
{1, 2, 3, 4} → {1, 4, 6, 7}.
/* 题目:Salary Increasing 链接 : //http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3745 题意:在数组的指定范围的数值的元素上增加的一个值,求最后的数组总值 思路:暴力。先求初始时总值,并且记录每个值的个数,增加值时,在原来的和的基础上增加相应的值,最后就得出总值了*/#include<cstdio>#include<cstring>#include<iostream>using namespace std;#define LL long long#define M 100050LL a[M],l,r,n,c,q,ctotal[M],temp[M],ans;int main(){ LL i,j; while(~scanf("%lld %lld",&n,&q)) { ans=0; memset(ctotal,0,sizeof(ctotal)); memset(temp,0,sizeof(temp)); for(i=1;i<=n;i++) { scanf("%lld",&a[i]); temp[a[i]]++; ans+=a[i]; } memcpy(ctotal,temp,sizeof(temp)); while(q--) { scanf("%lld %lld %lld",&l,&r,&c); for(i=l;i<=r;i++) { if(i+c<M) ctotal[i+c]=temp[i]+temp[c+i]; ans+=temp[i]*c; temp[i]=0; } for(i=l;i<l+c&&i<M;i++) ctotal[i]=0; for(i=l+c;i<=r+c&&i<M;i++) temp[i]=ctotal[i]; } printf("%lld\n",ans); } return 0;}
- ZOJ3475解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- Antiprime解题报告
- expr解题报告
- 华容道解题报告
- tju解题报告
- zju1062/pku1095解题报告
- UsacoGate解题报告 --- 序曲
- ZJU 2060 解题报告
- ZJU 1331 解题报告
- ZJU 1115 解题报告
- ZJU1057解题报告
- vxl cannot build with share libs
- 三硬币问题
- Makefile介绍
- 获取Owner属性值的两种方式---Owner
- Java技术路线图
- ZOJ3475解题报告
- arcpy的错误处理机制
- canvas 使用细节
- 平板蓝牙测试与移植
- c++ 自加(自减)运算符--后++或--为什么要返回一个const?
- 研究生开题总结
- Mysql 日期函数
- 49 Java socket 2
- AE10.0开发中,要素类出现乱码问题