题目描述
blablabla
样例
算法1
Java 代码
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int[] arr=new int[n+1];
for(int i=1;i<=n;i++){
arr[i]=sc.nextInt();
}
int[] b = new int[n+2];
for(int i = 1; i<= n;i++){
insert(b, i, i, arr[i]);
}
for(int i = 0;i<m;i++){
int l = sc.nextInt();
int r = sc.nextInt();
int c = sc.nextInt();
insert(b, l, r, c);
}
for(int i = 1; i<= n;i++){
b[i] += b[i-1] ;
}
for(int i=1;i<=n;i++){
System.out.print(b[i] + " ");
}
}
public static void insert(int[] a,int l,int r,int c) {
a[l]+=c;
a[r+1]-=c;
}
}