Submission #1258787

#TimeUsernameProblemLanguageResultExecution timeMemory
1258787truongnhattungFoehn Phenomena (JOI17_foehn_phenomena)C++20
0 / 100
341 ms14360 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int a[200004],st[6*200004], lazy[6*200004]; int pre[200004]; void build(int id,int l,int r) { if(l==r) { st[id]=a[l]; return; } int mid=(l+r)/2; build(id*2,l,mid); build(id*2+1,mid+1,r); st[id]=st[id*2]+st[id*2+1]; } void push(int id, int l, int r){ if(lazy[id]!=1){ st[id]+=lazy[id]; if(l!=r){ lazy[2*id]+=lazy[id]; lazy[2*id+1]+=lazy[id]; } lazy[id]=0; } } void update(int id, int l, int r, int u, int v, int val){ push(id,l,r); if(r<u||l>v) return; if(l>=u&&r<=v) { lazy[id]=val; push(id,l,r); return; } int m=(l+r)/2; update(2*id,l,m,u,v,val); update(2*id+1,m+1,r,u,v,val); st[id]=(st[2*id]+st[2*id+1]); } int get(int id,int l,int r,int u,int v) { push(id,l,r); if(l>v||r<u) return 0; if(u<=l&&r<=v) { return st[id]; } int mid=(l+r)/2; return get(2*id,l,mid,u,v)+get(2*id+1,mid+1,r,u,v); } main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n,q,s,t; cin>>n>>q>>s>>t; int kq=0; for (int i=0;i<=n;i++) { cin>>a[i]; if(i!=0) { if(a[i]>a[i-1]) { kq+=(a[i-1]-a[i])*s; pre[i]=(a[i-1]-a[i])*s; } else { kq+=(a[i-1]-a[i])*t; pre[i]=(a[i-1]-a[i])*t; } } } build(1,0,n); for (int i=1;i<=q;i++) { int l,r,x; cin>>l>>r>>x; update(1,0,n,l,r,x); int l1,r1,l2,r2; if(l-1>=0) { l1=get(1,0,n,l-1,l-1); r1=get(1,0,n,l,l); if(r1>l1) { kq=kq-pre[l]+(l1-r1)*s; pre[l]=(l1-r1)*s; } else { kq=kq-pre[l]+(l1-r1)*t; pre[l]=(l1-r1)*t; } } if(r+1<=n) { l2=get(1,0,n,r,r); r2=get(1,0,n,r+1,r+1); if(r2>l2) { kq=kq-pre[r+1]+(l2-r2)*s; pre[r+1]=(l2-r2)*s; } else { kq=kq-pre[r+1]+(l2-r2)*t; pre[r+1]=(l2-r2)*t; } } cout<<kq<<'\n'; } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...