# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
371039 |
2021-02-25T16:10:47 Z |
valerikk |
Snowball (JOI21_ho_t2) |
C++17 |
|
1333 ms |
10020 KB |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector <ll> x(n);
for (int i = 0; i < n; i++) cin >> x[i];
vector <ll> w(q);
for (int i = 0; i < q; i++) cin >> w[i];
vector <ll> pref_mn(q + 1), pref_mx(q + 1);
pref_mn[0] = pref_mx[0] = 0;
ll sum = 0;
for (int i = 0; i < q; i++) {
sum += w[i];
pref_mn[i + 1] = min(pref_mn[i], sum);
pref_mx[i + 1] = max(pref_mx[i], sum);
}
auto get_mn = [&](ll val) {
int l = -1, r = q + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (pref_mn[m] <= val) r = m; else l = m;
}
return r;
};
auto get_mx = [&](ll val) {
int l = -1, r = q + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (pref_mx[m] >= val) r = m; else l = m;
}
return r;
};
ll mn = pref_mn[q], mx = pref_mx[q];
vector <ll> ans(n, 0);
ans[0] += -mn;
ans[n - 1] += mx;
for (int i = 0; i + 1 < n; i++) {
if (x[i] + mx < x[i + 1] + mn) {
ans[i] += mx;
ans[i + 1] += -mn;
continue;
}
ll l = x[i], r = x[i + 1] + 1;
while (r - l > 1) {
ll m = (l + r) / 2;
if (get_mx(m - x[i]) < get_mn(m - 1 - x[i + 1])) l = m; else r = m;
}
ans[i] += l - x[i];
ans[i + 1] += x[i + 1] - l;
}
for (int i = 0; i < n; i++) cout << ans[i] << '\n';
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
5 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
492 KB |
Output is correct |
8 |
Correct |
4 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
7 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
5 ms |
492 KB |
Output is correct |
7 |
Correct |
4 ms |
492 KB |
Output is correct |
8 |
Correct |
4 ms |
492 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
7 ms |
492 KB |
Output is correct |
17 |
Correct |
6 ms |
492 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
39 ms |
5100 KB |
Output is correct |
21 |
Correct |
31 ms |
4972 KB |
Output is correct |
22 |
Correct |
32 ms |
5100 KB |
Output is correct |
23 |
Correct |
43 ms |
5100 KB |
Output is correct |
24 |
Correct |
174 ms |
5612 KB |
Output is correct |
25 |
Correct |
1333 ms |
9764 KB |
Output is correct |
26 |
Correct |
1278 ms |
9860 KB |
Output is correct |
27 |
Correct |
1182 ms |
9636 KB |
Output is correct |
28 |
Correct |
1137 ms |
9708 KB |
Output is correct |
29 |
Correct |
1006 ms |
9452 KB |
Output is correct |
30 |
Correct |
588 ms |
9064 KB |
Output is correct |
31 |
Correct |
172 ms |
8684 KB |
Output is correct |
32 |
Correct |
97 ms |
8556 KB |
Output is correct |
33 |
Correct |
90 ms |
1260 KB |
Output is correct |
34 |
Correct |
1238 ms |
9836 KB |
Output is correct |
35 |
Correct |
1160 ms |
9636 KB |
Output is correct |
36 |
Correct |
1301 ms |
9836 KB |
Output is correct |
37 |
Correct |
1157 ms |
9580 KB |
Output is correct |
38 |
Correct |
1171 ms |
9636 KB |
Output is correct |
39 |
Correct |
1143 ms |
9708 KB |
Output is correct |
40 |
Correct |
927 ms |
9708 KB |
Output is correct |
41 |
Correct |
34 ms |
4972 KB |
Output is correct |
42 |
Correct |
64 ms |
8556 KB |
Output is correct |
43 |
Correct |
930 ms |
9804 KB |
Output is correct |
44 |
Correct |
35 ms |
4972 KB |
Output is correct |
45 |
Correct |
73 ms |
9580 KB |
Output is correct |
46 |
Correct |
986 ms |
9964 KB |
Output is correct |
47 |
Correct |
911 ms |
10020 KB |
Output is correct |
48 |
Correct |
944 ms |
9892 KB |
Output is correct |