제출 #267315

#제출 시각아이디문제언어결과실행 시간메모리
267315leductoanFoehn Phenomena (JOI17_foehn_phenomena)C++14
30 / 100
511 ms18980 KiB
#include<bits/stdc++.h> using namespace std; #define task "Phenomena" #define lb lower_bound #define ub upper_bound #define alll(v) (v).begin(),(v).end() #define szz(v) (v).size() #define fi first #define se second #define pb push_back #define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i,b,a) for (int i = (b), _a = (a); i >= _a; --i) typedef long double ld; typedef long long ll; typedef pair<int,int> pii; const int MOD=1000000007; /// 998244353 const int base=311; /// for hash actually const int N=2e5+5; ll st[4*N],lazy[4*N],n,q,s,t,a[N]; void down(int i, int l, int r) { int t=lazy[i]; st[i<<1]+=t; st[i<<1|1]+=t; lazy[i<<1]+=t; lazy[i<<1|1]+=t; lazy[i]=0; } void upd(int i, int l, int r, int u, int v, int val) { if(u>r||v<l) return; if(u<=l&&r<=v) { lazy[i]+=val; st[i]+=val; return; } down(i,l,r); int mid=(l+r)>>1; upd(i<<1,l,mid,u,v,val); upd(i<<1|1,mid+1,r,u,v,val); } int get(int i, int l, int r, int p) { if(l==r) return st[i]; down(i,l,r); int mid=(l+r)>>1; if(p<=mid) return get(i<<1,l,mid,p); else return get(i<<1|1,mid+1,r,p); } void solved() { cin>>n>>q>>s>>t; s=-s; ll ans=0; ++n; FOR(i,1,n) { cin>>a[i]; upd(1,1,n,i,i,a[i]); } FOR(i,1,n-1) { if(a[i]<a[i+1]) ans+=s*(a[i+1]-a[i]); else ans+=t*(a[i]-a[i+1]); } while(q--) { int l,r,x; cin>>l>>r>>x; ++l,++r; int p1=get(1,1,n,l-1), p2=get(1,1,n,l); if(l>1&&p1<p2) ans-=s*(p2-p1); else ans-=t*(p1-p2); // cout<<s*(p2-p1)<<endl;s p1=get(1,1,n,r), p2=get(1,1,n,r+1); if(r<n&&p1<p2) ans-=s*(p2-p1); else ans-=t*(p1-p2); // cout<<ans<<endl; upd(1,1,n,l,r,x); p1=get(1,1,n,l-1), p2=get(1,1,n,l); if(l>1&&p1<p2) ans+=s*(p2-p1); else ans+=t*(p1-p2); p1=get(1,1,n,r), p2=get(1,1,n,r+1); if(r<n&&p1<p2) ans+=s*(p2-p1); else ans+=t*(p1-p2); cout<<ans<<'\n'; /*FOR(i,1,n) cout<<get(1,1,n,i)<<' '; cout<<endl;*/ } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } solved(); }

컴파일 시 표준 에러 (stderr) 메시지

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