int n, m; int a[N]; int b[N]; //改变两边的值,使得中间连续值得以被间接改变,降低时间复杂度 voidinsert(int l, int r, int c) { b[l] += c; b[r + 1] -= c; } intmain() { scanf("%d%d", &n, &m); //获取前缀和即a数组 for (int i = 1;i <= n;++i) scanf("%d", &a[i]); //将前缀和赋给b,向b数组插入元素,假设前缀和皆为0 for (int i = 1;i <= n;++i) insert(i, i, a[i]); //改变区间内的前缀和 while (m--) { int l, r, c; scanf("%d%d%d", &l, & r, &c); insert(l, r, c); }
for (int i = 1;i <= n;++i) b[i] += b[i - 1]; for (int i = 1;i <= n;++i) printf("%d ", b[i]);