# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
706401 | Alihan_8 | Foehn Phenomena (JOI17_foehn_phenomena) | C++17 | 169 ms | 13128 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>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q, S, _T;
cin >> n >> q >> S >> _T;
vector <int> p(n+1);
for ( auto &i: p ) cin >> i;
vector <int> bit(n+1);
auto upd = [&](int i, int val){
for (; i <= n; i += i&-i ) bit[i] += val;
};
auto get = [&](int i){
int cnt = 0;
for (; i > 0; i -= i&-i ) cnt += bit[i];
return cnt;
};
int cnt = 0;
for ( int i = 1; i <= n; i++ ){
if ( p[i-1] < p[i] ) cnt -= S*(p[i]-p[i-1]);
else cnt += _T*(-p[i]+p[i-1]);
upd(i, p[i]), upd(i+1, -p[i]);
}
while ( q-- ){
int l, r, x; cin >> l >> r >> x;
if ( get(l) > get(l-1) ) cnt += S*(get(l)-get(l-1));
else cnt -= _T*(-get(l)+get(l-1));
if ( r+1 <= n ){
if ( get(r+1) > get(r) ) cnt += S*(get(r+1)-get(r));
else cnt -= _T*(get(r)-get(r+1));
}
upd(l, x), upd(r+1, -x);
if ( get(l) > get(l-1) ) cnt -= S*(get(l)-get(l-1));
else cnt += _T*(-get(l)+get(l-1));
if ( r+1 <= n ){
if ( get(r+1) > get(r) ) cnt -= S*(get(r+1)-get(r));
else cnt += _T*(get(r)-get(r+1));
}
cout << cnt << ln;
}
cout << '\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... |