Submission #58919

#TimeUsernameProblemLanguageResultExecution timeMemory
58919TadijaSebezFoehn Phenomena (JOI17_foehn_phenomena)C++11
100 / 100
363 ms52080 KiB
#include <stdio.h> #define ll long long const int N=200050; struct BIT { ll sum[N],a[N]; void init(){ for(int i=0;i<N;i++) sum[i]=a[i]=0;} void Set1(int i, ll x){ int j=i;for(;i<N;i+=i&-i) sum[i]+=x-a[j];a[j]=x;} void Set2(int i, ll x){ for(i++;i<N;i+=i&-i) sum[i]+=x;} void Set2(int l, int r, ll x){ Set2(l,x);Set2(r+1,-x);} ll Get1(int i){ ll ret=0;for(;i;i-=i&-i) ret+=sum[i];return ret;} ll Get2(int i){ return Get1(i+1);} ll Get1(){ return Get1(N-1);} } BIT1,BIT2; int a[N],s,t; ll abs(ll x){ return x>0?x:-x;} ll Get(ll x, ll y) { return (ll)(x>y?-s:t)*abs(x-y); } int main() { int n,q,i;BIT1.init();BIT2.init(); scanf("%i %i %i %i",&n,&q,&s,&t); for(i=0;i<=n;i++) scanf("%i",&a[i]),BIT2.Set2(i,i,a[i]); for(i=1;i<=n;i++) BIT1.Set1(i,Get(a[i],a[i-1])); int l,r,x; while(q--) { scanf("%i %i %i",&l,&r,&x); BIT2.Set2(l,r,x); BIT1.Set1(l,Get(BIT2.Get2(l),BIT2.Get2(l-1))); if(r!=n) BIT1.Set1(r+1,Get(BIT2.Get2(r+1),BIT2.Get2(r))); printf("%lld\n",BIT1.Get1()); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i %i %i",&n,&q,&s,&t);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:25:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=0;i<=n;i++) scanf("%i",&a[i]),BIT2.Set2(i,i,a[i]);
                    ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i %i",&l,&r,&x);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...