제출 #926881

#제출 시각아이디문제언어결과실행 시간메모리
926881haru09Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
111 ms12560 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define task "code" const int ar=2e5+5; const ll mod=1e9+7; int n,q,s,t; int a[ar]; ll ans=0; ll bit[ar]; void update(int u,int v) { int id=u; while(id<=n+1) { bit[id]+=v; id+=id&(-id); } } ll get(int p) { int id=p; ll ans=0; while(id>0) { ans+=bit[id]; id-=id&(-id); } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin>>n>>q>>s>>t; for (int i=0;i<=n;i++) { cin>>a[i]; if (i) update(i,a[i]),update(i+1,-a[i]); } for (int i=1;i<=n;i++) { if (a[i]>a[i-1]) ans-=1ll*s*(a[i]-a[i-1]); else ans+=1ll*t*(a[i-1]-a[i]); } while(q--) { int l,r,x; ll val1,val2; cin>>l>>r>>x; val1=get(l); val2=get(l-1); if (val1>val2) ans+=(val1-val2)*s; else ans-=(val2-val1)*t; if (r<n) { val1=get(r+1); val2=get(r); if (val1>val2) ans+=(val1-val2)*s; else ans-=(val2-val1)*t; } update(l,x); update(r+1,-x); val1=get(l); val2=get(l-1); if (val1>val2) ans-=(val1-val2)*s; else ans+=(val2-val1)*t; if (r<n) { val1=get(r+1); val2=get(r); if (val1>val2) ans-=(val1-val2)*s; else ans+=(val2-val1)*t; } cout<<ans<<'\n'; } }

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

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