Submission #102934

#TimeUsernameProblemLanguageResultExecution timeMemory
102934RockyBFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
314 ms13368 KiB
/// In The Name Of God #include <bits/stdc++.h> #define f first #define s second #define pb push_back #define pp pop_back #define mp make_pair #define sz(x) (int)x.size() #define sqr(x) ((x) * 1ll * (x)) #define all(x) x.begin(), x.end() #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, l, r) for (int i = (l); i >= (r); i--) #define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); #define nl '\n' #define ioi exit(0); typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int N = (int)5e5 + 7; const int inf = (int)1e9 + 7; const int mod = (int)1e9 + 7; const ll linf = (ll)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}; const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; using namespace std; int n, q, s, t; ll a[N]; struct tree { ll f[N]; void upd(int p, int x) { for (; p < N; p |= p + 1) f[p] += x; } ll get(int p) { ll res = 0; for (; p >= 0; p = (p & (p + 1)) - 1) res += f[p]; return res; } } f; ll ans; void upd(int p, int x) { if (p < 0 || p >= n) return; a[p] = f.get(p), a[p + 1] = f.get(p + 1); if (a[p] < a[p + 1]) ans -= (abs(a[p + 1] - a[p]) * s) * x; else ans += (abs(a[p] - a[p + 1]) * t) * x; } int main() { #ifdef IOI2018 freopen ("in.txt", "r", stdin); #endif Kazakhstan cin >> n >> q >> s >> t; rep(i, 0, n) { cin >> a[i]; f.upd(i + 1, -a[i]); f.upd(i, a[i]); } rep(i, 0, n - 1) { if (a[i] < a[i + 1]) ans -= abs(a[i + 1] - a[i]) * s; else ans += abs(a[i] - a[i + 1]) * t; } rep(i, 1, q) { int l, r, x; cin >> l >> r >> x; upd(l - 1, -1); upd(r, -1); f.upd(l, x); f.upd(r + 1, -x); upd(l - 1, 1); upd(r, 1); /* rep(j, l, r) a[j] += x; int ans = 0; rep(j, 0, n - 1) { if (a[j] < a[j + 1]) ans -= (a[j + 1] - a[j]) * s; else ans += (a[j] - a[j + 1]) * t; }*/ cout << ans << nl; } ioi }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...