# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
372618 |
2021-03-01T06:24:44 Z |
blue |
Snowball (JOI21_ho_t2) |
C++11 |
|
281 ms |
11500 KB |
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int N, Q;
cin >> N >> Q;
long long X[N+1];
for(int i = 1; i <= N; i++) cin >> X[i];
long long W[Q+1];
for(int i = 1; i <= Q; i++) cin >> W[i];
long long Wsum[Q+1];
Wsum[0] = 0;
for(int i = 1; i <= Q; i++) Wsum[i] = Wsum[i-1] + W[i];
// for(long long i = 0; i <= Q; i++) cout << Wsum[i] << ' ';
// cout << '\n';
long long Wmin[Q+1], Wmax[Q+1];
Wmin[0] = Wmax[0] = 0;
for(int i = 1; i <= Q; i++)
{
Wmin[i] = min(Wsum[i], Wmin[i-1]);
Wmax[i] = max(Wsum[i], Wmax[i-1]);
}
// for(long long i = 0; i <= Q; i++) cout << Wmin[i] << ' ';
// cout << '\n';
// for(long long i = 0; i <= Q; i++) cout << Wmax[i] << ' ';
// cout << '\n';
vector<long long> res(N+1, 0);
res[1] += -Wmin[Q];
for(int i = 1; i < N; i++)
{
int A = 0;
for(int bit = 20; bit >= 0; bit--)
{
if(A + (1 << bit) > Q) continue;
if(-Wmin[A + (1 << bit)] + Wmax[A + (1 << bit)] < X[i+1] - X[i]) A += (1 << bit);
}
A++;
// cout << A << ' ';
if(A == Q+1)
{
res[i] += Wmax[Q];
res[i+1] += -Wmin[Q];
}
else
{
if(W[A] < 0)
{
res[i] += Wmax[A-1];
res[i+1] += X[i+1] - X[i] - Wmax[A-1];
}
else
{
res[i+1] += -Wmin[A-1];
res[i] += X[i+1] - X[i] - (-Wmin[A-1]);
}
}
}
// cout << '\n';
res[N] += Wmax[Q];
for(int i = 1; i <= N; i++) cout << res[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
0 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 |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
4 ms |
364 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
3 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
3 ms |
364 KB |
Output is correct |
10 |
Correct |
3 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
0 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 |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
4 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
96 ms |
6636 KB |
Output is correct |
21 |
Correct |
88 ms |
6508 KB |
Output is correct |
22 |
Correct |
120 ms |
6508 KB |
Output is correct |
23 |
Correct |
106 ms |
6636 KB |
Output is correct |
24 |
Correct |
125 ms |
7020 KB |
Output is correct |
25 |
Correct |
281 ms |
11372 KB |
Output is correct |
26 |
Correct |
266 ms |
11244 KB |
Output is correct |
27 |
Correct |
245 ms |
11116 KB |
Output is correct |
28 |
Correct |
263 ms |
11244 KB |
Output is correct |
29 |
Correct |
237 ms |
11008 KB |
Output is correct |
30 |
Correct |
229 ms |
10720 KB |
Output is correct |
31 |
Correct |
191 ms |
10092 KB |
Output is correct |
32 |
Correct |
193 ms |
10092 KB |
Output is correct |
33 |
Correct |
24 ms |
1388 KB |
Output is correct |
34 |
Correct |
256 ms |
11244 KB |
Output is correct |
35 |
Correct |
254 ms |
11136 KB |
Output is correct |
36 |
Correct |
271 ms |
11380 KB |
Output is correct |
37 |
Correct |
270 ms |
11176 KB |
Output is correct |
38 |
Correct |
246 ms |
11116 KB |
Output is correct |
39 |
Correct |
251 ms |
11244 KB |
Output is correct |
40 |
Correct |
245 ms |
11076 KB |
Output is correct |
41 |
Correct |
111 ms |
6508 KB |
Output is correct |
42 |
Correct |
175 ms |
10092 KB |
Output is correct |
43 |
Correct |
269 ms |
11488 KB |
Output is correct |
44 |
Correct |
117 ms |
6508 KB |
Output is correct |
45 |
Correct |
211 ms |
11244 KB |
Output is correct |
46 |
Correct |
265 ms |
11372 KB |
Output is correct |
47 |
Correct |
276 ms |
11372 KB |
Output is correct |
48 |
Correct |
276 ms |
11500 KB |
Output is correct |