fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9.  
  10. int n, q;
  11. cin >> n >> q;
  12.  
  13. vector<long long> a(n);
  14.  
  15. for(int i = 0; i < n; i++)
  16. cin >> a[i];
  17.  
  18. vector<long long> diff(n + 1, 0);
  19.  
  20. for(int i = 0; i < q; i++) {
  21. int l, r;
  22. cin >> l >> r;
  23.  
  24. diff[l]++;
  25. diff[r + 1]--;
  26. }
  27.  
  28. long long sum = 0;
  29.  
  30. for(int i = 0; i < n; i++) {
  31. sum += diff[i];
  32. a[i] += sum;
  33. }
  34.  
  35. for(int i = 0; i < n; i++)
  36. cout << a[i] << " ";
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5320KB
stdin
5 2
10 20 30 40 50
1 3
2 4
stdout
10 21 32 42 51