# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791636 |
2023-07-24T08:24:25 Z |
n3rm1n |
Snowball (JOI21_ho_t2) |
C++17 |
|
104 ms |
15372 KB |
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const long long MAXN = 2e5+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, q;
long long a[MAXN], wind[MAXN];
long long moveleft[MAXN], moveright[MAXN];
void read()
{
cin >> n >> q;
for (long long i = 1; i <= n; ++ i)
cin >> a[i];
long long pos = 0;
for (long long i = 1; i <= q; ++ i)
{
cin >> wind[i];
pos += wind[i];
moveleft[i] = min(pos, moveleft[i-1]);
moveright[i] = max(pos, moveright[i-1]);
}
for (long long i = 1; i <= q; ++ i)
{
moveleft[i] *= -1;
// cout << moveleft[i] << " " << moveright[i] << endl;
}
}
long long ans[MAXN];
void solve()
{
for (long long i = 2; i <= n; ++ i)
{
// int f = 0;
int l = 1, r = q, mid, x = q+1;
while(l <= r)
{
mid = (l + r)/2;
if(a[i-1] + moveright[mid] >= a[i] - moveleft[mid])
{
x = mid;
r = mid - 1;
}
else l = mid + 1;
}
if(x != q+1)
{
// cout << "***" << endl;
// cout << i-1 << " " << i << " " << j << endl;
long long segment = a[i] - a[i-1];
long long to_first = 0, to_second = 0;
if(wind[x] >= 0)
{
to_second = moveleft[x];
to_first = segment - to_second;
}
else
{
to_first = moveright[x];
to_second = segment - to_first;
}
//cout << to_first << " " << to_second << endl;
ans[i-1] += to_first;
ans[i] += to_second;
}
else
{
ans[i-1] += moveright[q];
ans[i] += moveleft[q];
}
}
ans[1] += moveleft[q];
ans[n] += moveright[q];
for (long long i = 1; i <= n; ++ i)
cout << ans[i] << " ";
cout << endl;
}
int main()
{
speed();
read();
solve();
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 |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
324 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 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 |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
380 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
324 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 |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
20 ms |
7056 KB |
Output is correct |
21 |
Correct |
26 ms |
6896 KB |
Output is correct |
22 |
Correct |
18 ms |
6732 KB |
Output is correct |
23 |
Correct |
19 ms |
6584 KB |
Output is correct |
24 |
Correct |
23 ms |
7020 KB |
Output is correct |
25 |
Correct |
79 ms |
13420 KB |
Output is correct |
26 |
Correct |
82 ms |
13384 KB |
Output is correct |
27 |
Correct |
87 ms |
13128 KB |
Output is correct |
28 |
Correct |
80 ms |
13204 KB |
Output is correct |
29 |
Correct |
78 ms |
12684 KB |
Output is correct |
30 |
Correct |
75 ms |
11980 KB |
Output is correct |
31 |
Correct |
50 ms |
11468 KB |
Output is correct |
32 |
Correct |
60 ms |
11584 KB |
Output is correct |
33 |
Correct |
7 ms |
1620 KB |
Output is correct |
34 |
Correct |
80 ms |
13772 KB |
Output is correct |
35 |
Correct |
80 ms |
13144 KB |
Output is correct |
36 |
Correct |
78 ms |
13416 KB |
Output is correct |
37 |
Correct |
78 ms |
13192 KB |
Output is correct |
38 |
Correct |
104 ms |
13052 KB |
Output is correct |
39 |
Correct |
79 ms |
13244 KB |
Output is correct |
40 |
Correct |
59 ms |
13132 KB |
Output is correct |
41 |
Correct |
23 ms |
7664 KB |
Output is correct |
42 |
Correct |
47 ms |
11592 KB |
Output is correct |
43 |
Correct |
58 ms |
14896 KB |
Output is correct |
44 |
Correct |
20 ms |
7576 KB |
Output is correct |
45 |
Correct |
55 ms |
13120 KB |
Output is correct |
46 |
Correct |
57 ms |
14996 KB |
Output is correct |
47 |
Correct |
77 ms |
15284 KB |
Output is correct |
48 |
Correct |
59 ms |
15372 KB |
Output is correct |