#include <bits/stdc++.h>
using namespace std;
#define ll long long int
constexpr ll oo = 4611686018427387904;
ll naj_lewo[200009];
ll naj_prawo[200009];
ll ter[200009];
ll wiatr[200009];
ll poz[200009];
ll odp[200009];
int bin_ser(int pocz, int kon, ll szuk){
int srod;
while(pocz<kon){
srod = (pocz+kon+1)/2;
if (naj_prawo[srod]-naj_lewo[srod] > szuk){
kon = srod-1;
}
else{
pocz = srod;
}
}
return pocz;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,q,dokl;
ll dyst;
cin >> n >> q;
for (int x=1;x<=n;x++){
cin >> poz[x];
}
ter[0] = 0;
for (int x=1;x<=q;x++){
cin >> wiatr[x];
ter[x] = ter[x-1] + wiatr[x];
naj_lewo[x] = min(naj_lewo[x-1],ter[x]);
naj_prawo[x] = max(naj_prawo[x-1],ter[x]);
}
for (int x=1;x<n;x++){
dyst = poz[x+1]-poz[x];
dokl = bin_ser(0,q,dyst);
odp[x] += naj_prawo[dokl];
odp[x+1] += -naj_lewo[dokl];
if (dokl < q){
if (wiatr[dokl+1]>0){
odp[x] += dyst-naj_prawo[dokl]+naj_lewo[dokl];
}
else{
odp[x+1] += dyst-naj_prawo[dokl]+naj_lewo[dokl];
}
}
}
odp[1] += -naj_lewo[q];
odp[n] += naj_prawo[q];
for (int x=1;x<=n;x++){
cout << odp[x] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
508 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
508 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
28 ms |
8652 KB |
Output is correct |
21 |
Correct |
26 ms |
8532 KB |
Output is correct |
22 |
Correct |
27 ms |
8272 KB |
Output is correct |
23 |
Correct |
30 ms |
8148 KB |
Output is correct |
24 |
Correct |
36 ms |
8644 KB |
Output is correct |
25 |
Correct |
98 ms |
15012 KB |
Output is correct |
26 |
Correct |
114 ms |
14940 KB |
Output is correct |
27 |
Correct |
115 ms |
14540 KB |
Output is correct |
28 |
Correct |
102 ms |
14740 KB |
Output is correct |
29 |
Correct |
98 ms |
14168 KB |
Output is correct |
30 |
Correct |
94 ms |
13720 KB |
Output is correct |
31 |
Correct |
66 ms |
13072 KB |
Output is correct |
32 |
Correct |
53 ms |
13200 KB |
Output is correct |
33 |
Correct |
9 ms |
1856 KB |
Output is correct |
34 |
Correct |
105 ms |
15364 KB |
Output is correct |
35 |
Correct |
99 ms |
14668 KB |
Output is correct |
36 |
Correct |
101 ms |
15008 KB |
Output is correct |
37 |
Correct |
102 ms |
14756 KB |
Output is correct |
38 |
Correct |
98 ms |
14628 KB |
Output is correct |
39 |
Correct |
96 ms |
14780 KB |
Output is correct |
40 |
Correct |
70 ms |
14772 KB |
Output is correct |
41 |
Correct |
32 ms |
9292 KB |
Output is correct |
42 |
Correct |
52 ms |
13152 KB |
Output is correct |
43 |
Correct |
79 ms |
16524 KB |
Output is correct |
44 |
Correct |
30 ms |
9164 KB |
Output is correct |
45 |
Correct |
84 ms |
14668 KB |
Output is correct |
46 |
Correct |
81 ms |
16636 KB |
Output is correct |
47 |
Correct |
85 ms |
16844 KB |
Output is correct |
48 |
Correct |
85 ms |
16880 KB |
Output is correct |