#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define fs first
#define sc second
int n, a[210000], ans[210000] = {0}, q;
vector<pii>pp;
signed main () {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1) pp.push_back({a[i] - a[i - 1], i - 1});
}
pp.push_back({LLONG_MAX - 2, 0}); pp.push_back({LLONG_MAX - 2, n});
sort(pp.begin(), pp.end());
int now = 0, l = 0, r = 0, x, stkf = 0;
while (q -- ) {
cin >> x;
now += x;
int oldl = l, oldr = r;
if (now < 0) l = max(l, -now);
if (now > 0) r = max(r, now);
while (stkf < pp.size() and l + r >= pp[stkf].fs) {
ans[pp[stkf].sc] += oldr, ans[pp[stkf].sc + 1] += oldl;
pp[stkf].fs -= oldl + oldr;
if (now < 0) ans[pp[stkf].sc + 1] += pp[stkf].fs;
else ans[pp[stkf].sc] += pp[stkf].fs;
stkf++;
}
}
while (stkf < pp.size()) {
ans[pp[stkf].sc] += r, ans[pp[stkf].sc + 1] += l;
stkf++;
}
for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
return 0;}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:28:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | while (stkf < pp.size() and l + r >= pp[stkf].fs) {
| ~~~~~^~~~~~~~~~~
Main.cpp:36:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | while (stkf < pp.size()) {
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2392 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
18 ms |
4420 KB |
Output is correct |
21 |
Correct |
17 ms |
4416 KB |
Output is correct |
22 |
Correct |
16 ms |
4188 KB |
Output is correct |
23 |
Correct |
16 ms |
4188 KB |
Output is correct |
24 |
Correct |
20 ms |
4892 KB |
Output is correct |
25 |
Correct |
61 ms |
12200 KB |
Output is correct |
26 |
Correct |
61 ms |
11968 KB |
Output is correct |
27 |
Correct |
62 ms |
12608 KB |
Output is correct |
28 |
Correct |
64 ms |
12224 KB |
Output is correct |
29 |
Correct |
71 ms |
11456 KB |
Output is correct |
30 |
Correct |
61 ms |
11200 KB |
Output is correct |
31 |
Correct |
56 ms |
10088 KB |
Output is correct |
32 |
Correct |
44 ms |
10436 KB |
Output is correct |
33 |
Correct |
7 ms |
3548 KB |
Output is correct |
34 |
Correct |
60 ms |
12432 KB |
Output is correct |
35 |
Correct |
66 ms |
12460 KB |
Output is correct |
36 |
Correct |
67 ms |
12104 KB |
Output is correct |
37 |
Correct |
63 ms |
12224 KB |
Output is correct |
38 |
Correct |
63 ms |
11964 KB |
Output is correct |
39 |
Correct |
62 ms |
11964 KB |
Output is correct |
40 |
Correct |
59 ms |
12988 KB |
Output is correct |
41 |
Correct |
19 ms |
5204 KB |
Output is correct |
42 |
Correct |
52 ms |
10432 KB |
Output is correct |
43 |
Correct |
66 ms |
13704 KB |
Output is correct |
44 |
Correct |
18 ms |
4948 KB |
Output is correct |
45 |
Correct |
58 ms |
12232 KB |
Output is correct |
46 |
Correct |
60 ms |
13868 KB |
Output is correct |
47 |
Correct |
57 ms |
14020 KB |
Output is correct |
48 |
Correct |
59 ms |
15016 KB |
Output is correct |