其他分享
首页 > 其他分享> > AcWing 797. 差分

AcWing 797. 差分

作者:互联网

题目传送门

#include <bits/stdc++.h>

using namespace std;
const int N = 100010;
int n, m;
int a[N], b[N];

/**
 * 功能:差分计算
 * @param l 左边界
 * @param r 右边界
 * @param c 值
 */
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++) cin >> a[i], insert(i, i, a[i]);
    while (m--) {
        int l, r, c;
        cin >> l >> r >> c;
        insert(l, r, c);
    }
    for (int i = 1; i <= n; i++)
        a[i] = a[i - 1] + b[i], printf("%d ", a[i]);
    return 0;
}

标签:797,insert,边界,int,cin,param,差分,AcWing
来源: https://www.cnblogs.com/littlehb/p/15761160.html