이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<>>;
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
inline void init_io() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
}
template <typename T>
T reversed(T arr) {
reverse(begin(arr), end(arr));
return arr;
}
template <typename T>
vector<vector<T>> transposed(const vector<vector<T>>& arr) {
int n = sz(arr), m = sz(arr[0]);
vector ans(m, vector<T>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ans[j][i] = arr[i][j];
}
}
return ans;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
out << "[";
for (int i = 0; i < sz(arr); i++) {
if (i) {
out << ", ";
}
out << arr[i];
}
return out << "]";
}
inline vector<bool>::reference operator|=(vector<bool>::reference&& a, bool b) {
a = a | b;
return a;
}
void solve() {
int n, q;
long ws, wt;
cin >> n >> q >> ws >> wt;
vector<long> arr(n + 1);
for (auto& a : arr) {
cin >> a;
}
vector<long> arrd(n + 1);
for (int i = 0; i < n; ++i) {
arrd[i] = arr[i + 1] - arr[i];
}
long ans = 0;
auto weight = [&](int i) -> long {
if (i >= n) {
return 0;
}
long x = arrd[i];
if (x > 0) {
return -abs(x) * ws;
} else {
return abs(x) * wt;
}
};
for (int i = 0; i < n; ++i) {
ans += weight(i);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
l--;
ans -= weight(l);
ans -= weight(r);
arrd[l] += x;
arrd[r] -= x;
ans += weight(l);
ans += weight(r);
cout << ans << endl;
}
}
int main() {
init_io();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |