Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, q, tmp1, tmp2, res;
- int l, r, x;
- vector<long long> a(200001);
- void initArray()
- {
- a[n] = 0;
- tmp2 = a[0];
- for(int i=1;i<n;i++)
- {
- tmp1 = a[i];
- a[i] = a[i]-tmp2;
- tmp2 = tmp1;
- }
- for(int i=0;i<n;i++)
- if(a[i]<0) res++;
- }
- int NPCOS()
- {
- if(l!=0)
- {
- if(a[l]<0){
- a[l] += x;
- if(a[l]>=0) res--;
- }
- else{
- a[l] += x;
- if(a[l]<0) res++;
- }
- }
- if(r+1 != n){
- if(a[r+1]<0){
- a[r+1] -= x;
- if(a[r+1]>=0) res--;
- }
- else{
- a[r+1] -= x;
- if(a[r+1]<0) res++;
- }
- }
- return res;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- freopen("NPCOS.INP","r",stdin);
- freopen("NPCOS.OUT","w",stdout);
- cin>>n>>q;
- for(int i=0;i<n;i++)cin>>a[i];
- initArray();
- for(int i=0;i<q;i++)
- {
- cin>>l>>r>>x;
- l--;r--;
- cout<<NPCOS()<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement