제출 #1291643

#제출 시각아이디문제언어결과실행 시간메모리
1291643anhphantFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
512 ms16424 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N, Q, S, T, A[200007]; namespace ST { ll ST[800007], lazy[800007]; void push_down(ll id) { ST[id * 2] += lazy[id]; ST[id * 2 + 1] += lazy[id]; lazy[id * 2] += lazy[id]; lazy[id * 2 + 1] += lazy[id]; lazy[id] = 0; } void update(ll id, ll l, ll r, ll L, ll R, ll x) { if (r < L || R < l) return; if (L <= l && r <= R) { ST[id] += x; lazy[id] += x; return; } ll mid = (l + r) / 2; push_down(id); update(id * 2, l, mid, L, R, x); update(id * 2 + 1, mid + 1, r, L, R, x); ST[id] = max(ST[id * 2], ST[id * 2 + 1]); } ll getans(ll id, ll l, ll r, ll L, ll R) { if (R == 0) return 0; if (r < L || R < l) return -1e18; if (L <= l && r <= R) return ST[id]; ll mid = (l + r) / 2; push_down(id); return max(getans(id * 2, l, mid, L, R), getans(id * 2 + 1, mid + 1, r, L, R)); } } ll temper; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } for(int i = 0; i <= 800000; ++i) ST::ST[i] = 0; cin >> N >> Q >> S >> T; cin >> A[0]; for(int i = 1; i <= N; ++i) { cin >> A[i]; temper += (A[i - 1] < A[i]? -S * (A[i] - A[i - 1]) : T * (A[i - 1] - A[i])); ST::update(1, 1, N, i, i, A[i]); } for(int i = 1; i <= Q; ++i) { ll l, r, x; cin >> l >> r >> x; ll x1, x2; x1 = ST::getans(1, 1, N, l - 1, l - 1); x2 = ST::getans(1, 1, N, l, l); temper -= (x1 < x2? -S * (x2 - x1) : T * (x1 - x2)); if (r != N) { x1 = ST::getans(1, 1, N, r, r); x2 = ST::getans(1, 1, N, r + 1, r + 1); temper -= (x1 < x2? -S * (x2 - x1) : T * (x1 - x2)); } ST::update(1, 1, N, l, r, x); x1 = ST::getans(1, 1, N, l - 1, l - 1); x2 = ST::getans(1, 1, N, l, l); temper += (x1 < x2? -S * (x2 - x1) : T * (x1 - x2)); //cerr << "i = " << x1 << " " << x2 << " " << -S * (x2 - x1) << " : " << i << " : " << temper << '\n'; if (r != N) { x1 = ST::getans(1, 1, N, r, r); x2 = ST::getans(1, 1, N, r + 1, r + 1); temper += (x1 < x2? -S * (x2 - x1) : T * (x1 - x2)); } cout << temper << '\n'; } }

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...