Submission #647987

#TimeUsernameProblemLanguageResultExecution timeMemory
647987lalala56Sjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int N=2e5+9; ll ST[4*N]; int n,a[N],d[N],q; ll Me(ll L,ll R,int m,int l){ ll res; if((d[m]>=0||m==l)&&d[m+1]>=0)res=L+R+d[m+1]; else if((d[m]<=0||m==l)&&d[m+1]<=0)res=L+R-d[m+1]; else res=L+R; return res; } void build(int id,int l,int r){ if(l==r){ ST[id]=0; return; } int m=(l+r)/2; build(id*2,l,m); build(id*2+1,m+1,r); ST[id]=Me(ST[id*2],ST[id*2+1],m,l); //if(l==1&&r==2)cout<<ST[id]<<"L\n"; } void upd(int id,int l,int r,int v,int x){ if(v<l||v>r)return; if(l==r)return; int m=(l+r)/2; upd(id*2,l,m,v,x); upd(id*2+1,m+1,r,v,x); ST[id]=Me(ST[id*2],ST[id*2+1],m,l); //if(l==1&&r==2)cout<<ST[id]<<"L\n"; } void giai(){ cin>>n>>q; for(int i=1;i<=n;i++){ cin>>a[i]; d[i]=a[i]-a[i-1]; //cout<<d[i]<<" "; } //cout<<'\n'; d[0]=0; build(1,1,n); //cout<<ST[1]<<'\n'; int l,r; ll x; while(q--){ cin>>l>>r>>x; d[l]+=x; d[r+1]-=x; //for(int i=1;i<=n;i++)cout<<d[i]<<" "; //cout<<'\n'; upd(1,1,n,l,x); if(r<n)upd(1,1,n,r+1,x); cout<<ST[1]<<'\n'; } } int main(){ if(fopen("solve.inp","r")){ freopen("solve.inp","r",stdin); freopen("solve.out","w",stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); giai(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("solve.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("solve.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...