#include <iostream>
#include <vector>
using namespace std;
const long long INF = 2e18;
struct segTree{
int l, r, mid;
long long val = 0, lz = 0;
segTree *lc, *rc;
segTree(vector<long long> &a, int _l, int _r): l(_l), r(_r){
mid = (l + r) / 2;
if (l == r - 1){
val = a[l];
return;
}
lc = new segTree(a, l, mid);
rc = new segTree(a, mid, r);
pull();
}
long long real_val(){
return val + lz;
}
void pull(){
val = min(lc->real_val(), rc->real_val());
}
void push(){
if (lz != 0){
lc->lz += lz;
rc->lz += lz;
lz = 0;
}
pull();
}
void update(int ll, int rr, long long u){
if (ll <= l && rr >= r){
lz -= u;
return;
}
push();
if (ll < mid){
lc->update(ll, rr, u);
}
if (mid < rr){
rc->update(ll, rr, u);
}
pull();
}
void query(vector<int> &ans){
if (real_val() > 0){
return;
}
if (l == r - 1){
ans.push_back(l);
val = INF;
return;
}
push();
lc->query(ans);
rc->query(ans);
pull();
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, q; cin >> n >> q;
vector<long long> a(n);
for (int i = 0; i < n; i++){
cin >> a[i];
}
vector<long long> b(n + 1, INF);
for (int i = 1; i < n; i++){
b[i] = a[i] - a[i - 1];
}
segTree st(b, 0, n + 1);
long long cur = 0, ll = 0, rr = 0;
vector<long long> ans(n);
vector<bool> vis(n + 1);
while (q--){
long long x; cin >> x;
cur += x;
if (x > 0 && cur > rr){
st.update(0, n + 1, cur - rr);
rr = cur;
vector<int> res;
st.query(res);
for (auto &i: res){
ans[i] += ll;
ans[i - 1] += b[i] - ll;
vis[i] = 1;
}
}
if (x < 0 && -cur > ll){
st.update(0, n + 1, -cur - ll);
ll = -cur;
vector<int> res;
st.query(res);
for (auto &i: res){
ans[i - 1] += rr;
ans[i] += b[i] - rr;
vis[i] = 1;
}
}
}
ans[0] += ll;
ans[n - 1] += rr;
for (int i = 1; i < n; i++){
if (!vis[i]){
ans[i - 1] += rr;
ans[i] += ll;
}
}
for (int i = 0; i < n; i++){
cout << ans[i] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
656 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
596 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
2 ms |
596 KB |
Output is correct |
16 |
Correct |
2 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
656 KB |
Output is correct |
18 |
Correct |
1 ms |
288 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
30 ms |
2336 KB |
Output is correct |
21 |
Correct |
26 ms |
2224 KB |
Output is correct |
22 |
Correct |
26 ms |
1992 KB |
Output is correct |
23 |
Correct |
31 ms |
2116 KB |
Output is correct |
24 |
Correct |
35 ms |
5084 KB |
Output is correct |
25 |
Correct |
205 ms |
35404 KB |
Output is correct |
26 |
Correct |
211 ms |
35332 KB |
Output is correct |
27 |
Correct |
201 ms |
35024 KB |
Output is correct |
28 |
Correct |
199 ms |
35160 KB |
Output is correct |
29 |
Correct |
192 ms |
34636 KB |
Output is correct |
30 |
Correct |
167 ms |
34028 KB |
Output is correct |
31 |
Correct |
111 ms |
33572 KB |
Output is correct |
32 |
Correct |
75 ms |
34368 KB |
Output is correct |
33 |
Correct |
14 ms |
3796 KB |
Output is correct |
34 |
Correct |
172 ms |
35716 KB |
Output is correct |
35 |
Correct |
183 ms |
35132 KB |
Output is correct |
36 |
Correct |
216 ms |
35404 KB |
Output is correct |
37 |
Correct |
215 ms |
35156 KB |
Output is correct |
38 |
Correct |
200 ms |
34896 KB |
Output is correct |
39 |
Correct |
175 ms |
35148 KB |
Output is correct |
40 |
Correct |
122 ms |
35328 KB |
Output is correct |
41 |
Correct |
28 ms |
2992 KB |
Output is correct |
42 |
Correct |
64 ms |
33612 KB |
Output is correct |
43 |
Correct |
92 ms |
37040 KB |
Output is correct |
44 |
Correct |
28 ms |
2864 KB |
Output is correct |
45 |
Correct |
75 ms |
35156 KB |
Output is correct |
46 |
Correct |
101 ms |
37120 KB |
Output is correct |
47 |
Correct |
93 ms |
37420 KB |
Output is correct |
48 |
Correct |
97 ms |
37440 KB |
Output is correct |