Advertisement
newb_ie

static range update

Nov 15th, 2021
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2.  
  3. using namespace std;
  4.  
  5. int main () {
  6. int n, q;
  7. cin >> n >> q;
  8. int a[n + 1];
  9. for (int i = 0; i <= n; ++i) a[i] = 0;
  10. for (int i = 1; i <= q; ++i) {
  11. int l, r, x;
  12. cin >> l >> r >> x;
  13. a[l] += x;
  14. if (r + 1 <= n) {
  15. a[r + 1] -= x;
  16. }
  17. }
  18. int sum = 0;
  19. int pref[n + 1];
  20. for (int i = 1; i <= n; ++i) {
  21. sum += a[i];
  22. pref[i] = sum;
  23. }
  24. for (int i = 1; i <= n; ++i) cout << pref[i] << ' ';
  25. }
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement