OJ problem Set-3745
Salary increasing Time limit: 2 Seconds Memory Limit: 65536 KB
Edward had established a company with n staffs. He is such a kind man the He did the Times Q salary increasing for his staffs. Each salary increasing is described by three integers ( l , r , c ). That means Edward would add units money for the staff c whose salaxy are in range [ l , r ] now. Edward wants to know the amount of all money he should pay to staffs after times Q salary increasing.
Input
The input file contains multiple test cases.
Each case begin with a integers: n --which indicate the amount of the staff; Q --which indicate times Q Salar Y increasing. The following n integers each describes the initial salary of a staff (mark as ai ). After that, there is Q triples of integers ( li , ri , ci ) ( i =1. Q ) which describe the salary Increasi ng in chronological.
1 ≤ n ≤105, 1≤ Q ≤105, 1≤ ai ≤105, 1≤ li ≤ ri ≤105, 1≤ ci ≤105, ri < c19/>
Process to the End of File.
Output
The Output of the total salary.
Sample Input
4 11 2 3 42 3 4
Sample Output
18
Hint
{1, 2, 3, 4}→{1, 4, 6, 7}.
Author: CHEN, Weijie
Contest: ZOJ Monthly, December
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<map>#include<queue>#include<Set>#include<stack>#include<cmath>#include<vector>#defineINF 0x3f3f3f3f#defineINF 0X3FFFFFFFFFFFFFFFLL#defineEPS 1e-9#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll;Const intmaxn=100000+Ten;intNUM[MAXN];intMain () {//freopen ("In.txt", "R", stdin); //freopen ("OUT.txt", "w", stdout); intn,q; while(~SCANF ("%d%d",&n,&q)) {inttmp; ll Sum=0; memset (num,0,sizeof(num)); for(intI=0; i<n;++i) {scanf ("%d",&tmp); NUM[TMP]++; Sum+=tmp; } intL,r,c; while(q--) {scanf ("%d%d%d",&l,&r,&c); //if (l>r) swap (l,r); for(inti=r;i>=l;--i) {sum+ = (LL) c*Num[i]; if(I+C<MAXN) num[i+c]+=Num[i]; Num[i]=0; }} printf ("%lld\n", sum); } return 0;}
zoj3745 Salary Increasing