AcWing 797. 差分
原题链接
简单
作者:
ls131
,
2020-05-15 11:57:09
,
所有人可见
,
阅读 517
#include <iostream>
using namespace std;
const int N = 100010;
int n, m;
int a[N], b[N];
void insert(int l, int r, int c)
{
b[l] += c;
b[r + 1] -= c;
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
//for (int i = 1; i <= n; i ++ ) cout<<a[i]<<' ';
// cout<<endl;
for (int i = 1; i <= n; i ++ ) insert(i, i, a[i]);
//for (int i = 1; i <= n; i ++ ) cout<<b[i]<<' ';
//cout<<endl;
while (m -- )
{
int l, r, c;
scanf("%d%d%d", &l, &r, &c);
insert(l, r, c);
// for (int i = 1; i <= n; i ++ ) printf("%d ", b[i]);
//cout<<endl;
}
for (int i = 1; i <= n; i ++ ) b[i] += b[i - 1];
for (int i = 1; i <= n; i ++ ) printf("%d ", b[i]);
return 0;
}