제출 #1081154

#제출 시각아이디문제언어결과실행 시간메모리
1081154skittles1412Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
78 ms7364 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...