이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define tam 200002
#define alt(x) (arr[x] + query(x))
lli BIT[tam],arr[tam],ST[(1<<19)+2];
lli n,q,s,t,a,b,l,r,c,offset,d;
void agrega(lli pos, lli val) {
while (pos < tam) {
BIT[pos] += val;
pos += pos&(-pos);
}
}
lli query(lli pos) {
lli res = 0;
while (pos > 0) {
res += BIT[pos];
pos -= pos&(-pos);
}
return res;
}
void actualiza(lli nodo, lli val) {
lli mitad,a,b;
ST[nodo] = val;
nodo /= 2;
while (nodo > 0) {
ST[nodo] = ST[nodo*2] + ST[(nodo*2)+1];
nodo /= 2;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q >> s >> t;
rep(i,0,n) cin >> arr[i];
s *= -1;
offset = 1;
while (offset < n) offset<<=1;
rep(i,0,n-1) {
a = arr[i];
b = arr[i+1];
c = (a<b)? (b-a)*s : (a-b)*t;
ST[offset+i] = c;
}
repa(i,offset-1,1) ST[i] = ST[i<<1] + ST[(i<<1)+1];
rep(i,1,q) {
cin >> l >> r >> c;
agrega(l,c);
agrega(r+1,-c);
a = alt(l-1);
b = alt(l);
c = (a<b)? (b-a)*s : (a-b)*t;
actualiza(l+offset-1, c);
if (r < n) {
a = alt(r);
b = alt(r+1);
c = (a<b)? (b-a)*s : (a-b)*t;
actualiza(r+offset, c);
}
cout << ST[1] << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'void actualiza(long long int, long long int)':
foehn_phenomena.cpp:33:9: warning: unused variable 'mitad' [-Wunused-variable]
33 | lli mitad,a,b;
| ^~~~~
foehn_phenomena.cpp:33:15: warning: unused variable 'a' [-Wunused-variable]
33 | lli mitad,a,b;
| ^
foehn_phenomena.cpp:33:17: warning: unused variable 'b' [-Wunused-variable]
33 | lli mitad,a,b;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |