AcWing 797. 差分
原题链接
简单
练习java高效的输入输出
import java.io.*;
class Main{
static int N = 100010;
static int[] a = new int[N];
static int[] b = new int[N];
public static void main(String[] args) throws IOException {
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
String[] s = cin.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int m = Integer.parseInt(s[1]);
s = cin.readLine().split(" ");
for (int i = 1; i <= n; i++) {
a[i] = Integer.parseInt(s[i - 1]);
b[i] = a[i] - a[i - 1];
}
int l, r, c;
while (m-- > 0) {
s = cin.readLine().split(" ");
l = Integer.parseInt(s[0]);
r = Integer.parseInt(s[1]);
c = Integer.parseInt(s[2]);
b[l] += c;
b[r + 1] -= c;
}
for (int i = 1; i <= n; i++) {
a[i] = b[i] + a[i - 1];
//System.out.print(a[i] + " ");
log.write(a[i] + " ");
}
cin.close();
log.flush();
log.close();
}
}