# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
415916 |
2021-06-01T17:23:18 Z |
meatrow |
Snowball (JOI21_ho_t2) |
C++17 |
|
1142 ms |
13716 KB |
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;
ll binpow(ll a, ll p, int mod = MOD) {
ll res = 1;
while (p) {
if (p & 1) {
(res *= a) %= mod;
}
p >>= 1;
(a *= a) %= mod;
}
return res;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
void solve() {
int n, q;
cin >> n >> q;
vector<ll> x(n + 2);
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
x[0] = -1e18;
x[n + 1] = 1e18;
vector<ll> shift(q + 1);
vector<ll> shiftR(q + 1);
vector<ll> shiftL(q + 1);
for (int i = 1; i <= q; i++) {
ll w;
cin >> w;
shift[i] = shift[i - 1] + w;
shiftR[i] = max(shift[i], shiftR[i - 1]);
shiftL[i] = max(-shift[i], shiftL[i - 1]);
}
for (int i = 1; i <= n; i++) {
ll ans = 0;
{
ll l = 0, r = min(x[i + 1] - x[i], shiftR.back()) + 1;
while (r - l > 1) {
ll mid = (l + r) / 2;
int pos = lower_bound(shiftR.begin(), shiftR.end(), mid) - shiftR.begin();
if (x[i + 1] - x[i] - shiftL[pos] < mid) {
r = mid;
} else {
l = mid;
}
}
ans += l;
}
{
ll l = 0, r = min(x[i] - x[i - 1], shiftL.back()) + 1;
while (r - l > 1) {
ll mid = (l + r) / 2;
int pos = lower_bound(shiftL.begin(), shiftL.end(), mid) - shiftL.begin();
if (x[i] - x[i - 1] - shiftR[pos] < mid) {
r = mid;
} else {
l = mid;
}
}
ans += l;
}
cout << ans << '\n';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
for (int tc = 1; tc <= T; tc++) {
// cout << "Case #" << tc << ": ";
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
7 ms |
368 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
7 ms |
368 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
6 |
Correct |
5 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
3 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
7 ms |
332 KB |
Output is correct |
16 |
Correct |
7 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
36 ms |
7100 KB |
Output is correct |
21 |
Correct |
37 ms |
6912 KB |
Output is correct |
22 |
Correct |
37 ms |
6724 KB |
Output is correct |
23 |
Correct |
47 ms |
6560 KB |
Output is correct |
24 |
Correct |
123 ms |
6964 KB |
Output is correct |
25 |
Correct |
984 ms |
11932 KB |
Output is correct |
26 |
Correct |
967 ms |
11788 KB |
Output is correct |
27 |
Correct |
956 ms |
11500 KB |
Output is correct |
28 |
Correct |
927 ms |
11580 KB |
Output is correct |
29 |
Correct |
838 ms |
11056 KB |
Output is correct |
30 |
Correct |
444 ms |
10416 KB |
Output is correct |
31 |
Correct |
121 ms |
9876 KB |
Output is correct |
32 |
Correct |
73 ms |
10052 KB |
Output is correct |
33 |
Correct |
74 ms |
1448 KB |
Output is correct |
34 |
Correct |
1142 ms |
12200 KB |
Output is correct |
35 |
Correct |
930 ms |
11604 KB |
Output is correct |
36 |
Correct |
981 ms |
11872 KB |
Output is correct |
37 |
Correct |
920 ms |
11600 KB |
Output is correct |
38 |
Correct |
956 ms |
11460 KB |
Output is correct |
39 |
Correct |
955 ms |
11576 KB |
Output is correct |
40 |
Correct |
437 ms |
11632 KB |
Output is correct |
41 |
Correct |
48 ms |
7684 KB |
Output is correct |
42 |
Correct |
84 ms |
10100 KB |
Output is correct |
43 |
Correct |
276 ms |
13420 KB |
Output is correct |
44 |
Correct |
52 ms |
7620 KB |
Output is correct |
45 |
Correct |
586 ms |
11588 KB |
Output is correct |
46 |
Correct |
358 ms |
13448 KB |
Output is correct |
47 |
Correct |
443 ms |
13708 KB |
Output is correct |
48 |
Correct |
178 ms |
13716 KB |
Output is correct |