#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define F0R(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ROF(i, a, b) for(int i=b-1; i>=a; i--)
#define siz(x) (int) x.size()
#define f first
#define s second
const int mxN = 2e5+10;
const ll infLL = 1e18+10;
int n, q;
ll x[mxN];
ll w[mxN];
ll ans[mxN];
ll dl[mxN], dr[mxN];
pair<ll, int> sl[mxN], sr[mxN];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
F0R(i, n) cin >> x[i];
F0R(i, q) cin >> w[i];
// we will first solve for prefixs and then suffixs
ll mn = 0, mx = 0;
ll pos = 0;
//F0R(i, q){
// pos += w[i];
// mn = min(mn, pos);
// mx = max(mx, pos);
//}
// find min and max
//F0R(i, n) ans[i] += mn+mx;
// init
dl[0] = infLL;
FOR(i, 1, n) dl[i] = x[i]-x[i-1];
dr[n-1] = infLL;
F0R(i, n-1) dr[i] = x[i+1]-x[i];
F0R(i, n) sl[i] = {dl[i], i}, sr[i] = {dr[i], i};
sort(sl, sl+n); sort(sr, sr+n);
//mn = 0, mx = 0, pos = 0;
int pl = 0, pr = 0;
F0R(i, q){
pos += w[i];
while(pl<n&&sl[pl].f<=mx-pos){
ans[sl[pl].s] += max(-mn, sl[pl].f-mx);
pl++;
}
while(pr<n&&sr[pr].f<=pos-mn){
ans[sr[pr].s] += max(mx, sr[pr].f+mn);
pr++;
}
mn = min(mn, pos);
mx = max(mx, pos);
}
while(pl<n){
ans[sl[pl].s] += -mn;
pl++;
}
while(pr<n){
ans[sr[pr].s] += mx;
pr++;
}
F0R(i, n){
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
620 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
620 KB |
Output is correct |
5 |
Correct |
2 ms |
620 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
620 KB |
Output is correct |
8 |
Correct |
3 ms |
620 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
2 ms |
620 KB |
Output is correct |
11 |
Correct |
2 ms |
620 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
2 ms |
620 KB |
Output is correct |
17 |
Correct |
2 ms |
620 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
620 KB |
Output is correct |
20 |
Correct |
35 ms |
4108 KB |
Output is correct |
21 |
Correct |
29 ms |
3948 KB |
Output is correct |
22 |
Correct |
32 ms |
3620 KB |
Output is correct |
23 |
Correct |
27 ms |
3692 KB |
Output is correct |
24 |
Correct |
33 ms |
4972 KB |
Output is correct |
25 |
Correct |
118 ms |
19420 KB |
Output is correct |
26 |
Correct |
115 ms |
19308 KB |
Output is correct |
27 |
Correct |
113 ms |
19180 KB |
Output is correct |
28 |
Correct |
117 ms |
19200 KB |
Output is correct |
29 |
Correct |
118 ms |
18964 KB |
Output is correct |
30 |
Correct |
116 ms |
18668 KB |
Output is correct |
31 |
Correct |
110 ms |
17772 KB |
Output is correct |
32 |
Correct |
85 ms |
18024 KB |
Output is correct |
33 |
Correct |
14 ms |
2460 KB |
Output is correct |
34 |
Correct |
117 ms |
19380 KB |
Output is correct |
35 |
Correct |
116 ms |
19308 KB |
Output is correct |
36 |
Correct |
118 ms |
19436 KB |
Output is correct |
37 |
Correct |
124 ms |
19180 KB |
Output is correct |
38 |
Correct |
118 ms |
19308 KB |
Output is correct |
39 |
Correct |
124 ms |
19180 KB |
Output is correct |
40 |
Correct |
120 ms |
19308 KB |
Output is correct |
41 |
Correct |
32 ms |
4716 KB |
Output is correct |
42 |
Correct |
105 ms |
18028 KB |
Output is correct |
43 |
Correct |
117 ms |
19308 KB |
Output is correct |
44 |
Correct |
35 ms |
4588 KB |
Output is correct |
45 |
Correct |
117 ms |
19232 KB |
Output is correct |
46 |
Correct |
108 ms |
19524 KB |
Output is correct |
47 |
Correct |
132 ms |
19436 KB |
Output is correct |
48 |
Correct |
109 ms |
19436 KB |
Output is correct |