제출 #159275

#제출 시각아이디문제언어결과실행 시간메모리
159275sochoFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
690 ms13176 KiB
#include "bits/stdc++.h" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, q, s, t; cin >> n >> q >> s >> t; long long alt[n+1]; for (long long i=0; i<n+1; i++) { cin >> alt[i]; } long long dlt[n]; for (long long i=0; i<n; i++) { dlt[i] = alt[i+1] - alt[i]; } s = - s; t = - t; long long init = 0; for (long long i=0; i<n; i++) { if (dlt[i] < 0) init += t * dlt[i]; else init += s * dlt[i]; } for (long long i=0; i<q; i++) { long long l, r, x; cin >> l >> r >> x; l--; r--; long long al = l; long long ar = r+1; long long old = dlt[al]; long long old_c = (old > 0 ? old * s : old * t); long long ne = dlt[al] + x; long long ne_c = (ne > 0 ? ne * s : ne * t); init -= old_c; init += ne_c; dlt[al] += x; if (ar != n) { long long old = dlt[ar]; long long old_c = (old > 0 ? old * s : old * t); long long ne = dlt[ar] - x; long long ne_c = (ne > 0 ? ne * s : ne * t); init -= old_c; init += ne_c; dlt[ar] -= x; } cout << init << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...