이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Why I am so dumb? :c
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = (int)2e5 + 5;
ll t[MAXN << 2];
int n, q, a, b;
int arr[MAXN];
ll ans;
void segUpd(int v, int tl, int tr, int l, int r, int x) {
if (l > r || tl > r || tr < l) {
return;
}
if (l <= tl && tr <= r) {
t[v] += x;
return;
}
int mid = (tl + tr) >> 1;
int c1 = (v << 1), c2 = (c1 | 1);
segUpd(c1, tl, mid, l, r, x);
segUpd(c2, mid + 1, tr, l, r, x);
}
ll getVal(int v, int tl, int tr, int ps) {
if (tl == tr) {
return t[v] + arr[tl];
}
int mid = (tl + tr) >> 1;
int c1 = (v << 1), c2 = (c1 | 1);
if (ps <= mid) {
return t[v] + getVal(c1, tl, mid, ps);
}
else {
return t[v] + getVal(c2, mid + 1, tr, ps);
}
}
ll calc(int ps) {
if (ps < 0 || ps == n) {
return 0ll;
}
ll v1 = getVal(1, 0, n, ps);
ll v2 = getVal(1, 0, n, ps + 1);
if (v1 < v2) {
return a * (v1 - v2);
}
else {
return b * (v1 - v2);
}
}
void solve() {
scanf("%d %d %d %d", &n, &q, &a, &b);
for (int i = 0; i <= n; ++i) {
scanf("%d", &arr[i]);
}
for (int i = 0; i < n; ++i) {
ans += calc(i);
}
for (int i = 1; i <= q; ++i) {
int l, r, x;
scanf("%d %d %d", &l, &r, &x);
ans -= calc(l - 1);
ans -= calc(r);
segUpd(1, 0, n, l, r, x);
ans += calc(l - 1);
ans += calc(r);
printf("%lld\n", ans);
}
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'void solve()':
foehn_phenomena.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &n, &q, &a, &b);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:88:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &l, &r, &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... |