https://codeforces.com/problemset/problem/295/A
题意:给定n个数,m次操作,k个设定。操作:给定区间[l, r]和d,对数组该区间内每个数增加d。k个设定:每次给定区间[l, r]∈[1, m],代表第l~r次操作执行了一次。问,最终执行完所有操作后,数组中的每个数的数值是多少。
思路:一眼差分,只不过要先统计出每次操作的操作次数,差分+前缀和。然后遍历每次操作,在区间上再进行差分的操作,但是数值不是输入的d,而是d * 之前统计出的该操作执行的次数。最后求前缀和,再加上原始的数组即可。
总结:题目不难,就是英文不行,没读懂题。。。。哎
inline void solve(){int n, m, k;cin >> n >> m >> k;vector<int> a(n);for (auto& x : a) {cin >> x;}vector<std::array<long long, 3>> adds(m);for (int i = 0; i < m; ++i) {cin >> adds[i][0] >> adds[i][1] >> adds[i][2];adds[i][0] --;adds[i][1] --;}vector<pair<int, int>> querys(k);vector<int> cnt(m + 1, 0);for (auto& [x, y] : querys) {cin >> x >> y;x --;y --;cnt[x] ++;cnt[y + 1] --;}for (int i = 1; i < m; ++i) {cnt[i] += cnt[i - 1];}vector<long long>b(n + 1);for (int i = 0; i < m; ++i) {auto[l, r, d] = adds[i];b[l] += cnt[i] * d;b[r + 1] -= cnt[i] * d;}for (int i = 1; i < n; ++i){b[i] += b[i - 1];}for (int i = 0; i < n; ++i) {cout << b[i] + a[i] << " \n"[i == n - 1];}}