제출 #924891

#제출 시각아이디문제언어결과실행 시간메모리
924891niterFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
83 ms13140 KiB
#include <bits/stdc++.h> #define loop(i,a,b) for(int i = (a); i < (b); i ++) using namespace std; typedef long long ll; const int mxn = 200005; ll S, T; ll a[mxn], b[mxn]; ll cal(ll pre, ll nxt){ if(nxt > pre) return (-S) * abs(nxt - pre); else return T * abs(pre - nxt); } ll cal(ll det){ if(det > 0) return (-S) * abs(det); else return T * abs(det); } int main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("in.txt", "r", stdin); int n, q; cin >> n >> q; cin >> S >> T; // S: decrease (go up), T: increase (go down) loop(i,0,n+1) cin >> a[i]; ll now = 0; loop(i,1,n+1){ b[i] = cal(a[i-1], a[i]); now += b[i]; // cout << now << '\n'; } for(int i = n; i >= 1; i--){ a[i] = a[i] - a[i-1]; } // loop(i,0,n+1){ // cout << a[i] << ' '; // } cout << '\n'; loop(queries,0,q){ int l, r; ll val; cin >> l >> r >> val; ll nxt_a = a[l] + val; ll nxt_b = cal(nxt_a); now -= b[l]; b[l] = nxt_b; now += b[l]; a[l] = nxt_a; if(r == n){ cout << now << '\n'; continue; } nxt_a = a[r+1] - val; nxt_b = cal(nxt_a); now -= b[r+1]; b[r+1] = nxt_b; now += b[r+1]; a[r+1] = nxt_a; cout << now << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...