이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define tobit(n) bitset<20>(n) //выводит 20 элементов в битовую систему
#define all(v) (v).begin(), (v).end()
#define rtt(v, k) rotate(v.begin(), v.begin() + k, v.end()); //move k elements back
signed main(){
int N, Q, S, T, result = 0; cin >> N >> Q >> S >> T;
S = S * (-1); T = T * (-1);
vector<int> v(N + 1), answer(N);
for(int i = 0; i < N + 1; i++) cin >> v[i];
for(int i = 0; i < N; i++){
answer[i] = v[i + 1] - v[i];
if(answer[i] > 0) result += S * answer[i];
else result += T*answer[i];
}
for(int i = 0; i < Q; i++){
int L, R, X; cin >> L >> R >> X;
if(answer[L - 1] > 0) result -= S * answer[L - 1];
else result -= T * answer[L - 1];
if(R < N){
if(answer[R] > 0) result -= S * answer[R];
else result -= T * answer[R];
} answer[L - 1] += X;
if(R < N) answer[R] -= X;
if(answer[L - 1] > 0) result += S * answer[L - 1];
else result += T * answer[L - 1];
if(R < N){
if(answer[R] > 0) result += S * answer[R];
else result += T * answer[R];
} cout << result << "\n";
}
}
// NEED TO FAST CIN && COUT //
const int fastIO = [](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
return 0;
}();
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |