Submission #758011

#TimeUsernameProblemLanguageResultExecution timeMemory
758011otariusSnowball (JOI21_ho_t2)C++17
100 / 100
116 ms13376 KiB
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <cstring> #include <queue> #include <map> #include <cmath> #include <iomanip> using namespace std; #define ff first #define sc second #define pb push_back #define ll long long #define pll pair<ll, ll> #define pii pair <int, int> #define ull unsigned long long #define int long long // #define int unsigned long long const ll inf = 1e18 + 7; const ll weirdMod = 998244353; int rgt[200005], lft[200005]; void solve() { int n, k; cin >> n >> k; int arr[n + 5] = {}, wnd[k + 5] = {}; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= k; i++) { cin >> wnd[i]; wnd[i] += wnd[i - 1]; } vector<int> vec; for (int i = 1; i <= k; i++) { rgt[i] = max(rgt[i - 1], wnd[i]); lft[i] = max(lft[i - 1], -wnd[i]); } ll ans[n + 5] = {}; arr[0] = -inf; arr[n + 1] = inf; for (int i = 0; i <= n; i++) { if (rgt[k] + lft[k] <= arr[i + 1] - arr[i]) { ans[i] += rgt[k]; ans[i + 1] += lft[k]; continue; } int l = 1, r = k, m; while (l < r) { m = (l + r) / 2; if (rgt[m] + lft[m] > arr[i + 1] - arr[i]) r = m; else l = m + 1; } while (rgt[l - 1] + lft[l - 1] > arr[i + 1] - arr[i]) l--; if (lft[l] != lft[l - 1]) { ans[i] += rgt[l]; ans[i + 1] += arr[i + 1] - arr[i] - rgt[l]; } else {ans[i] += arr[i + 1] - arr[i] - lft[l]; ans[i + 1] += lft[l];} } for (int i = 1; i <= n; i++) cout << ans[i] << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); cout << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...