Submission #1118103

#TimeUsernameProblemLanguageResultExecution timeMemory
1118103vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
83 ms6628 KiB
#include <bits/stdc++.h> #define sts(v) stable_sort(v.BE, v.E) #define Rsts(v) stable_sort(v.rBE, v.rE) #define rev(v) reverse(v.BE, v.E) #define BE begin() #define rBE rbegin() #define E end() #define rE rend() #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define F first #define S second using namespace std; using ll = long long; struct ABI{ vector<ll> abi; ABI(int n){ abi.resize(n + 1); } void updt(int i, int val){ for(; i < (int)abi.size(); i += i & -i) abi[i] += val; } void range(int l, int r, int val){ updt(l, val); updt(r + 1, -val); } ll query(int i){ ll sum = 0; for(; i > 0; i -= i & -i) sum += abi[i]; return sum; } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, Q, S, T; cin >> n >> Q >> S >> T; vector<ll> v(n + 1); for(int i = 0; i <= n; i++) cin >> v[i]; bool type[n + 1]; int x = 0, y = 0, last[n + 1]; for(int i = 1; i <= n; i++){ last[i] = v[i] - v[i - 1]; type[i] = last[i] > 0; if(type[i]) x += last[i]; else y += abs(last[i]); } // cout << x << ' ' << y << '\n'; ABI abi(n); while(Q--){ int l, r, X; cin >> l >> r >> X; abi.range(l, r, X); ll i = v[l] + abi.query(l), _i = v[l - 1] + abi.query(l - 1); if(type[l]) x -= last[l]; else y -= abs(last[l]); last[l] = i - _i; type[l] = last[l] > 0; if(type[l]) x += last[l]; else y += abs(last[l]); if(r < n){ r++; i = v[r] + abi.query(r); _i = v[r - 1] + abi.query(r - 1); if(type[r]) x -= last[r]; else y -= abs(last[r]); last[r] = i - _i; type[r] = last[r] > 0; if(type[r]) x += last[r]; else y += abs(last[r]); } cout << y * T - x * S << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...