# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1114169 |
2024-11-18T09:10:52 Z |
Dan4Life |
Snowball (JOI21_ho_t2) |
C++17 |
|
105 ms |
18628 KB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
#define int long long
const int N = (int)2e5+10;
const int LINF = (int)1e18;
int n, q, a[N], w[N], pr[N], mnpr[N], mxpr[N];
using ar2 = array<int,2>;
ar2 xd[N];
ar2 f(int dis){
int a = 0, b = dis, mnB=dis, mxA = 0;
int l = 0, r = q;
while(l<r){
int mid = (l+r+1)/2;
if(a+mxpr[mid] >= b+mnpr[mid]) r=mid-1;
else l = mid;
}
mxA = a+mxpr[l], mnB = b+mnpr[l];
a += pr[l], b+=pr[l];
if(l<q){
a+=w[l]; b+=w[l];
if(a>mnB) a=mnB;
if(b<mxA) b=mxA;
mxA = max(mxA, a);
mnB = min(mnB, b);
}
return {mxA,dis-mnB};
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> q; a[0] = -LINF; a[n+1]=LINF;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i < q; i++){
cin >> w[i],pr[i+1]=pr[i]+w[i];
mnpr[i+1]=min(mnpr[i],pr[i+1]);
mxpr[i+1]=max(mxpr[i],pr[i+1]);
}
for(int i = 1; i <= n+1; i++) xd[i] = f(a[i]-a[i-1]);
for(int i = 1; i <= n; i++) cout << xd[i][1]+xd[i+1][0] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4644 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
3 ms |
4688 KB |
Output is correct |
5 |
Correct |
3 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4688 KB |
Output is correct |
7 |
Correct |
2 ms |
4688 KB |
Output is correct |
8 |
Correct |
3 ms |
4688 KB |
Output is correct |
9 |
Correct |
3 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
2 ms |
4432 KB |
Output is correct |
12 |
Correct |
1 ms |
4432 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
2 ms |
4688 KB |
Output is correct |
16 |
Correct |
2 ms |
4688 KB |
Output is correct |
17 |
Correct |
2 ms |
4688 KB |
Output is correct |
18 |
Correct |
1 ms |
4432 KB |
Output is correct |
19 |
Correct |
2 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4644 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
3 ms |
4688 KB |
Output is correct |
5 |
Correct |
3 ms |
4432 KB |
Output is correct |
6 |
Correct |
2 ms |
4688 KB |
Output is correct |
7 |
Correct |
2 ms |
4688 KB |
Output is correct |
8 |
Correct |
3 ms |
4688 KB |
Output is correct |
9 |
Correct |
3 ms |
4432 KB |
Output is correct |
10 |
Correct |
2 ms |
4432 KB |
Output is correct |
11 |
Correct |
2 ms |
4432 KB |
Output is correct |
12 |
Correct |
1 ms |
4432 KB |
Output is correct |
13 |
Correct |
1 ms |
4432 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
2 ms |
4688 KB |
Output is correct |
16 |
Correct |
2 ms |
4688 KB |
Output is correct |
17 |
Correct |
2 ms |
4688 KB |
Output is correct |
18 |
Correct |
1 ms |
4432 KB |
Output is correct |
19 |
Correct |
2 ms |
4432 KB |
Output is correct |
20 |
Correct |
35 ms |
7688 KB |
Output is correct |
21 |
Correct |
26 ms |
7604 KB |
Output is correct |
22 |
Correct |
19 ms |
7660 KB |
Output is correct |
23 |
Correct |
19 ms |
7760 KB |
Output is correct |
24 |
Correct |
34 ms |
10120 KB |
Output is correct |
25 |
Correct |
86 ms |
16712 KB |
Output is correct |
26 |
Correct |
83 ms |
16660 KB |
Output is correct |
27 |
Correct |
87 ms |
16192 KB |
Output is correct |
28 |
Correct |
80 ms |
16260 KB |
Output is correct |
29 |
Correct |
88 ms |
15956 KB |
Output is correct |
30 |
Correct |
71 ms |
15176 KB |
Output is correct |
31 |
Correct |
48 ms |
14608 KB |
Output is correct |
32 |
Correct |
43 ms |
14912 KB |
Output is correct |
33 |
Correct |
14 ms |
7760 KB |
Output is correct |
34 |
Correct |
83 ms |
17016 KB |
Output is correct |
35 |
Correct |
87 ms |
16456 KB |
Output is correct |
36 |
Correct |
83 ms |
16712 KB |
Output is correct |
37 |
Correct |
87 ms |
16432 KB |
Output is correct |
38 |
Correct |
105 ms |
16296 KB |
Output is correct |
39 |
Correct |
75 ms |
16456 KB |
Output is correct |
40 |
Correct |
55 ms |
16496 KB |
Output is correct |
41 |
Correct |
24 ms |
10464 KB |
Output is correct |
42 |
Correct |
42 ms |
14920 KB |
Output is correct |
43 |
Correct |
57 ms |
18256 KB |
Output is correct |
44 |
Correct |
23 ms |
10312 KB |
Output is correct |
45 |
Correct |
50 ms |
16480 KB |
Output is correct |
46 |
Correct |
59 ms |
18140 KB |
Output is correct |
47 |
Correct |
58 ms |
18404 KB |
Output is correct |
48 |
Correct |
68 ms |
18628 KB |
Output is correct |