Submission #1012109

#TimeUsernameProblemLanguageResultExecution timeMemory
1012109vantamSjeckanje (COCI21_sjeckanje)C++17
55 / 110
2055 ms9140 KiB
#pragma GCC optimize("O3") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> using namespace std; const int N=200005 ; long long i,j,n,q,l,r,x; long long a[200005],f[200005],dp[200005][2]; long long st[4*N],s[4*N],mit[4*N], mis[4*N],mat[4*N],mas[4*N] ; void build(int id, int l, int r){ if(l==r){ st[id]=abs(f[l]);s[id]=mit[id]=mis[id]=mat[id]=mas[id]=f[l] ; return ; } int mid=(l+r)/2 ; build(2*id,l,mid) ; build(2*id+1,mid+1,r) ; st[id]=max({st[2*id], st[2*id+1],abs(mis[2*id]+mit[2*id+1]),abs(mas[2*id]+mat[2*id+1])}) ; s[id]=s[2*id]+s[2*id+1] ; mit[id]=min(mit[2*id],s[2*id]+mit[2*id+1]) ; mis[id]=min(mis[2*id+1],s[2*id+1]+mis[2*id]) ; mat[id]=max(mat[2*id],s[2*id]+mat[2*id+1]) ; mas[id]=max(mas[2*id+1],s[2*id+1]+mas[2*id]) ; //cout << id << " " << l << ' ' << r << ' ' << st[id] << '\n' ; return ; } void up(int id, int l, int r, int u){ if(r<u || u<l) return ; if(l==r){ st[id]=abs(f[u]);s[id]=mit[id]=mis[id]=mat[id]=mas[id]=f[u] ; return ; } int mid=(l+r)/2 ; up(2*id,l,mid,u) ; up(2*id+1,mid+1,r,u) ; st[id]=max({st[2*id], st[2*id+1],abs(mis[2*id]+mit[2*id+1]),abs(mas[2*id]+mat[2*id+1])}) ; s[id]=s[2*id]+s[2*id+1] ; mit[id]=min(mit[2*id],s[2*id]+mit[2*id+1]) ; mis[id]=min(mis[2*id+1],s[2*id+1]+mis[2*id]) ; mat[id]=max(mat[2*id],s[2*id]+mat[2*id+1]) ; mas[id]=max(mas[2*id+1],s[2*id+1]+mas[2*id]) ; return ; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); #define NAME "test" if(fopen(NAME".inp", "r")){ freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } cin >> n >> q; for(i=1;i<=n;i++){ cin >> a[i] ; f[i]=a[i]-a[i+1] ; } for(i=1;i<=n;i++){ f[i]=a[i]-a[i+1] ; } //build(1,1,n-1) ; //cout << f[3] << '\n' ; while(q--){ cin >> l >> r >> x ; f[l-1]-=x ; f[r]+=x ; //up(1,1,n-1,l-1) ; //up(1,1,n-1,r) ; //cout << st[1] << '\n' ; //cout << f[1] << '\n' ; for(i=1;i<n;i++){ if(f[i-1]*f[i]>=0){ dp[i][0]=max(dp[i-1][0], dp[i-1][1]) ; dp[i][1]=max(dp[i-1][0], dp[i-1][1])+abs(f[i]) ; }else{ //if(l==2 && i==2) cout << dp[i] dp[i][1]=dp[i-1][0]+abs(f[i]) ; dp[i][0]=max(dp[i-1][0], dp[i-1][1]) ; } //cout << f[3] << '\n' ; //cout << i << ' ' << dp[i][0] << ' ' << dp[i][1] << '\n'; } cout << max(dp[n-1][0], dp[n-1][1]) << '\n' ; } return 0; } /* 4 7 -1 3 -6 8 1 4 4 2 2 1 4 4 3 2 1 1 2 -1 1 1 2 -4 2 */

Compilation message (stderr)

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