|
GangsterTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2526 Accepted Submission(s): 656
Problem Description
There 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.
Input
The 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).
Output
Print A[1] to A[n] in one line. All the numbers are separated by a space.
Sample Input
Sample Output
|
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 0x3f3f3f3f
#define inf -0x3f3f3f3f
#define mem0(a) memset(a,0,sizeof(a))
const int maxn = 200000+10;
struct node{
int l,r,_max,_min,lazy;
}a[maxn<<2];
int n,m,P;
void Get(int cur){
a[cur]._max = max(a[cur<<1]._max,a[cur<<1|1]._max);
a[cur]._min = min(a[cur<<1]._min,a[cur<<1|1]._min);
}
void build(int l,int r,int cur){
a[cur].l = l;
a[cur].r = r ;
a[cur].lazy = a[cur]._min = a[cur]._max = 0;
if(l == r)
return ;
int mid = ( l + r )>>1;
build(l,mid,cur<<1);
build(mid+1,r,cur<<1|1);
}
void pushdown(int cur){
if(a[cur].lazy){
a[cur<<1].lazy += a[cur].lazy;
a[cur<<1]._min += a[cur].lazy;
a[cur<<1]._max += a[cur].lazy;
a[cur<<1|1].lazy += a[cur].lazy;
a[cur<<1|1]._min += a[cur].lazy;
a[cur<<1|1]._max += a[cur].lazy;
a[cur].lazy = 0 ;
}
}
void update(int l,int r,int v,int cur){
if(l == a[cur].l && r == a[cur].r ){
if(a[cur]._max < P){
a[cur].lazy += v;
a[cur]._min += v;
a[cur]._max += v;
return ;
}
else if(a[cur]._min >= P){
a[cur].lazy += 2*v;
a[cur]._min += 2*v;
a[cur]._max += 2*v;
return ;
}
}
pushdown(cur);
int mid = (a[cur].l+a[cur].r)>>1;
if(r <= mid)
update(l,r,v,cur<<1);
else if( l > mid)
update(l,r,v,cur<<1|1);
else {
update(l,mid,v,cur<<1);
update(mid+1,r,v,cur<<1|1);
}
Get(cur);
}
void query(int l,int r,int cur){
if( l == r){
if(l != 1)
printf(" ");
printf("%d",a[cur].lazy);
return ;
}
// if(a[cur].lazy != 0){
// a[cur<<1].lazy += a[cur].lazy;
// a[cur<<1|1].lazy +=a[cur].lazy;
// a[cur].lazy = 0;
// }
pushdown(cur);
int mid =( l + r)>>1;
query(l,mid,cur<<1);
query(mid+1,r,cur<<1|1);
}
int main()
{
while(scanf("%d%d%d",&n,&m,&P)!=EOF){
build(1,n,1);
while(m--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,1);
}
query(1,n,1);
printf("\n");
}
return 0;
}