#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;
};
struct SegTree {
int leftQuery, rightQuery;
info segTree[4 * MAX_N], 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 };
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 );
}
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, info 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 );
//printf( "%d %d %lld %lld\n", l, r, segTree[v].minn, segTree[v].maxx );
}
void update( int l, int r, info x ) {
//printf( "UPDATE %d %d %lld %lld\n", l, r, x.minn, x.maxx );
update( 0, leftQuery, rightQuery, l, r, x );
}
long long queryAll() {
return segTree[0].maxx - segTree[0].minn;
}
} cost;
long long mins[MAX_N], maxs[MAX_N];
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;
}
for ( int j = 1; j <= n; j++ ) {
mins[j] = INF;
maxs[j] = -INF;
}
cost.init( 1, n );
for ( int i = 0; i < n; i++ ) {
for ( int j = nrm[i]; j <= n; j++ ) {
mins[j] += d;
maxs[j] += d;
}
cost.update( nrm[i], n, { d, d } );
mins[nrm[i]] += -INF + x[i];
maxs[nrm[i]] += INF + x[i];
cost.update( nrm[i], nrm[i], { -INF - x[i], INF - x[i] } );
if ( i >= n - q ) {
long long ans = cost.queryAll();
long long mn = INF, mx = -INF;
for ( int j = 1; j <= n; j++ ) {
mn = min( mn, mins[j] );
mx = max( mx, maxs[j] );
}
cout << ans / 2;
if ( ans % 2 == 1 )
cout << ".5";
cout << " ";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1598 ms |
44452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1598 ms |
44452 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |