ZOJ 3475(机智的暴力)
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define M 100020
using namespace std;
#define LL long long int
LL a[M],total[M],s[M];
int main()
{
LL n,q;
while(cin>>n>>q)
{
LL sum=0;
memset(a,0,sizeof(a));
memset(s,0,sizeof(s));
for(int i=0; i<n; i++)
{
cin>>a[i];
s[a[i]]++;
sum+=a[i];
}
while(q--)
{
LL l,r,c;
cin>>l>>r>>c;
for(int i=l; i<=r; i++)
{
total[i+c]=s[i]+s[i+c];
sum+=s[i]*c;
s[i]=0;
}
for(int i=l; i<l+c; i++)
total[i]=0;
for(int i=l+c; i<=r+c; i++)
s[i]=total[i];
}
cout<<sum<<endl;
}
return 0;
}