이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
int q, n, s, tt, a[ 200001 ], t[ 800001 ];
void upd( int v, int tl, int tr, int l, int r ) {
if ( tl > r || tr < l )
return;
if ( tl >= l && tr <= r ) {
t[ v ] += num;
return;
}
int mid = ( tl + tr ) / 2;
upd( v + v, tl, mid, l, r );
upd( v + v + 1, mid + 1, tr, l, r );
}
void build( int v, int tl, int tr ) {
if ( tl == tr ) {
t[ v ] = a[ tl ];
return;
}
int mid = ( tl + tr ) / 2;
build( v + v, tl, mid );
build( v + v + 1, mid + 1, tr );
}
void gett( int v, int tl, int tr, int pos ) {
if ( tl > pos || tr < pos )
return;
if ( tl == tr ) {
a[ tl ] = t[ v ];
return;
}
if ( t[ v ] != 0 ) {
t[ v + v ] += t[ v ];
t[ v + v + 1 ] += t[ v ];
t[ v ] = 0;
}
int mid = ( tl + tr ) / 2;
gett( v + v, tl, mid, pos );
gett( v + v + 1, mid + 1, tr, pos );
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
cin >> q;
cin >> s >> tt;
cin >> a[ 0 ];
for ( int i = 1; i <= n; i ++ )
cin >> a[ i ];
for ( int i = 1; i <= n; i ++ ) {
if ( a[ i ] > a[ i - 1 ] ) {
sum -= s * ( a[ i ] - a[ i - 1 ] );
}
else
sum += tt * ( a[ i - 1 ] - a[ i ] );
}
build( 1, 1, n );
int l, r;
while ( q -- ) {
cin >> l >> r >> num;
gett( 1, 1, n, l );
gett( 1, 1, n, r );
upd( 1, 1, n, l, r );
num = 0;
if ( a[ l ] > a[ l - 1 ] )
sum += s * ( a[ l ] - a[ l - 1 ] );
else
sum -= tt * ( a[ l - 1 ] - a[ l] );
if ( r < n ) {
if ( a[ r + 1 ] > a[ r ] )
sum += s * ( a[ r + 1 ] - a[ r ] );
else
sum -= tt * ( a[ r ] - a[ r + 1 ] );
}
gett( 1, 1, n, l );
gett( 1, 1, n, r );
if ( a[ l ] > a[ l - 1 ] )
sum -= s * ( a[ l ] - a[ l - 1 ] );
else
sum += tt * ( a[ l - 1 ] - a[ l ] );
if ( r < n ) {
if ( a[ r + 1 ] > a[ r ] )
sum -= s * ( a[ r + 1 ] - a[ r ] );
else
sum += tt * ( a[ r ] - a[ r + 1 ] );
}
cout << sum << "\n";
}
}
/*
*/
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
85 | 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... |