1915. 一维差分

模板题,不解释代码及一般步骤。注意开快读和long long。

#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mn = 1e5 + 10; ll n, m, a[mn]; signed main() { ios::sync_with_stdio(false), cin.tie(0); cin >> n >> m; for (ll l, r, v; m--;) { cin >> l >> r >> v; a[l] += v, a[r + 1] -= v; } for (ll i = 1; i <= n; ++i) { a[i] += a[i - 1]; cout << a[i] << ' '; } return 0; }