이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pii pair<int, int>
#define piss pair<int, pii>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 2e5+5;
int n, q, s, t;
int a[N], b[N];
int tree[N*4];
void build(int l, int r, int idx) {
if (l == r) {
// cout << idx << " " << l << " Lll " << endl;
if (b[l] < 0) tree[idx] = (-s) * abs(b[l]);
else tree[idx] = abs(b[l]) * t;
return;
}
int mid = (l + r) / 2;
build(l, mid, idx*2);
build(mid+1, r, idx*2+1);
tree[idx] = tree[idx*2] + tree[idx*2+1];
// cout << idx << " " << tree[idx] << " " << mid << endl;
}
void update(int l, int r, int where, int idx) {
// cerr << l << " " << r << " " << where << endl;
if (l > where or r < where) return;
if (l == r && r == where) {
if (b[l] < 0) tree[idx] = (-s) * abs(b[l]);
else tree[idx] = abs(b[l]) * t;
return;
}
int mid = (l + r) / 2;
if (where <= mid) update(l, mid, where, idx*2);
else update(mid+1, r, where, idx*2+1);
tree[idx] = tree[idx*2] + tree[idx*2+1];
}
signed main() {
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) b[i] = a[i-1] - a[i];
build(1, n, 1);
// for (int i = 1; i <= 7; i++) cout << i << ": " << tree[i] << endl;
while(q--) {
int x, y, z; cin >> x >> y >> z;
b[x] -= z;
b[y+1] += z;
update(1, n, x, 1);
update(1, n, y+1, 1);
// cerr << "..." << endl;
cout << tree[1] << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |