# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
878071 | 2023-11-24T04:20:18 Z | frostray8653 | Snowball (JOI21_ho_t2) | C++17 | 79 ms | 15488 KB |
// #pragma GCC optimize("Ofast,unroll-loops,O3") #include <bits/stdc++.h> #define int long long // #define ll long long #define pii pair<int,int> #define pll pair<ll,ll> #define IO ios::sync_with_stdio(0), cin.tie(0) #define FOR(i, a, b) for (int i = a, I = b; i <= b; i++) using namespace std; void dbg() {;} template<class T, class ...U> void dbg(T a, U ...b) {cout << a << " "; dbg(b...);} void ent() {cout << "\n";} const int mod = 998244353; // const int mod = 1e9 + 7; // const int INF = 2e9; const int INF = 9e17; /// ------- Initialization End ------- const int N = 200005; int a[N]; int dx[N]; int bestl[N], bestr[N]; int ans[N]; signed main() { IO; int n, m; cin >> n >> m; FOR(i, 1, n) cin >> a[i]; FOR(i, 1, m) cin >> dx[i]; int now = 0; int lft = 0, rgt = 0; FOR(i, 1, m) { now += dx[i]; lft = min(lft, now); rgt = max(rgt, now); bestl[i] = lft; bestr[i] = rgt; } ans[1] += abs(bestl[m]); FOR(i, 1, n) { if (i == n) { ans[i] += abs(bestr[m]); } else { int dif = a[i + 1] - a[i]; int l = 0, r = m + 1; while (l + 1 < r) { int mid = (l + r) >> 1; if (bestr[mid] - bestl[mid] >= dif) r = mid; else l = mid; } int id = l; int len = bestr[id] - bestl[id]; ans[i + 0] += abs(bestr[id]); ans[i + 1] += abs(bestl[id]); if (id < m) { if (bestr[id + 1] > bestr[id]) { ans[i + 0] += dif - len; } else { ans[i + 1] += dif - len; } } } } FOR(i, 1, n) cout << ans[i] << "\n"; return 0; } /* 4 3 -2 3 5 8 2 -4 7 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6624 KB | Output is correct |
8 | Correct | 1 ms | 6644 KB | Output is correct |
9 | Correct | 2 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 2 ms | 6488 KB | Output is correct |
16 | Correct | 2 ms | 6492 KB | Output is correct |
17 | Correct | 1 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 6492 KB | Output is correct |
2 | Correct | 1 ms | 6492 KB | Output is correct |
3 | Correct | 1 ms | 6492 KB | Output is correct |
4 | Correct | 1 ms | 6492 KB | Output is correct |
5 | Correct | 2 ms | 6492 KB | Output is correct |
6 | Correct | 1 ms | 6492 KB | Output is correct |
7 | Correct | 1 ms | 6624 KB | Output is correct |
8 | Correct | 1 ms | 6644 KB | Output is correct |
9 | Correct | 2 ms | 6492 KB | Output is correct |
10 | Correct | 1 ms | 6492 KB | Output is correct |
11 | Correct | 1 ms | 6492 KB | Output is correct |
12 | Correct | 1 ms | 6492 KB | Output is correct |
13 | Correct | 1 ms | 6492 KB | Output is correct |
14 | Correct | 1 ms | 6492 KB | Output is correct |
15 | Correct | 2 ms | 6488 KB | Output is correct |
16 | Correct | 2 ms | 6492 KB | Output is correct |
17 | Correct | 1 ms | 6492 KB | Output is correct |
18 | Correct | 1 ms | 6492 KB | Output is correct |
19 | Correct | 1 ms | 6492 KB | Output is correct |
20 | Correct | 18 ms | 8516 KB | Output is correct |
21 | Correct | 18 ms | 8380 KB | Output is correct |
22 | Correct | 19 ms | 8276 KB | Output is correct |
23 | Correct | 16 ms | 8028 KB | Output is correct |
24 | Correct | 20 ms | 8540 KB | Output is correct |
25 | Correct | 73 ms | 13468 KB | Output is correct |
26 | Correct | 75 ms | 13704 KB | Output is correct |
27 | Correct | 72 ms | 13136 KB | Output is correct |
28 | Correct | 79 ms | 13232 KB | Output is correct |
29 | Correct | 70 ms | 12600 KB | Output is correct |
30 | Correct | 73 ms | 12420 KB | Output is correct |
31 | Correct | 46 ms | 11600 KB | Output is correct |
32 | Correct | 41 ms | 11744 KB | Output is correct |
33 | Correct | 7 ms | 7260 KB | Output is correct |
34 | Correct | 74 ms | 13796 KB | Output is correct |
35 | Correct | 72 ms | 13232 KB | Output is correct |
36 | Correct | 77 ms | 13508 KB | Output is correct |
37 | Correct | 72 ms | 13300 KB | Output is correct |
38 | Correct | 76 ms | 13088 KB | Output is correct |
39 | Correct | 69 ms | 13140 KB | Output is correct |
40 | Correct | 53 ms | 13208 KB | Output is correct |
41 | Correct | 19 ms | 9272 KB | Output is correct |
42 | Correct | 42 ms | 11652 KB | Output is correct |
43 | Correct | 51 ms | 14928 KB | Output is correct |
44 | Correct | 19 ms | 9040 KB | Output is correct |
45 | Correct | 47 ms | 13136 KB | Output is correct |
46 | Correct | 52 ms | 15184 KB | Output is correct |
47 | Correct | 61 ms | 15236 KB | Output is correct |
48 | Correct | 54 ms | 15488 KB | Output is correct |