#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p, r = (1LL << 50);
vector<ll> df, sg, mn, mx, lz, wl, wr;
void push(int i)
{
mn[i] += lz[i];
mx[i] += lz[i];
sg[i] += lz[i];
if (i < p)
{
lz[2 * i] += lz[i];
lz[2 * i + 1] += lz[i];
}
lz[i] = 0;
}
void upd(ll l, ll r, ll i, ll x)
{
if (wl[i] >= r || wr[i] <= l)
{
push(i);
return;
}
if (wl[i] >= l && wr[i] <= r)
{
lz[i] += x;
push(i);
return;
}
push(i);
upd(l, r, 2 * i, x);
upd(l, r, 2 * i + 1, x);
mn[i] = min(mn[2 * i], mn[2 * i + 1]);
mx[i] = max(mx[2 * i], mx[2 * i + 1]);
df[i] = max(mx[2 * i + 1] - mn[2 * i], max(df[2 * i], df[2 * i + 1]));
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll n, m, d, i, j, z, la;
cin >> n >> m >> d;
if (n)
{
multiset<ll> s;
while (n--)
{
cin >> i;
s.insert(i);
}
while (m--)
{
cin >> i;
s.insert(i);
z = 0;
la = -d;
for (auto h : s)
{
la = max(la + d, h);
z = max(z, la - h);
}
if (z % 2)
cout << z / 2 << ".5 ";
else
cout << z / 2 << " ";
}
}
else
{
vector<vector<ll> > q(m, {0, 0});
vector<ll> in(m), va(m);
for (i = 0; i < m; i++)
{
cin >> q[i][0];
q[i][1] = i;
}
sort(q.begin(), q.end());
for (i = 0; i < m; i++)
{
in[q[i][1]] = i;
va[q[i][1]] = q[i][0];
}
p = m;
while (p != (p & -p))
p++;
wl.resize(2 * p);
wr.resize(2 * p);
sg.resize(2 * p);
df.resize(2 * p);
lz.resize(2 * p);
mn.resize(2 * p);
mx.resize(2 * p);
for (i = p; i < 2 * p; i++)
{
wl[i] = i;
wr[i] = i + 1;
mn[i] = r;
mx[i] = -r;
sg[i] = 0;
df[i] = 0;
lz[i] = 0;
}
for (i = p - 1; i > 0; i--)
{
wl[i] = wl[2 * i];
wr[i] = wr[2 * i + 1];
mn[i] = r;
mx[i] = -r;
sg[i] = 0;
df[i] = 0;
lz[i] = 0;
}
for (i = 0; i < m; i++)
{
j = in[i] + p;
sg[j] -= va[i];
mn[j] = mx[j] = sg[j];
upd(j, j + 1, 1, 0);
upd(j, 2 * p, 1, d);
z = df[1];
if (z % 2)
cout << z / 2 << ".5 ";
else
cout << z / 2 << " ";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
564 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
564 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
122 ms |
11696 KB |
Output is correct |
10 |
Correct |
79 ms |
11600 KB |
Output is correct |
11 |
Correct |
66 ms |
11604 KB |
Output is correct |
12 |
Correct |
62 ms |
11604 KB |
Output is correct |
13 |
Correct |
58 ms |
11092 KB |
Output is correct |
14 |
Correct |
52 ms |
11600 KB |
Output is correct |
15 |
Correct |
134 ms |
11040 KB |
Output is correct |
16 |
Correct |
87 ms |
11516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
46164 KB |
Output is correct |
2 |
Correct |
208 ms |
47976 KB |
Output is correct |
3 |
Correct |
214 ms |
47952 KB |
Output is correct |
4 |
Correct |
190 ms |
45824 KB |
Output is correct |
5 |
Correct |
186 ms |
47104 KB |
Output is correct |
6 |
Correct |
187 ms |
46156 KB |
Output is correct |
7 |
Correct |
275 ms |
47136 KB |
Output is correct |
8 |
Correct |
207 ms |
46036 KB |
Output is correct |
9 |
Correct |
213 ms |
45904 KB |
Output is correct |
10 |
Correct |
201 ms |
48260 KB |
Output is correct |
11 |
Correct |
186 ms |
46660 KB |
Output is correct |
12 |
Correct |
193 ms |
47700 KB |
Output is correct |
13 |
Correct |
198 ms |
45912 KB |
Output is correct |
14 |
Correct |
238 ms |
47804 KB |
Output is correct |
15 |
Correct |
204 ms |
47768 KB |
Output is correct |
16 |
Correct |
199 ms |
45392 KB |
Output is correct |
17 |
Correct |
204 ms |
47188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
199 ms |
46164 KB |
Output is correct |
2 |
Correct |
208 ms |
47976 KB |
Output is correct |
3 |
Correct |
214 ms |
47952 KB |
Output is correct |
4 |
Correct |
190 ms |
45824 KB |
Output is correct |
5 |
Correct |
186 ms |
47104 KB |
Output is correct |
6 |
Correct |
187 ms |
46156 KB |
Output is correct |
7 |
Correct |
275 ms |
47136 KB |
Output is correct |
8 |
Correct |
207 ms |
46036 KB |
Output is correct |
9 |
Correct |
213 ms |
45904 KB |
Output is correct |
10 |
Correct |
201 ms |
48260 KB |
Output is correct |
11 |
Correct |
186 ms |
46660 KB |
Output is correct |
12 |
Correct |
193 ms |
47700 KB |
Output is correct |
13 |
Correct |
198 ms |
45912 KB |
Output is correct |
14 |
Correct |
238 ms |
47804 KB |
Output is correct |
15 |
Correct |
204 ms |
47768 KB |
Output is correct |
16 |
Correct |
199 ms |
45392 KB |
Output is correct |
17 |
Correct |
204 ms |
47188 KB |
Output is correct |
18 |
Correct |
313 ms |
46420 KB |
Output is correct |
19 |
Correct |
306 ms |
48196 KB |
Output is correct |
20 |
Correct |
211 ms |
47956 KB |
Output is correct |
21 |
Correct |
263 ms |
46160 KB |
Output is correct |
22 |
Correct |
297 ms |
46420 KB |
Output is correct |
23 |
Correct |
199 ms |
46164 KB |
Output is correct |
24 |
Correct |
288 ms |
46672 KB |
Output is correct |
25 |
Correct |
204 ms |
45976 KB |
Output is correct |
26 |
Correct |
316 ms |
45904 KB |
Output is correct |
27 |
Correct |
278 ms |
48468 KB |
Output is correct |
28 |
Correct |
247 ms |
46412 KB |
Output is correct |
29 |
Correct |
260 ms |
47700 KB |
Output is correct |
30 |
Correct |
238 ms |
45904 KB |
Output is correct |
31 |
Correct |
242 ms |
47984 KB |
Output is correct |
32 |
Correct |
217 ms |
47952 KB |
Output is correct |
33 |
Correct |
343 ms |
45396 KB |
Output is correct |
34 |
Correct |
247 ms |
47192 KB |
Output is correct |