이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 200010
int N, Q;
ll S, T;
ll A[maxn];
ll BIT[maxn]; //store offsets
void up(int spot, ll diff) {
while (spot < maxn) {
BIT[spot] += diff;
spot += spot & (-spot);
}
}
void update(int l, int r, ll diff) {
l+=2;
r+=2;
up(l, diff);
up(r+1, 0-diff);
}
ll query(int spot) {
spot+=2;
ll res = 0LL;
while (spot > 0) {
res += BIT[spot];
spot -= spot & (-spot);
}
return res;
}
ll getval(int spot) {
return A[spot] + query(spot); //think this is good
}
ll docons(ll v1, ll v2) {
if (v1 < v2) {
return -1LL*S*(v2-v1);
}
return T*(v1-v2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> Q >> S >> T;
for (int i = 0; i <= N; i++) {
cin >> A[i];
}
ll cans = 0LL;
for (int i = 1; i <= N; i++) {
cans += docons(A[i-1], A[i]);
}
int l, r;
ll x;
while (Q--) {
cin >> l >> r >> x;
ll odiff = 0LL;
ll v1, v2;
if (l != 0) {
odiff += docons(getval(l-1), getval(l));
}
if (r != N) {
odiff += docons(getval(r), getval(r+1));
}
cans -= odiff;
update(l, r, x);
if (l != 0) cans += docons(getval(l-1), getval(l));
if (r != N) cans += docons(getval(r), getval(r+1));
cout << cans << '\n';
}
cout.flush();
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:64:6: warning: unused variable 'v1' [-Wunused-variable]
ll v1, v2;
^~
foehn_phenomena.cpp:64:10: warning: unused variable 'v2' [-Wunused-variable]
ll v1, v2;
^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |