제출 #361985

#제출 시각아이디문제언어결과실행 시간메모리
361985OlerinskiyFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
173 ms8812 KiB
#include <iostream> #include <iomanip> #include <algorithm> #include <bitset> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <cmath> #include <time.h> #include <random> #include <string> #include <cassert> #include <vector> #include <ostream> #include <istream> #include <stack> #include <deque> #include <queue> #include <functional> #include <chrono> #include <stack> #include <limits> using namespace std; #define int long long #define pb push_back #define all(a) (a).begin(), (a).end() #define pii pair<int, int> #define ld long double istream& operator>> (istream& in, pii& b) { in >> b.first >> b.second; return in; } ostream& operator<< (ostream& out, const pii& b) { out << "{" << b.first << ", " << b.second << "}"; return out; } template<typename T> ostream& operator<< (ostream& out, const vector<T>& a) { for (auto k : a) out << k << " "; return out; } template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;} template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;} #ifdef LOCAL #define dbg(x) cout << #x << " : " << (x) << endl; const long long INF = 1e18; // const long long mod = 2600000069; // const long long p = 10; #else #define dbg(x) 57 const long long INF = 1e18; // const long long mod = 2600000069; // const long long p = 179; #endif const ld PI = 4 * atan(1); #define time clock() / (double) CLOCKS_PER_SEC // #pragma GCC optimize("Ofast,no-stack-protector") // #pragma GCC target("sse,sse2,sse3,sse3,sse4") // #pragma GCC optimize("unroll-loops") // #pragma GCC optimize("fast-math") // #pragma GCC target("avx2") mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count()); const int N = 2e5 + 10; int n, q, s, t; int a[N]; int f[N]; void add(int pos, int x) { pos++; for (; pos <= n; pos += pos & -pos) { f[pos] += x; } } int ask(int l) { l++; int ans = 0; for (; l > 0; l -= l & -l) { ans += f[l]; } return ans; } int ask(int l, int r) { return ask(r) - ask(l - 1); } int d(int a, int b) { if (a < b) return (a - b) * s; return (a - b) * t; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q >> s >> t; n++; for (int i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; for (int i = 1; i < n; i++) { ans += d(a[i - 1], a[i]); add(i, a[i] - a[i - 1]); } while (q--) { int l, r, x; cin >> l >> r >> x; if (l > 0) { ans -= d(ask(l - 1), ask(l)); } if (r < n - 1) { ans -= d(ask(r), ask(r + 1)); } add(l, x); add(r + 1, -x); if (l > 0) { ans += d(ask(l - 1), ask(l)); } if (r < n - 1) { ans += d(ask(r), ask(r + 1)); } cout << ans << "\n"; } } /* 3 5 1 2 0 4 1 8 1 2 2 1 1 -2 2 3 5 1 2 -1 1 3 5 2 2 5 5 0 6 -1 1 1 4 1 2 8 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...