이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define left 2*h,l,(l+r)/2
#define right 2*h+1,(l+r)/2+1,r
using namespace std;
const int N=2e5+5;
long long n,q,s,t,L,R,X,ANS,idx,x,y,V=0;
long long a[N],v[6*N];
void Get(Tree) {
if (idx<l || r<idx) return ; V+=v[h];
if (l==idx && r==idx) return ;
Get(left),Get(right);
}
void Upd(Tree) {
if (R<l || r<L) return ;
if (L<=l && r<=R) { v[h]+=X; return ; }
Upd(left),Upd(right);
}
void RectL(long long x,long long y,long long X) {
if (x<y) {
ANS+=(y-x)*s;
y+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
else {
ANS-=(x-y)*t;
y+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
}
void RectR(long long x,long long y,long long X) {
if (x<y) {
ANS+=(y-x)*s;
x+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
else {
ANS-=(x-y)*t;
x+=X;
if (x<y) ANS-=(y-x)*s;
else ANS+=(x-y)*t;
}
}
main () {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>q>>s>>t;
for (int i=0; i<=n; i++) {
cin>>a[i];
if (i) {
if (a[i-1]<a[i]) ANS-=(a[i]-a[i-1])*s;
else ANS+=(a[i-1]-a[i])*t;
L=i,R=i,X=a[i];
Upd(1,1,n);
}
}
while (q--) {
cin>>L>>R>>X;
if (R==n) {
idx=L-1,V=0,Get(1,1,n),x=V;
idx=L,V=0,Get(1,1,n),y=V;
RectL(x,y,X);
}
else {
idx=L-1,V=0,Get(1,1,n),x=V;
idx=L,V=0,Get(1,1,n),y=V;
RectL(x,y,X);
idx=R,V=0,Get(1,1,n),x=V;
idx=R+1,V=0,Get(1,1,n),y=V;
RectR(x,y,X);
}
Upd(1,1,n);
cout<<ANS<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'void Get(int, int, int)':
foehn_phenomena.cpp:12:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (idx<l || r<idx) return ; V+=v[h];
^~
foehn_phenomena.cpp:12:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if (idx<l || r<idx) return ; V+=v[h];
^
foehn_phenomena.cpp: At global scope:
foehn_phenomena.cpp:49:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |