Submission #669703

#TimeUsernameProblemLanguageResultExecution timeMemory
669703soondro2266Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
603 ms42956 KiB
#include<bits/stdc++.h> using namespace std; #define int long long struct seg{ int l, r, val, s, t, mid; seg* ch[2] = {}; seg(int _l, int _r, int _s, int _t, vector<int> &arr):l(_l),r(_r),s(_s),t(_t){ if(l == r-1){ val = arr[l]; return; } mid = (l+r)/2; ch[0] = new seg(l, mid, s, t, arr); ch[1] = new seg(mid, r, s, t, arr); pull(); } int get(){ if(l == r-1){ if(val < 0){ return val*(0-t); } else{ return val*(0-s); } } return val; } void pull(){ val = ch[0]->get() + ch[1]->get(); } void add(int idx, int k){ if(l == r-1){ val += k; return; } if(idx < mid){ ch[0]->add(idx, k); } else{ ch[1]->add(idx, k); } pull(); } int query(int a, int b){ if(a <= l && r <= b){ return get(); } int ans = 0; if(a < mid){ ans += ch[0]->get(); } if(b > mid){ ans += ch[1]->get(); } return ans; } }; signed main(){ cin.tie(0)->sync_with_stdio(0); int n, q, s, t; cin >> n >> q >> s >> t; int sum; cin >> sum; vector<int> arr; for(int i = 0, tmp; i < n; i++){ cin >> tmp; arr.push_back(tmp - sum); sum = tmp; } seg tr(0,n,s,t,arr); for(int i = 0, a, b, c; i < q; i++){ cin >> a >> b >> c; a--; tr.add(a, c); if(b < n){ tr.add(b, (0-c)); } cout << tr.query(0, n) << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...