# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
977843 | SmuggingSpun | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 117 ms | 11620 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>
#define taskname "A"
using namespace std;
typedef long long ll;
const int lim = 2e5 + 5;
int n, q, s, t;
ll ans = 0, bit[lim];
void update(int p, int x){
for(; p <= n; p += p & -p){
bit[p] += x;
}
}
ll get(int p){
ll ans = 0;
for(; p > 0; p -= p & -p){
ans += bit[p];
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> q >> s >> t;
int x;
cin >> x;
for(int i = 1, pre = 0; i <= n; i++, pre = x){
cin >> x;
update(i, x - pre);
if(pre < x){
ans -= 1LL * s * (x - pre);
}
else{
ans += 1LL * t * (pre - x);
}
}
for(int _ = 0; _ < q; _++){
int l, r, x;
cin >> l >> r >> x;
ll d = get(l - 1) - get(l);
if(d < 0){
ans += 1LL * s * -d;
}
else{
ans -= 1LL * t * d;
}
if(r < n){
if((d = get(r) - get(r + 1)) < 0){
ans += 1LL * s * -d;
}
else{
ans -= 1LL * t * d;
}
}
update(l, x);
update(r + 1, -x);
if((d = get(l - 1) - get(l)) < 0){
ans -= 1LL * s * -d;
}
else{
ans += 1LL * t * d;
}
if(r < n){
if((d = get(r) - get(r + 1)) < 0){
ans -= 1LL * s * -d;
}
else{
ans += 1LL * t * d;
}
}
cout << ans << "\n";
}
}
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... |