AcWing 797. 差分-JAVA
原题链接
简单
作者:
Susu
,
2020-01-26 00:20:13
,
所有人可见
,
阅读 573
import java.io.*;
public class Main{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
int n = Integer.valueOf(str[0]),m = Integer.valueOf(str[1]);
String[] strs =br.readLine().split(" ");
int[] a = new int[n+1];
int[] b = new int[n+2];
for(int i=1;i<=n;i++){
a[i]=Integer.valueOf(strs[i-1]);
b[i]+=a[i];
b[i+1]-=a[i];
}
while(m-->0){
String[] s = br.readLine().split(" ");
int l = Integer.valueOf(s[0]);
int r = Integer.valueOf(s[1]);
int c = Integer.valueOf(s[2]);
b[l]+=c;
b[r+1]-=c;
}
for(int i=1;i<=n;i++){
b[i]+=b[i-1];
System.out.print(b[i]+" ");
}
}
}
为什么不用Scanner?