Submission #954155

#TimeUsernameProblemLanguageResultExecution timeMemory
954155StefanSebezFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
137 ms16892 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N=3*1e5+500; ll p[N+50]; void Update(int i,ll qval){ for(;i<=N;i+=i&(-i)) p[i]+=qval; } ll Get(int i){ ll sum=0; for(;i>=1;i-=i&(-i)) sum+=p[i]; return sum; } //int Sum(int l,int r){return Get(r)-Get(l-1);} int main() { int n,q;ll S,T;scanf("%i%i%lld%lld",&n,&q,&S,&T); ll a[N+50];for(int i=0;i<=n;i++) scanf("%lld",&a[i]); ll b[N+50],res=0; for(int i=1;i<=n;i++){ if(a[i-1]<a[i]) b[i]=(a[i-1]-a[i])*S; else b[i]=(a[i-1]-a[i])*T; res+=b[i]; } //printf("%i\n",res); while(q--){ int l,r;ll x;scanf("%i%i%lld",&l,&r,&x); Update(l,x);Update(r+1,-x); ll temp=b[l],u=Get(l-1)+a[l-1],v=Get(l)+a[l]; if(u<v) b[l]=(u-v)*S; else b[l]=(u-v)*T; res+=b[l]-temp; //printf("%i %i %i %i\n",u,v,temp,b[l]); if(r+1<=n){ temp=b[r+1],u=Get(r)+a[r],v=Get(r+1)+a[r+1]; if(u<v) b[r+1]=(u-v)*S; else b[r+1]=(u-v)*T; res+=b[r+1]-temp; } printf("%lld\n",res); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:17:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     int n,q;ll S,T;scanf("%i%i%lld%lld",&n,&q,&S,&T);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:18:43: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     ll a[N+50];for(int i=0;i<=n;i++) scanf("%lld",&a[i]);
      |                                      ~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:27:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   int l,r;ll x;scanf("%i%i%lld",&l,&r,&x);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...