zoj3745 Salary Increasing

OJ Problem Set - 3745

Salary Increasing

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 n integers 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 ≤ liri ≤ 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}.


Author: CHEN, Weijie
Contest: ZOJ Monthly, December 2013

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cmath>
#include<vector>
#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define eps 1e-9
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int maxn=100000+10;
int num[maxn];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,q;
    while(~scanf("%d%d",&n,&q))
    {
        int tmp;
        ll sum=0;
        memset(num,0,sizeof(num));
        for(int i=0;i<n;++i)
        {
            scanf("%d",&tmp);
            num[tmp]++;
            sum+=tmp;
        }
        int l,r,c;
        while(q--)
        {
            scanf("%d%d%d",&l,&r,&c);
            //if(l>r) swap(l,r);
            for(int i=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;
}

 

转载于:https://www.cnblogs.com/13224ACMer/p/4665254.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值