Submission #252704

#TimeUsernameProblemLanguageResultExecution timeMemory
252704ChrisTFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
233 ms13180 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MN = 2e5 + 5; ll bit[MN], a[MN]; void update (int i, ll v) { for (;i<MN;i+=i&-i) bit[i] += v; } ll query (int i) { ll ret = 0; for (;i;i^=i&-i) ret += bit[i]; return ret; } int main () { int n,q,s,t; ll sum = 0; scanf ("%d %d %d %d",&n,&q,&s,&t); for (int i = 0; i <= n; i++) { scanf ("%lld",&a[i]); if (!i) continue; update(i,a[i]); update(i+1,-a[i]); if (a[i] <= a[i-1]) sum += (ll)t * (a[i-1] - a[i]); else sum -= (ll)s * (a[i]-a[i-1]); } while (q--) { int l,r,x; scanf ("%d %d %d",&l,&r,&x); if (l > 0) { a[l] = query(l); a[l-1] = query(l-1); if (a[l] <= a[l-1]) sum -= (ll)t * (a[l-1] - a[l]); else sum += (ll)s * (a[l]-a[l-1]); } if (r < n) { a[r+1] = query(r+1); a[r] = query(r); if (a[r+1] <= a[r]) sum -= (ll)t * (a[r] - a[r+1]); else sum += (ll)s * (a[r+1]-a[r]); } update(l,x); update(r+1,-x); if (l > 0) { a[l] = query(l); a[l-1] = query(l-1); if (a[l] <= a[l-1]) sum += (ll)t * (a[l-1] - a[l]); else sum -= (ll)s * (a[l]-a[l-1]); } if (r < n) { a[r+1] = query(r+1); a[r] = query(r); if (a[r+1] <= a[r]) sum += (ll)t * (a[r] - a[r+1]); else sum -= (ll)s * (a[r+1]-a[r]); } printf ("%lld\n",sum); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d %d %d %d",&n,&q,&s,&t);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:20:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%lld",&a[i]);  if (!i) continue;
   ~~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:27:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d %d %d",&l,&r,&x);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...