Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int n, q, tmp1, tmp2, res;
  5. int l, r, x;
  6. vector<long long> a(200001);
  7.  
  8. void initArray()
  9. {
  10.     a[n] = 0;
  11.     tmp2 = a[0];
  12.     for(int i=1;i<n;i++)
  13.     {
  14.         tmp1 = a[i];
  15.         a[i] = a[i]-tmp2;
  16.         tmp2 = tmp1;
  17.     }
  18.     for(int i=0;i<n;i++)
  19.         if(a[i]<0) res++;
  20. }
  21.  
  22. int NPCOS()
  23. {
  24.     if(l!=0)
  25.     {
  26.         if(a[l]<0){
  27.             a[l] += x;
  28.             if(a[l]>=0) res--;
  29.         }
  30.         else{
  31.             a[l] += x;
  32.             if(a[l]<0) res++;
  33.         }
  34.     }
  35.  
  36.     if(r+1 != n){
  37.         if(a[r+1]<0){
  38.             a[r+1] -= x;
  39.             if(a[r+1]>=0) res--;
  40.         }
  41.         else{
  42.             a[r+1] -= x;
  43.             if(a[r+1]<0) res++;
  44.         }
  45.     }
  46.     return res;
  47. }
  48.  
  49. int main()
  50. {
  51.     ios_base::sync_with_stdio(0);
  52.     cin.tie(0);
  53.     freopen("NPCOS.INP","r",stdin);
  54.     freopen("NPCOS.OUT","w",stdout);
  55.  
  56.     cin>>n>>q;
  57.     for(int i=0;i<n;i++)cin>>a[i];
  58.  
  59.     initArray();
  60.  
  61.     for(int i=0;i<q;i++)
  62.     {
  63.         cin>>l>>r>>x;
  64.         l--;r--;
  65.         cout<<NPCOS()<<" ";
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement