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 int long long
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 998244353;
struct FenwickTree {
vector<int> s; int res;
FenwickTree(int n) : s(n) {}
void modify(int pos, int dif) {
for(; pos < s.size(); pos|=pos+1) s[pos] += dif;
}
int calc(int pos) {
for(res = 0; pos > 0; pos&=pos-1) res += s[pos-1];
return res;
}
};
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie();
int n, q, s, t; cin>>n>>q>>s>>t;
FenwickTree bit(n+1);
for (int i = 0, pre = 0, a; i <= n; i++) {
cin>>a; bit.modify(i, a - pre);
pre = a;
}
int res = 0;
auto update = [&](int i, int mult) {
if (i+1 > n) return;
int dif = bit.calc(i+1) - bit.calc(i+2);
if (dif < 0) res += mult*s*dif;
else res += mult*t*dif;
};
for (int i = 0; i <= n; i++) update(i, 1);
while (q--) {
int l, r, x; cin>>l>>r>>x;
update(l-1, -1);
update(r, -1);
bit.modify(l, x);
bit.modify(r+1, -x);
update(l-1, 1);
update(r, 1);
cout<<res<<"\n";
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In member function 'void FenwickTree::modify(long long int, long long int)':
foehn_phenomena.cpp:15:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(; pos < s.size(); pos|=pos+1) s[pos] += dif;
| ~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |