zoj3745 Salary Increasing

Source: Internet
Author: User

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&LT;MAXN) num[i+c]+=Num[i]; Num[i]=0; }} printf ("%lld\n", sum); }    return 0;}

zoj3745 Salary Increasing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.