제출 #1266291

#제출 시각아이디문제언어결과실행 시간메모리
1266291wedonttalkanymoreSnowball (JOI21_ho_t2)C++20
100 / 100
66 ms11336 KiB
#include <bits/stdc++.h> /* Strat code: - Thinking about how to solve the full problems: 15 min - Thinking about subtasks + code: 30 min - Stress: 10 - 15 min => Total need 2h15m */ using namespace std; using ll = long long; #define int long long #define pii pair<ll, ll> #define fi first #define se second const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 16; int n, q; int a[N]; int w[N]; int pos[N]; int pmin[N], pmax[N]; int ans[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); if (fopen(".inp", "r")) { freopen(".inp", "r", stdin); freopen(".out", "w", stdout); } cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= q; i++) cin >> w[i]; for (int i = 1; i <= q; i++) pos[i] = pos[i - 1] + w[i]; // for (int i = 1; i <= q; i++) cout << pos[i] << ' '; // cout << '\n'; for (int i = 1; i <= q; i++) { pmin[i] = min(pmin[i - 1], pos[i]); // ben trai pmax[i] = max(pmax[i - 1], pos[i]); // ben phai // cout << pmin[i] << ' ' << pmax[i] << '\n'; } // if (n == 1) { // cout << pmax[q] - pmin[q]; // return 0; // } ans[1] += abs(pmin[q]); ans[n] += pmax[q]; // cout << ans[1] << ' ' << ans[n] << '\n'; for (int i = 1; i < n; i++) { int dist = a[i + 1] - a[i]; // cout << i << ' ' << dist << '\n'; if (pmax[q] + abs(pmin[q]) <= dist) { ans[i] += pmax[q]; ans[i + 1] += abs(pmin[q]); } else { int l = 1, r = q, res = 0; while(l <= r) { int mid = (l + r) / 2; if (pmax[mid] + abs(pmin[mid]) > dist) { res = mid; r = mid - 1; } else l = mid + 1; } // cout << res << '\n'; if (pmax[res - 1] == pmax[res]) { ans[i] += pmax[res]; ans[i + 1] += dist - pmax[res]; } else { ans[i + 1] += abs(pmin[res]); ans[i] += dist - abs(pmin[res]); } } } for (int i = 1; i <= n; i++) cout << ans[i] << '\n'; return 0; }

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

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