제출 #887269

#제출 시각아이디문제언어결과실행 시간메모리
887269hafoFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
120 ms14676 KiB
#include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define pb push_back #define pa pair<int, int> #define pall pair<ll, int> #define fi first #define se second #define TASK "test" #define Size(x) (int) x.size() #define all(x) x.begin(), x.end() using namespace std; template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;} const int MOD = 1e9 + 7; const int LOG = 20; const int maxn = 2e5 + 7; const ll oo = 1e18 + 69; int n, q, s, t, a[maxn], l, r, x, type[maxn]; struct BIT { ll bit[maxn]; void update(int x, ll val) { for(; x <= n; x += x&-x) bit[x] += val; } ll get(int x) { ll ans = 0; for(; x; x -= x&-x) ans += bit[x]; return ans; } } bit[2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen(TASK".inp", "r", stdin); //freopen(TASK".out", "w", stdout); cin>>n>>q>>s>>t; for(int i = 0; i <= n; i++) cin>>a[i]; for(int i = 1; i <= n; i++) { type[i] = (a[i - 1] - a[i] >= 0); bit[type[i]].update(i, a[i - 1] - a[i]); } while(q--) { cin>>l>>r>>x; ll val = bit[type[l]].get(l) - bit[type[l]].get(l - 1); bit[type[l]].update(l, -val); val -= x; type[l] = (val >= 0); bit[type[l]].update(l, val); if(r < n) { val = bit[type[r + 1]].get(r + 1) - bit[type[r + 1]].get(r); bit[type[r + 1]].update(r + 1, -val); val += x; type[r + 1] = (val >= 0); bit[type[r + 1]].update(r + 1, val); } cout<<bit[0].get(n) * s + bit[1].get(n) * t<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...