# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
404119 | radaiosm7 | Foehn Phenomena (JOI17_foehn_phenomena) | C++98 | 173 ms | 10436 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, q, i, l, r;
long long s, t, c, ans, curl1, curl2, curr1, curr2;
long long alt[200005];
long long fen[200005];
void add(long long val, int indx) {
for (++indx; indx <= n; indx += (indx&(-indx))) {
fen[indx] += val;
}
}
void addlr(long long val, int l, int r) {
add(val, l);
add(-val, r+1);
}
long long point(int indx) {
long long res = 0LL;
for (++indx; indx > 0; indx -= (indx & (-indx))) {
res += fen[indx];
}
return res;
}
int main() {
scanf("%d%d%lld%lld", &n, &q, &s, &t);
ans = 0LL;
t *= -1LL;
scanf("%lld", &alt[0]);
for (i=1; i <= n; ++i) {
scanf("%lld", &alt[i]);
addlr(alt[i], i, i);
if (alt[i] > alt[i-1]) {
ans += (alt[i]-alt[i-1])*s;
}
else {
ans += (alt[i-1]-alt[i])*t;
}
}
while (q--) {
scanf("%d%d%lld", &l, &r, &c);
curl1 = point(l-1);
curl2 = point(l);
if (curl2 > curl1) {
ans -= (curl2-curl1)*s;
}
else {
ans -= (curl1-curl2)*t;
}
if (r+1 <= n) {
curr2 = point(r+1);
curr1 = point(r);
if (curr2 > curr1) {
ans -= (curr2-curr1)*s;
}
else {
ans -= (curr1-curr2)*t;
}
}
addlr(c, l, r);
curl2 = point(l);
if (curl2 > curl1) {
ans += (curl2-curl1)*s;
}
else {
ans += (curl1-curl2)*t;
}
if (r+1 <= n) {
curr1 = point(r);
if (curr2 > curr1) {
ans += (curr2-curr1)*s;
}
else {
ans += (curr1-curr2)*t;
}
}
printf("%lld\n", ans);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |