제출 #155232

#제출 시각아이디문제언어결과실행 시간메모리
155232kungfulonFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
152 ms13196 KiB
#include <bits/stdc++.h> #define rep(i,a,b) for(int i = (a);i <= (b);i++) #define repd(i,a,b) for(int i = (a);i >= (b);i--) #define PB push_back #define F first #define S second #define Task "" using namespace std; template <class T> T read(T &a){a = 0;char c = cin.get();bool nega = 0;while(!isdigit(c) && c != '-') c = cin.get();if(c == '-') nega = 1,c = cin.get();a = c - 48;c = cin.get();while(isdigit(c)) a = a * 10 + c - 48,c = cin.get();if(nega) a = -a;return a;} template <class T> void writep(T a){if(a > 9) writep(a / 10);cout.put(a % 10 + 48);} template <class T> void write(T a){if(a < 0) cout.put('-'),a = -a;writep(a);cout.put(' ');} template <class T> void writeln(T a){write(a);cout.put('\n');} const int N = 200012; int n,q,s,t; long long a[N],b[N]; long long ans = 0; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); // ifstream cin (Task".inp"); // ofstream cout (Task".out"); cin >> n >> q >> s >> t; rep(i,0,n) cin >> a[i]; rep(i,1,n) b[i] = a[i-1] - a[i]; rep(i,1,n) ans += 1ll*b[i] * (b[i] < 0 ? s : t); while(q--) { int l,r,val; cin >> l >> r >> val; ans -= 1ll*b[l] * (b[l] < 0 ? s : t); if(r+1 <= n)ans -= 1ll*b[r+1] * (b[r+1] < 0 ? s : t); b[l] -= val; b[r+1] += val; ans += 1ll*b[l] * (b[l] < 0 ? s : t); if(r+1 <= n)ans += 1ll*b[r+1] * (b[r+1] < 0 ? s : t); cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...