# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092723 | 2024-09-24T20:21:29 Z | I_am_Polish_Girl | Snowball (JOI21_ho_t2) | C++14 | 95 ms | 15316 KB |
#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimization ("unroll-loops") #include <vector> #include <algorithm> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <stack> #include <queue> #include <cmath> #include <random> #include <chrono> #include <iomanip> #include <iostream> #include <bitset> #define int long long using namespace std; int log_ = 3; int inf = 2000000000000000000; int mod = 5; int p = 505; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n , m; cin >> n >> m; vector <int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector <int> pr; pr.push_back(0); int p = 0; for (int i = 0; i < m; i++) { int x; cin >> x; p += x; pr.push_back(p); } int mx = 0; int mn = 0; vector <int> pr2; pr2.push_back(0); for (int i = 1; i <= m; i++) { if (mn > pr[i]) { if (i + 1 <= m) { if (pr[i] > pr[i + 1]) continue; } pr2.push_back(pr[i]); mn = pr[i]; } if (mx < pr[i]) { if (i + 1 <= m) { if (pr[i] < pr[i + 1]) continue; } pr2.push_back(pr[i]); mx = pr[i]; } } pr = pr2; vector <int> l(pr.size(), 0); vector <int> r(pr.size() , 0); for (int i = 1; i < pr.size(); i++) { l[i] = min(l[i - 1], pr[i]); r[i] = max(r[i - 1], pr[i]); } for (int i = 0; i < n; i++) { int pr_ = -inf; if (i > 0) pr_ = a[i - 1]; int lx = 0; int rx = pr.size(); while (rx - lx > 1) { int m = (lx + rx) / 2; if ((-l[m] + r[m]) <= (a[i] - pr_)) { lx = m; } else rx = m; } int ans = 0; ans += -l[lx]; if (lx + 1 < l.size()) { if (l[lx] > l[lx + 1]) { ans += (a[i] - pr_) - (-l[lx] + r[lx]); } } int next_ = inf; if (i + 1 < n) next_ = a[i + 1]; lx = 0; rx = pr.size(); while (rx - lx > 1) { int m = (lx + rx) / 2; if ((-l[m] + r[m]) <= (next_ - a[i])) { lx = m; } else rx = m; } ans += r[lx]; if (lx + 1 < r.size()) { if (r[lx] < r[lx + 1]) { ans += (next_ - a[i]) - (-l[lx] + r[lx]); } } cout << ans << "\n"; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 0 ms | 348 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 0 ms | 348 KB | Output is correct |
19 | Correct | 0 ms | 348 KB | Output is correct |
20 | Correct | 19 ms | 4480 KB | Output is correct |
21 | Correct | 20 ms | 4560 KB | Output is correct |
22 | Correct | 17 ms | 4460 KB | Output is correct |
23 | Correct | 17 ms | 4556 KB | Output is correct |
24 | Correct | 23 ms | 4820 KB | Output is correct |
25 | Correct | 85 ms | 7752 KB | Output is correct |
26 | Correct | 84 ms | 7624 KB | Output is correct |
27 | Correct | 95 ms | 7372 KB | Output is correct |
28 | Correct | 86 ms | 7368 KB | Output is correct |
29 | Correct | 80 ms | 6860 KB | Output is correct |
30 | Correct | 48 ms | 4300 KB | Output is correct |
31 | Correct | 38 ms | 4056 KB | Output is correct |
32 | Correct | 40 ms | 4028 KB | Output is correct |
33 | Correct | 8 ms | 992 KB | Output is correct |
34 | Correct | 61 ms | 5276 KB | Output is correct |
35 | Correct | 62 ms | 5332 KB | Output is correct |
36 | Correct | 86 ms | 7624 KB | Output is correct |
37 | Correct | 82 ms | 7368 KB | Output is correct |
38 | Correct | 83 ms | 7368 KB | Output is correct |
39 | Correct | 80 ms | 7368 KB | Output is correct |
40 | Correct | 65 ms | 7376 KB | Output is correct |
41 | Correct | 19 ms | 2552 KB | Output is correct |
42 | Correct | 33 ms | 7260 KB | Output is correct |
43 | Correct | 72 ms | 15176 KB | Output is correct |
44 | Correct | 20 ms | 9296 KB | Output is correct |
45 | Correct | 63 ms | 10984 KB | Output is correct |
46 | Correct | 69 ms | 15316 KB | Output is correct |
47 | Correct | 68 ms | 12744 KB | Output is correct |
48 | Correct | 48 ms | 10948 KB | Output is correct |