# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
880146 |
2023-11-28T20:51:25 Z |
rockstar |
Snowball (JOI21_ho_t2) |
C++17 |
|
2058 ms |
14000 KB |
//#pragma GCC optimize("O3,unroll-loops,inline")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(a) a.begin(), a.end()
bool check_right(int i, int len, vector<int>& mn, vector<int>& mx, int dist_to_next) {
int q = mx.size() - 1;
int l = -1, r = q;
while (r - l > 1) {
int mid = (l + r) / 2;
if (mx[mid] >= len)
r = mid;
else
l = mid;
}
return mx[r] >= len && dist_to_next + mn[r] - len >= 0;
}
bool check_left(int i, int len, vector<int>& mn, vector<int>& mx, int dist_to_next) {
int q = mx.size() - 1;
int l = -1, r = q;
while (r - l > 1) {
int mid = (l + r) / 2;
if (-mn[mid] >= len)
r = mid;
else
l = mid;
}
return -mn[r] >= len && dist_to_next - mx[r] - len >= 0;
}
void solve() {
int n, q;
cin >> n >> q;
vector<int> x(n);
for (int& i : x)
cin >> i;
vector<int> ans(n, 0), mn(q + 1, 0), mx(q + 1, 0);
int a = 0;
for (int i = 0; i < q; ++i) {
int w;
cin >> w;
a += w;
mn[i + 1] = min(mn[i], a);
mx[i + 1] = max(mx[i], a);
}
for (int i = 0; i < n; ++i) {
int l = 0, r = 1e18;
while (r - l > 1) {
int mid = r / 2 + l / 2 + (r % 2 + l % 2) / 2;
if (check_right(i, mid, mn, mx, (i != n - 1 ? x[i + 1] - x[i] : 1e18)))
l = mid;
else
r = mid;
}
ans[i] += l;
l = 0, r = 1e18;
while (r - l > 1) {
int mid = r / 2 + l / 2 + (r % 2 + l % 2) / 2;
if (check_left(i, mid, mn, mx, (i != 0 ? x[i] - x[i - 1] : 1e18)))
l = mid;
else
r = mid;
}
ans[i] += l;
}
for (int i : ans)
cout << i << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
11 ms |
348 KB |
Output is correct |
5 |
Correct |
11 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
364 KB |
Output is correct |
7 |
Correct |
10 ms |
348 KB |
Output is correct |
8 |
Correct |
11 ms |
552 KB |
Output is correct |
9 |
Correct |
11 ms |
348 KB |
Output is correct |
10 |
Correct |
10 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
552 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
12 ms |
564 KB |
Output is correct |
16 |
Correct |
11 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
500 KB |
Output is correct |
19 |
Correct |
9 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
11 ms |
348 KB |
Output is correct |
5 |
Correct |
11 ms |
348 KB |
Output is correct |
6 |
Correct |
11 ms |
364 KB |
Output is correct |
7 |
Correct |
10 ms |
348 KB |
Output is correct |
8 |
Correct |
11 ms |
552 KB |
Output is correct |
9 |
Correct |
11 ms |
348 KB |
Output is correct |
10 |
Correct |
10 ms |
348 KB |
Output is correct |
11 |
Correct |
11 ms |
552 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
12 ms |
564 KB |
Output is correct |
16 |
Correct |
11 ms |
348 KB |
Output is correct |
17 |
Correct |
11 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
500 KB |
Output is correct |
19 |
Correct |
9 ms |
468 KB |
Output is correct |
20 |
Correct |
20 ms |
5724 KB |
Output is correct |
21 |
Correct |
18 ms |
5528 KB |
Output is correct |
22 |
Correct |
23 ms |
5212 KB |
Output is correct |
23 |
Correct |
36 ms |
5204 KB |
Output is correct |
24 |
Correct |
224 ms |
5512 KB |
Output is correct |
25 |
Correct |
1987 ms |
11996 KB |
Output is correct |
26 |
Correct |
2058 ms |
11924 KB |
Output is correct |
27 |
Correct |
1998 ms |
11516 KB |
Output is correct |
28 |
Correct |
2021 ms |
11688 KB |
Output is correct |
29 |
Correct |
1965 ms |
11348 KB |
Output is correct |
30 |
Correct |
1856 ms |
10648 KB |
Output is correct |
31 |
Correct |
1694 ms |
9960 KB |
Output is correct |
32 |
Correct |
1669 ms |
10312 KB |
Output is correct |
33 |
Correct |
153 ms |
1620 KB |
Output is correct |
34 |
Correct |
1986 ms |
12328 KB |
Output is correct |
35 |
Correct |
2009 ms |
11684 KB |
Output is correct |
36 |
Correct |
2012 ms |
11976 KB |
Output is correct |
37 |
Correct |
2013 ms |
11676 KB |
Output is correct |
38 |
Correct |
1988 ms |
11520 KB |
Output is correct |
39 |
Correct |
1971 ms |
11716 KB |
Output is correct |
40 |
Correct |
1868 ms |
11716 KB |
Output is correct |
41 |
Correct |
19 ms |
6236 KB |
Output is correct |
42 |
Correct |
1634 ms |
10324 KB |
Output is correct |
43 |
Correct |
1830 ms |
13396 KB |
Output is correct |
44 |
Correct |
19 ms |
6012 KB |
Output is correct |
45 |
Correct |
1728 ms |
11600 KB |
Output is correct |
46 |
Correct |
1753 ms |
13516 KB |
Output is correct |
47 |
Correct |
1731 ms |
13744 KB |
Output is correct |
48 |
Correct |
1745 ms |
14000 KB |
Output is correct |