제출 #568993

#제출 시각아이디문제언어결과실행 시간메모리
568993DJ035Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
316 ms17296 KiB
#include <bits/stdc++.h> #define MEM 200005 #define sanic ios_base::sync_with_stdio(0) #define MOD 1000000 #define x first #define y second using namespace std; typedef long long ll; typedef pair<ll, ll> pi; const ll INF = 1e13+7; ll t,n,m,x,y; ll tree[4*MEM], a[MEM], c[MEM]; ll init(ll pos, ll val, ll idx, ll s, ll e){ if(s>idx || idx>e) return tree[pos]; if(s==e) return tree[pos] = val; ll mid = (s+e)/2; return tree[pos] = init(pos*2, val, idx, s, mid)+init(pos*2+1, val, idx, mid+1, e); } ll query(ll nd, ll l, ll r, ll s, ll e){ if(l>e || s>r) return 0; if(l<=s && e<=r) return tree[nd]; ll mid = (s+e)/2; return query(nd*2, l, r, s, mid)+query(nd*2+1, l, r, mid+1, e); } int main() { sanic; cin.tie(0); cout.tie(0); cin >> n >> m >> x >> y; for(int i=0; i<=n; i++){ cin >> a[i]; if(i) c[i] = a[i-1]-a[i]; } for(int i=1; i<=n; i++) init(1, c[i]*(c[i]>0 ? y:x), i, 1, n); while(m--){ ll q1,q2,q3; cin >> q1 >> q2 >> q3; c[q1] -= q3; c[q2+1] += q3; init(1, c[q1]*(c[q1]>0 ? y:x), q1, 1, n); init(1, c[q2+1]*(c[q2+1]>0 ? y:x), q2+1, 1, n); cout << query(1, 1, n, 1, n) <<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...