fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5.  
  6. int main(){
  7. int n, q; cin >> n >> q;
  8. int a[n];
  9. for(int &x : a) cin >> x;
  10. // Xây dựng mảng hiệu
  11. int d[n];
  12. for(int i = 0; i < n; i++){
  13. if(i == 0){
  14. d[i] = a[i];
  15. }
  16. else{
  17. d[i] = a[i] - a[i - 1];
  18. }
  19. }
  20.  
  21. while(q--){
  22. int l, r, k;
  23. cin >> l >> r >> k;
  24. d[l] += k;
  25. d[r + 1] -= k;
  26. }
  27.  
  28. // Tính mảng cộng dồn của mảng hiệu
  29. int pre[n];
  30. for(int i = 0; i < n; i++){
  31. if(i == 0){
  32. pre[i] = d[i];
  33. cout << pre[i] << " ";
  34. }
  35. else {
  36. pre[i] = pre[i - 1] + d[i];
  37. cout << pre[i] << " ";
  38. }
  39. }
  40. }
  41.  
  42.  
Success #stdin #stdout 0.01s 5296KB
stdin
7 3
8 5 8 9 7 6 9 
0 5 0
0 5 0
1 5 1
stdout
8 6 9 10 8 7 9