이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;
int N, Q; ll S, T;
ll A[1000010];
int L, R; ll X, now;
struct dt {
ll ar[(1<<22)], lz[(1<<22)];
void init() { for (int i=0; i<=N; i++) upd(i, i, A[i]); }
ll get(int t, int s, int e, int i) {
spread(i);
if (s==e) return ar[i];
int md=(s+e)/2;
if (t<=md) return get(t, s, md, i*2);
else return get(t, md+1, e, i*2+1);
}
void upd(int is, int ie, int s, int e, int i, ll val) {
if (s>e) return ;
if (is<=s&&e<=ie) { lz[i]+=val; return ; }
int md=(s+e)/2;
if (is<=md) upd(is, ie, s, md, i*2, val);
if (md+1<=ie) upd(is, ie, md+1, e, i*2+1, val);
}
void spread(int i) {
if (i<(1<<21)) lz[i*2]+=lz[i], lz[i*2+1]+=lz[i];
ar[i]+=lz[i]; lz[i]=0;
}
void upd(int is, int ie, ll val) { upd(is, ie, 0, N, 1, val); }
ll get(int t) { return get(t, 0, N, 1); }
}DS;
ll f(ll a, ll b) { return (a-b)*(a<b?S:T); }
int main() {
scanf("%d %d %lld %lld", &N, &Q, &S, &T);
for (int i=0; i<=N; i++) scanf("%lld", &A[i]);
for (int i=1; i<=N; i++) now+=f(A[i-1], A[i]);
DS.init();
for (int i=0; i<Q; i++) {
scanf("%d %d %lld", &L, &R, &X);
now-=f(DS.get(L-1), DS.get(L));
if (R!=N) now-=f(DS.get(R), DS.get(R+1));
DS.upd(L, R, X);
now+=f(DS.get(L-1), DS.get(L));
if (R!=N) now+=f(DS.get(R), DS.get(R+1));
printf("%lld\n", now);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %lld %lld", &N, &Q, &S, &T);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:47:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=0; i<=N; i++) scanf("%lld", &A[i]);
~~~~~^~~~~~~~~~~~~~~
foehn_phenomena.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %lld", &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... |