ZOJ月赛的一道稍微容易一点的题- - |||

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}.



题目的大意是说给出N个员工的初始工资,并给出Q次加薪机会,然后满足在L R 这个闭区间内的工资的员工可以得到C的工资加成,问最后N个人的总工资为多少钱。

额这道题一开始我跟鑫神看理解成了线段树的区间更新然后求输出最顶端的数,然后TLE了- - 大湿说直接暴力可以过,结果我就傻傻的去不做任何处理的去写了个暴力结果又T了,后来在大湿的指点下发现这道题类似于暑假老学长跟我说过的一个筛法的问题,这里是把人的工资用一个初始全为0的数组进行计数,然后碰到了第K个人的信息则A[K]++进行计数,然后这样一来就可以求当前的工资总和sum+=a[k]*c,然后注意每次从L到R注意每次要把后面的a[i+c]更新为a[i],而a[i]本身注意清零,然后用于后面的统计,然后就这样,暴力的过了。。。好吧复习期末的过程中没做题。。手又生了,,考完了寒假要努力刷点题了- -!

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;


int main()
{
    int a[100005];
    int n,q;
    long long m;
    while(cin>>n>>q)
    {   m=0;
        memset(a,0,sizeof(a));
        for(int i=1;i<=n;i++)
        {   int k;
            cin>>k;
            a[k]++;
            m+=k;
        }
        int l,r,c;
        while(q--)
        {
              cin>>l>>r>>c;
        for(int i=l;i<=r;i++ )
        {
                if(a[i]!=0)
                {
                    m+=c*a[i];
                }

        }
            for(int i=r;i>=l;i--)
            {
                a[i+c]+=a[i];
                a[i]=0;
            }
        }
        cout<<m<<endl;

    }




}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值