#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
const long long inf = 1e18;
int N, Q; cin >> N >> Q;
vector<long long> X = {-inf};
for (int i = 0; i < N; ++i) {
long long C; cin >> C;
X.push_back(C);
}
X.push_back(inf);
vector<long long> res(N + 2);
vector<pair<long long, int>> cands;
for (int i = 1; i <= N + 1; ++i) {
cands.push_back({X[i] - X[i - 1], i});
}
auto solve = [&](pair<long long, int> x, long long a, long long b, long long A, long long B) {
auto [len, id] = x;
if (A + B <= len) {
res[id - 1] += A;
res[id] += B;
} else {
assert(a + b <= len);
if (a != A) {
res[id] += B;
res[id - 1] += len - B;
} else {
res[id - 1] += A;
res[id] += len - A;
}
}
};
sort(cands.begin(), cands.end());
long long pf = 0, sf = 0, os = 0;
int j = 0;
while (Q--) {
long long x; cin >> x;
os += x;
auto opf = pf, osf = sf;
pf = max(pf, os);
sf = max(sf, -os);
while (j < cands.size() && cands[j].first <= pf + sf) {
solve(cands[j++], opf, osf, pf, sf);
}
}
while (j < cands.size()) {
solve(cands[j++], pf, sf, pf, sf);
}
for (int i = 1; i <= N; ++i) {
cout << res[i] << "\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:53:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | while (j < cands.size() && cands[j].first <= pf + sf) {
| ~~^~~~~~~~~~~~~~
Main.cpp:57:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | while (j < cands.size()) {
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
524 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 KB |
Output is correct |
14 |
Correct |
0 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 |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
524 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 KB |
Output is correct |
14 |
Correct |
0 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 |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
18 ms |
2488 KB |
Output is correct |
21 |
Correct |
15 ms |
2396 KB |
Output is correct |
22 |
Correct |
14 ms |
2116 KB |
Output is correct |
23 |
Correct |
14 ms |
2140 KB |
Output is correct |
24 |
Correct |
18 ms |
2976 KB |
Output is correct |
25 |
Correct |
62 ms |
12104 KB |
Output is correct |
26 |
Correct |
57 ms |
12104 KB |
Output is correct |
27 |
Correct |
60 ms |
11696 KB |
Output is correct |
28 |
Correct |
58 ms |
12100 KB |
Output is correct |
29 |
Correct |
62 ms |
11188 KB |
Output is correct |
30 |
Correct |
62 ms |
10820 KB |
Output is correct |
31 |
Correct |
54 ms |
10304 KB |
Output is correct |
32 |
Correct |
40 ms |
10576 KB |
Output is correct |
33 |
Correct |
6 ms |
1624 KB |
Output is correct |
34 |
Correct |
60 ms |
12344 KB |
Output is correct |
35 |
Correct |
55 ms |
11740 KB |
Output is correct |
36 |
Correct |
58 ms |
11956 KB |
Output is correct |
37 |
Correct |
62 ms |
11844 KB |
Output is correct |
38 |
Correct |
59 ms |
11652 KB |
Output is correct |
39 |
Correct |
59 ms |
11836 KB |
Output is correct |
40 |
Correct |
58 ms |
11844 KB |
Output is correct |
41 |
Correct |
17 ms |
3124 KB |
Output is correct |
42 |
Correct |
50 ms |
10564 KB |
Output is correct |
43 |
Correct |
64 ms |
13636 KB |
Output is correct |
44 |
Correct |
17 ms |
2900 KB |
Output is correct |
45 |
Correct |
56 ms |
11792 KB |
Output is correct |
46 |
Correct |
53 ms |
13732 KB |
Output is correct |
47 |
Correct |
55 ms |
13844 KB |
Output is correct |
48 |
Correct |
55 ms |
14000 KB |
Output is correct |