一维差分
重点:差分只要会更新,一直更新一直爽
思路:先假设a[i]为0然后再一个一个的【i,i】小区间单点更新,就可以得到a[i]的差分
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
int n,m;
const int N = 100010;
int a[N];
int b[N];
void insert(int l,int r,int c)
{
b[l] += c;
b[r+1] -= c;
}
int main()
{
cin >>n>>m;
for(int i=1;i<=n;i)
{
scanf(“%d”,&a[i]);
}
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] +b[i];
for(int i=1;i<=n;i++)printf("%d ",b[i]);
return 0;
}