Total Submission(s): 2013 Accepted Submission(s): 520
Problem DescriptionThere are two groups of gangsters fighting with each other. The first group stands in a line, but the other group has a magic gun that can shoot a range [a, b], and everyone in that range will take a damage of c points. When a gangster is taking damage, if he has already taken at least P point of damage, then the damage will be doubled. You are required to calculate the damage that each gangster in the first group toke.
To simplify the problem, you are given an array A of length N and a magic number P. Initially, all the elements in this array are 0.
Now, you have to perform a sequence of operation. Each operation is represented as (a, b, c), which means: For each A[i] (a <= i <= b), if A[i] < P, then A[i] will be A[i] + c, else A[i] will be A[i] + c * 2.
Compute all the elements in this array when all the operations finish.
InputThe input consists several testcases.
The first line contains three integers n, m, P (1 <= n, m, P <= 200000), denoting the size of the array, the number of operations and the magic number.
Next m lines represent the operations. Each operation consists of three integers a; b and c (1 <= a <= b <= n, 1 <= c <= 20).
OutputPrint A[1] to A[n] in one line. All the numbers are separated by a space.
Sample Input
3 2 11 2 12 3 1
Sample Output
1 3 1
Source2011 Alibaba-Cup Campus Contest
Recommendlcy
#include <iostream>#include<stdio.h>#include<string.h>using namespace std;const int maxn=200010;int addv[maxn<<2],ma[maxn<<2],mi[maxn<<2],ans[maxn],pp;//開始mi開小了居然TLE坑呀。。。void btree(int L,int R,int k){ int ls,rs,mid; addv[k]=mi[k]=ma[k]=0; if(L==R) return ; ls=k<<1; rs=ls|1; mid=(L+R)>>1; btree(L,mid,ls); btree(mid+1,R,rs);}void update(int L,int R,int l,int r,int k,int d){ int ls,rs,mid; if(L==l&&R==r) { if(mi[k]>=pp) { addv[k]+=2*d; mi[k]+=2*d; ma[k]+=2*d; return ; } else if(ma[k]<pp) { addv[k]+=d; mi[k]+=d; ma[k]+=d; return ; } } ls=k<<1; rs=ls|1; mid=(L+R)>>1; if(addv[k]) { addv[ls]+=addv[k]; addv[rs]+=addv[k]; mi[ls]+=addv[k]; ma[ls]+=addv[k]; mi[rs]+=addv[k]; ma[rs]+=addv[k]; addv[k]=0; } if(r<=mid) update(L,mid,l,r,ls,d); else if(l>mid) update(mid+1,R,l,r,rs,d); else { update(L,mid,l,mid,ls,d); update(mid+1,R,mid+1,r,rs,d); } mi[k]=min(mi[ls],mi[rs])+addv[k]; ma[k]=max(ma[ls],ma[rs])+addv[k];}void getans(int L,int R,int k,int d){ int ls,rs,mid; if(L==R) { ans[L]=addv[k]+d; return; } ls=k<<1; rs=ls|1; mid=(L+R)>>1; getans(mid+1,R,rs,d+addv[k]); getans(L,mid,ls,d+addv[k]);}int main(){ int n,m,a,b,c,i; while(~scanf("%d%d%d",&n,&m,&pp)) { btree(1,n,1); while(m--) { scanf("%d%d%d",&a,&b,&c); update(1,n,a,b,1,c); } getans(1,n,1,0); for(i=1;i<n;i++) printf("%d ",ans[i]); printf("%d\n",ans[n]); } return 0;}