# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252704 | ChrisT | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 233 ms | 13180 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |