# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
715327 |
2023-03-26T13:07:55 Z |
Pring |
Snowball (JOI21_ho_t2) |
C++14 |
|
135 ms |
17044 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MXN = 200005;
int n, q, pos[MXN], w0[MXN], ans[MXN], bound;
vector<int> w;
vector<pii> vp;
void BUILD_W() {
int l = 0, r = 0, now = 0;
for (int i = 0; i < q; i++) {
now += w0[i];
if (r < now) {
r = now;
w.push_back(now);
} else if (now < l) {
l = now;
w.push_back(now);
}
}
q = w.size();
now = 0;
l = 0;
r = 0;
vp.push_back({0, 0});
for (int i = 0; i < q; i++) {
now = w[i];
l = min(now, l);
r = max(now, r);
vp.push_back({r, -l});
}
bound = vp.back().first + vp.back().second;
}
pii BSH(int x) {
if (x >= bound) return vp.back();
int l = 0, r = q + 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
(vp[mid].first + vp[mid].second > x ? r : l) = mid;
}
int d = x - vp[l].first - vp[l].second;
pii ans = vp[l];
if (vp[l].first != vp[l + 1].first) ans.first += d;
else ans.second += d;
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 0; i < n; i++) cin >> pos[i];
for (int i = 0; i < q; i++) cin >> w0[i];
BUILD_W();
// for (auto &i : w) cout << i << ' ';
// cout << endl;
// for (auto &i : vp) cout << i.first << ' ' << i.second << endl;
for (int i = 0; i + 1 < n; i++) {
pii p = BSH(pos[i + 1] - pos[i]);
ans[i] += p.first;
ans[i + 1] += p.second;
}
ans[0] += vp.back().second;
ans[n - 1] += vp.back().first;
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 |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
516 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
508 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
516 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
508 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
380 KB |
Output is correct |
20 |
Correct |
38 ms |
9924 KB |
Output is correct |
21 |
Correct |
34 ms |
9588 KB |
Output is correct |
22 |
Correct |
36 ms |
9468 KB |
Output is correct |
23 |
Correct |
32 ms |
9216 KB |
Output is correct |
24 |
Correct |
35 ms |
9460 KB |
Output is correct |
25 |
Correct |
103 ms |
15108 KB |
Output is correct |
26 |
Correct |
122 ms |
15080 KB |
Output is correct |
27 |
Correct |
135 ms |
14268 KB |
Output is correct |
28 |
Correct |
112 ms |
14148 KB |
Output is correct |
29 |
Correct |
93 ms |
11692 KB |
Output is correct |
30 |
Correct |
70 ms |
8976 KB |
Output is correct |
31 |
Correct |
74 ms |
8312 KB |
Output is correct |
32 |
Correct |
52 ms |
8464 KB |
Output is correct |
33 |
Correct |
14 ms |
1876 KB |
Output is correct |
34 |
Correct |
90 ms |
10868 KB |
Output is correct |
35 |
Correct |
89 ms |
10568 KB |
Output is correct |
36 |
Correct |
110 ms |
14728 KB |
Output is correct |
37 |
Correct |
109 ms |
13448 KB |
Output is correct |
38 |
Correct |
106 ms |
14276 KB |
Output is correct |
39 |
Correct |
99 ms |
14444 KB |
Output is correct |
40 |
Correct |
88 ms |
14436 KB |
Output is correct |
41 |
Correct |
37 ms |
10448 KB |
Output is correct |
42 |
Correct |
68 ms |
8460 KB |
Output is correct |
43 |
Correct |
100 ms |
16696 KB |
Output is correct |
44 |
Correct |
40 ms |
10256 KB |
Output is correct |
45 |
Correct |
67 ms |
14552 KB |
Output is correct |
46 |
Correct |
103 ms |
16832 KB |
Output is correct |
47 |
Correct |
83 ms |
13900 KB |
Output is correct |
48 |
Correct |
102 ms |
17044 KB |
Output is correct |