이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n, q, k1, k2, a, z, l, r, d;
ll tren;
ll loga[200005];
void update(int x, int y) {
x++;
for (x; x <= n+1; x += x & -x) loga[x] += y;
}
ll query(int x) {
ll out = 0;
x++;
for (x; x > 0; x -= x & -x) out += loga[x];
return out;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q >> k1 >> k2;
for (int i = 0; i <= n; i++) {
cin >> a;
if (i > 0) {
if (a > z) tren -= k1*(ll)(a-z);
else tren += k2*(ll)(z-a);
}
z = a;
update(i, a);
update(i+1, -a);
}
for (int i = 0; i < q; i++) {
cin >> l >> r >> d;
ll br1 = query(l-1);
ll br2 = query(l);
if (br1 < br2) tren += k1*(ll)(br2-br1);
else tren -= k2*(ll)(br1-br2);
if (r+1 <= n) {
ll br1 = query(r);
ll br2 = query(r+1);
if (br1 < br2) tren += k1*(ll)(br2-br1);
else tren -= k2*(ll)(br1-br2);
}
update(l, d);
update(r+1, -d);
br1 = query(l-1);
br2 = query(l);
if (br1 < br2) tren -= k1*(ll)(br2-br1);
else tren += k2*(ll)(br1-br2);
if (r+1 <= n) {
ll br1 = query(r);
ll br2 = query(r+1);
if (br1 < br2) tren -= k1*(ll)(br2-br1);
else tren += k2*(ll)(br1-br2);
}
cout << tren << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'void update(int, int)':
foehn_phenomena.cpp:19:7: warning: statement has no effect [-Wunused-value]
19 | for (x; x <= n+1; x += x & -x) loga[x] += y;
| ^
foehn_phenomena.cpp: In function 'll query(int)':
foehn_phenomena.cpp:25:7: warning: statement has no effect [-Wunused-value]
25 | for (x; x > 0; x -= x & -x) out += loga[x];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |