# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
112306 | Mercenary | Foehn Phenomena (JOI17_foehn_phenomena) | C++14 | 163 ms | 13176 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;
#define taskname "A"
#define pb push_back
#define mp make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
int s , t , n , q;
ll a[maxn] , b[maxn];
void update(int x , int delta){
for( ; x <= n ; x += x & -x)
a[x] += delta;
}
ll query(int x){
ll res = 0;
for( ; x > 0 ; x &= x - 1)
res += a[x];
return res;
}
ll get(ll pre , ll now , ll add){
ll res = 0;
if(pre <= now){
res += (ll)s * (now - pre);
}else res -= (ll)t * (pre - now);
now += add;
if(pre <= now){
res -= (ll)s * (now - pre);
}else res += (ll)t * (pre - now);
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> q >> s >> t;
ll res = 0;
for(int i = 0 ; i <= n ; ++i){
cin >> b[i];
if(i > 0){
update(i,b[i]-b[i - 1]);
if(b[i] >= b[i - 1]){
res -= s * (ll)(b[i] - b[i - 1]);
// cout << i << " ";
}else{
res += t * (ll)(b[i - 1] - b[i]);
}
}
// cout << res << endl;
}
for(int i = 1 ; i <= q ; ++i){
int x , y , val;cin >> x >> y >> val;
res += get(query(x - 1) , query(x) , val);
if(y != n)res += get(query(y) , query(y + 1) , -val);
update(x,val);
update(y + 1 , -val);
cout << res << '\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... |