# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
880561 |
2023-11-29T16:22:08 Z |
OAleksa |
Snowball (JOI21_ho_t2) |
C++14 |
|
89 ms |
15740 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
int n, q;
cin >> n >> q;
vector<int> a(n), w(q);
for (int i = 0;i < n;i++)
cin >> a[i];
int l = 0, r = 0, s = 0;
vector<pair<int, int>> seg;
seg.push_back({0, 0});
for (int i = 0;i < q;i++)
cin >> w[i];
for (int i = 0;i < q;i++) {
s += w[i];
l = min(l, s);
r = max(r, s);
seg.push_back({abs(l), r});
}
vector<int> ans(n);
for (int i = 0;i < n - 1;i++) {
int l = 1, r = q, x = 0;
int d = a[i + 1] - a[i];
while (l <= r) {
int mid = (l + r) / 2;
int c = seg[mid].f + seg[mid].s;
if (c <= d) {
x = mid;
l = mid + 1;
}
else
r = mid - 1;
}
if (x == q) {
ans[i] += seg[x].s;
ans[i + 1] += seg[x].f;
}
else {
int u;
if (seg[x + 1].f != seg[x].f) {
u = min(seg[x + 1].f, d - seg[x].s);
ans[i + 1] += u;
ans[i] += d - u;
}
else {
u = min(seg[x + 1].s, d - seg[x].f);
ans[i] += u;
ans[i + 1] += d - u;
}
}
}
ans[0] += abs(l);
ans[n - 1] += r;
for (int i = 0;i < n;i++)
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
604 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 |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
604 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 |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
23 ms |
8276 KB |
Output is correct |
21 |
Correct |
21 ms |
8416 KB |
Output is correct |
22 |
Correct |
20 ms |
9416 KB |
Output is correct |
23 |
Correct |
20 ms |
9424 KB |
Output is correct |
24 |
Correct |
23 ms |
8660 KB |
Output is correct |
25 |
Correct |
74 ms |
14060 KB |
Output is correct |
26 |
Correct |
74 ms |
13808 KB |
Output is correct |
27 |
Correct |
73 ms |
13936 KB |
Output is correct |
28 |
Correct |
74 ms |
14064 KB |
Output is correct |
29 |
Correct |
78 ms |
12764 KB |
Output is correct |
30 |
Correct |
69 ms |
12288 KB |
Output is correct |
31 |
Correct |
49 ms |
11980 KB |
Output is correct |
32 |
Correct |
54 ms |
12128 KB |
Output is correct |
33 |
Correct |
7 ms |
1760 KB |
Output is correct |
34 |
Correct |
74 ms |
13808 KB |
Output is correct |
35 |
Correct |
72 ms |
13248 KB |
Output is correct |
36 |
Correct |
89 ms |
13504 KB |
Output is correct |
37 |
Correct |
73 ms |
13504 KB |
Output is correct |
38 |
Correct |
72 ms |
13040 KB |
Output is correct |
39 |
Correct |
73 ms |
13764 KB |
Output is correct |
40 |
Correct |
53 ms |
14280 KB |
Output is correct |
41 |
Correct |
22 ms |
10700 KB |
Output is correct |
42 |
Correct |
43 ms |
11768 KB |
Output is correct |
43 |
Correct |
55 ms |
15048 KB |
Output is correct |
44 |
Correct |
22 ms |
9424 KB |
Output is correct |
45 |
Correct |
50 ms |
13300 KB |
Output is correct |
46 |
Correct |
56 ms |
15740 KB |
Output is correct |
47 |
Correct |
63 ms |
15332 KB |
Output is correct |
48 |
Correct |
58 ms |
15732 KB |
Output is correct |