Submission #29367

#TimeUsernameProblemLanguageResultExecution timeMemory
29367cdemirerFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
399 ms11772 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<pair<int, int> > vii; typedef vector<vector<pair<int, int> > > vvii; #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) ll N, Q, S, T; ll A[200001]; ll res = 0; typedef struct Node_ { int llim, rlim; ll update; } Node; const int segsz = 524288; Node seg[segsz]; int offset = segsz/2; ll get(int x) { x += offset; ll ret = 0; while (x > 0) { ret += seg[x].update; x /= 2; } return ret; } void _update(int x, int l, int r, int dy) { int llim = seg[x].llim; int rlim = seg[x].rlim; int mid = (llim + rlim) / 2; if (l == llim && r == rlim) seg[x].update += dy; else if (l > mid) _update(2*x+1, l, r, dy); else if (r <= mid) _update(2*x, l, r, dy); else { _update(2*x, l, mid, dy); _update(2*x+1, mid+1, r, dy); } } void update(int l, int r, int dy) { _update(1, l, r, dy); } int main(int argc, char **argv) { //freopen("input", "r", stdin); //freopen("output", "w", stdout); //ios_base::sync_with_stdio(0); //cin.tie(0); //cin >> N >> Q >> S >> T; scanf("%lld%lld%lld%lld", &N, &Q, &S, &T); for (int i = offset; i < segsz; i++) { seg[i].llim = seg[i].rlim = i - offset; seg[i].update = 0; } for (int i = offset-1; i > 0; i--) { seg[i].llim = seg[2*i].llim; seg[i].rlim = seg[2*i+1].rlim; seg[i].update = 0; } for (int i = 0; i < N+1; i++) { //cin >> A[i]; scanf("%lld", &(A[i])); seg[i+offset].update = A[i]; } for (int i = 1; i < N+1; i++) { if (A[i] == A[i-1]) continue; if (A[i] > A[i-1]) res -= S*(A[i]-A[i-1]); else res += T*(A[i-1]-A[i]); } for (int i = 0; i < Q; i++) { int l, r, dy; //cin >> l >> r >> dy; scanf("%d%d%d", &l, &r, &dy); ll a = get(l-1), b = get(l), c = get(r); ll d = (r+1<=N?get(r+1):c); ll old_effect = (a>b?T*(a-b):-S*(b-a)) + (c>d?T*(c-d):-S*(d-c)); update(l, r, dy); b += dy; c += dy; if (r+1>N) d = c; ll new_effect = (a>b?T*(a-b):-S*(b-a)) + (c>d?T*(c-d):-S*(d-c)); res += new_effect - old_effect; //cout << res << "\n"; printf("%lld\n", res); } return 0; }

Compilation message (stderr)

foehn_phenomena.cpp: In function 'int main(int, char**)':
foehn_phenomena.cpp:56:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld%lld", &N, &Q, &S, &T);
                                           ^
foehn_phenomena.cpp:68:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &(A[i]));
                         ^
foehn_phenomena.cpp:78:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l, &r, &dy);
                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...