#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 4e5;
const long long INF = 1e15;
int x[MAX_N], nrm[MAX_N];
map<int, vector<int>> frecv;
struct info {
long long minn, maxx, maxDiff;
};
struct add {
long long minn, maxx;
};
struct SegTree {
int leftQuery, rightQuery;
info segTree[4 * MAX_N];
add lazy[4 * MAX_N];
void propag( int v, int l, int r ) {
segTree[v].minn += lazy[v].minn;
segTree[v].maxx += lazy[v].maxx;
if ( l != r ) {
lazy[v * 2 + 1].minn += lazy[v].minn;
lazy[v * 2 + 2].minn += lazy[v].minn;
lazy[v * 2 + 1].maxx += lazy[v].maxx;
lazy[v * 2 + 2].maxx += lazy[v].maxx;
}
lazy[v] = { 0, 0 };
}
void init( int v, int l, int r ) {
if ( l == r ) {
segTree[v] = { INF, -INF, 0 };
return;
}
int mid = (l + r) / 2;
init( v * 2 + 1, l, mid );
init( v * 2 + 2, mid + 1, r );
segTree[v].minn = min( segTree[v * 2 + 1].minn, segTree[v * 2 + 2].minn );
segTree[v].maxx = max( segTree[v * 2 + 1].maxx, segTree[v * 2 + 2].maxx );
segTree[v].maxDiff = max( segTree[v * 2 + 2].maxx - segTree[v * 2 + 1].minn, max( segTree[v * 2 + 1].maxDiff, segTree[v * 2 + 2].maxDiff ) );
}
void init( int l, int r ) {
leftQuery = l;
rightQuery = r;
init( 0, l, r );
}
void update( int v, int l, int r, int lu, int ru, add x ) {
propag( v, l, r );
if ( l > ru || r < lu )
return;
if ( lu <= l && r <= ru ) {
lazy[v] = x;
propag( v, l, r );
return;
}
int mid = (l + r) / 2;
update( v * 2 + 1, l, mid, lu, ru, x );
update( v * 2 + 2, mid + 1, r, lu, ru, x );
segTree[v].minn = min( segTree[v * 2 + 1].minn, segTree[v * 2 + 2].minn );
segTree[v].maxx = max( segTree[v * 2 + 1].maxx, segTree[v * 2 + 2].maxx );
segTree[v].maxDiff = max( segTree[v * 2 + 2].maxx - segTree[v * 2 + 1].minn, max( segTree[v * 2 + 1].maxDiff, segTree[v * 2 + 2].maxDiff ) );
}
void update( int l, int r, add x ) {
update( 0, leftQuery, rightQuery, l, r, x );
}
long long queryAll() {
return segTree[0].maxDiff;
}
} cost;
int main() {
ios_base::sync_with_stdio( false );
cin.tie( NULL );
int n, q, d;
cin >> n >> q >> d;
n += q;
for ( int i = 0; i < n; i++ ) {
cin >> x[i];
frecv[x[i]].push_back( i );
}
int val = 0;
for ( auto p: frecv ) {
for ( int i: p.second )
nrm[i] = ++val;
}
cost.init( 1, n );
for ( int i = 0; i < n; i++ ) {
cost.update( nrm[i], nrm[i], { -INF - x[i], INF - x[i] } );
cost.update( nrm[i], n, { d, d } );
if ( i >= n - q ) {
long long ans = cost.queryAll();
cout << ans / 2;
if ( ans % 2 == 1 )
cout << ".5";
cout << " ";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2908 KB |
Output is correct |
2 |
Correct |
2 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
3 ms |
2908 KB |
Output is correct |
7 |
Correct |
2 ms |
2908 KB |
Output is correct |
8 |
Correct |
2 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2908 KB |
Output is correct |
2 |
Correct |
2 ms |
2908 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
3 ms |
2908 KB |
Output is correct |
7 |
Correct |
2 ms |
2908 KB |
Output is correct |
8 |
Correct |
2 ms |
2908 KB |
Output is correct |
9 |
Correct |
340 ms |
49236 KB |
Output is correct |
10 |
Correct |
327 ms |
49488 KB |
Output is correct |
11 |
Correct |
146 ms |
28204 KB |
Output is correct |
12 |
Correct |
225 ms |
49328 KB |
Output is correct |
13 |
Correct |
200 ms |
49228 KB |
Output is correct |
14 |
Correct |
209 ms |
49348 KB |
Output is correct |
15 |
Correct |
316 ms |
48728 KB |
Output is correct |
16 |
Correct |
210 ms |
49264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
48404 KB |
Output is correct |
2 |
Correct |
215 ms |
50164 KB |
Output is correct |
3 |
Correct |
163 ms |
29340 KB |
Output is correct |
4 |
Correct |
211 ms |
48104 KB |
Output is correct |
5 |
Correct |
217 ms |
49592 KB |
Output is correct |
6 |
Correct |
212 ms |
48464 KB |
Output is correct |
7 |
Correct |
217 ms |
49552 KB |
Output is correct |
8 |
Correct |
211 ms |
48212 KB |
Output is correct |
9 |
Correct |
221 ms |
48212 KB |
Output is correct |
10 |
Correct |
220 ms |
51028 KB |
Output is correct |
11 |
Correct |
213 ms |
48976 KB |
Output is correct |
12 |
Correct |
212 ms |
50004 KB |
Output is correct |
13 |
Correct |
219 ms |
48112 KB |
Output is correct |
14 |
Correct |
214 ms |
50216 KB |
Output is correct |
15 |
Correct |
222 ms |
50016 KB |
Output is correct |
16 |
Correct |
209 ms |
48208 KB |
Output is correct |
17 |
Correct |
210 ms |
49492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
48404 KB |
Output is correct |
2 |
Correct |
215 ms |
50164 KB |
Output is correct |
3 |
Correct |
163 ms |
29340 KB |
Output is correct |
4 |
Correct |
211 ms |
48104 KB |
Output is correct |
5 |
Correct |
217 ms |
49592 KB |
Output is correct |
6 |
Correct |
212 ms |
48464 KB |
Output is correct |
7 |
Correct |
217 ms |
49552 KB |
Output is correct |
8 |
Correct |
211 ms |
48212 KB |
Output is correct |
9 |
Correct |
221 ms |
48212 KB |
Output is correct |
10 |
Correct |
220 ms |
51028 KB |
Output is correct |
11 |
Correct |
213 ms |
48976 KB |
Output is correct |
12 |
Correct |
212 ms |
50004 KB |
Output is correct |
13 |
Correct |
219 ms |
48112 KB |
Output is correct |
14 |
Correct |
214 ms |
50216 KB |
Output is correct |
15 |
Correct |
222 ms |
50016 KB |
Output is correct |
16 |
Correct |
209 ms |
48208 KB |
Output is correct |
17 |
Correct |
210 ms |
49492 KB |
Output is correct |
18 |
Correct |
351 ms |
48460 KB |
Output is correct |
19 |
Correct |
397 ms |
52288 KB |
Output is correct |
20 |
Correct |
166 ms |
31164 KB |
Output is correct |
21 |
Correct |
232 ms |
50260 KB |
Output is correct |
22 |
Correct |
291 ms |
50616 KB |
Output is correct |
23 |
Correct |
218 ms |
50276 KB |
Output is correct |
24 |
Correct |
360 ms |
51112 KB |
Output is correct |
25 |
Correct |
210 ms |
50008 KB |
Output is correct |
26 |
Correct |
358 ms |
50336 KB |
Output is correct |
27 |
Correct |
361 ms |
52652 KB |
Output is correct |
28 |
Correct |
267 ms |
50568 KB |
Output is correct |
29 |
Correct |
303 ms |
51796 KB |
Output is correct |
30 |
Correct |
233 ms |
49904 KB |
Output is correct |
31 |
Correct |
238 ms |
52012 KB |
Output is correct |
32 |
Correct |
219 ms |
51792 KB |
Output is correct |
33 |
Correct |
334 ms |
49772 KB |
Output is correct |
34 |
Correct |
233 ms |
51444 KB |
Output is correct |