# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092722 | 2024-09-24T20:19:16 Z | I_am_Polish_Girl | Snowball (JOI21_ho_t2) | C++14 | 91 ms | 11448 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 = 200000000000000; 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 | 348 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 | 544 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 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 | 1 ms | 508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 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 | 544 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 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 | 1 ms | 508 KB | Output is correct |
20 | Correct | 19 ms | 6600 KB | Output is correct |
21 | Correct | 18 ms | 6596 KB | Output is correct |
22 | Correct | 17 ms | 6356 KB | Output is correct |
23 | Correct | 17 ms | 6040 KB | Output is correct |
24 | Correct | 28 ms | 6352 KB | Output is correct |
25 | Correct | 90 ms | 11448 KB | Output is correct |
26 | Correct | 91 ms | 11208 KB | Output is correct |
27 | Correct | 86 ms | 10992 KB | Output is correct |
28 | Correct | 86 ms | 11208 KB | Output is correct |
29 | Correct | 79 ms | 10332 KB | Output is correct |
30 | Correct | 49 ms | 7672 KB | Output is correct |
31 | Correct | 40 ms | 7132 KB | Output is correct |
32 | Correct | 35 ms | 7116 KB | Output is correct |
33 | Correct | 7 ms | 1500 KB | Output is correct |
34 | Correct | 65 ms | 9404 KB | Output is correct |
35 | Correct | 63 ms | 8952 KB | Output is correct |
36 | Correct | 85 ms | 11244 KB | Output is correct |
37 | Correct | 86 ms | 10952 KB | Output is correct |
38 | Correct | 84 ms | 10956 KB | Output is correct |
39 | Correct | 80 ms | 11208 KB | Output is correct |
40 | Correct | 69 ms | 11212 KB | Output is correct |
41 | Incorrect | 20 ms | 4688 KB | Output isn't correct |
42 | Halted | 0 ms | 0 KB | - |