# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
61030 | gusfring | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 353 ms | 162632 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;
const int MAXN = 2e5 + 5;
typedef long long ll;
ll bit[MAXN], A[MAXN], result;
int N, Q, S, T;
void updateP(int pos, int v){
while(pos <= N){ bit[pos] += v; pos += (pos&(-pos)); }
}
void update(int lo, int hi, int v){
updateP(lo, v);
updateP(hi + 1, -v);
}
ll query(int pos){
ll res = A[pos];
for(; pos>0; pos-=(pos&(-pos))) res += bit[pos];
return res;
}
ll val(ll a, ll b){
if(a < b) return (a - b) * S;
return (a - b) * T;
}
int main(){
scanf("%d %d %d %d", &N, &Q, &S, &T);
for(int i=0; i<=N; ++i) scanf("%lld", &A[i]);
for(int i=0; i<N; ++i) result += val(A[i], A[i + 1]);
while(Q--){
int l, r, v;
scanf("%d %d %d", &l, &r, &v);
result -= val(query(l - 1), query(l));
if(r < N) result -= val(query(r), query(r + 1));
update(l, r, v);
result += val(query(l - 1), query(l));
if(r < N) result += val(query(r), query(r + 1));
printf("%lld\n", result);
}
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... |