#include <bits/stdc++.h>
#define se second
#define fs first
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<ll,ll>
#define ld long double
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }
const int N = 2e5 + 7;
const int Mod = 1e9 + 7;
const int szBL = 240;
const ll INF = 1e18;
const int BASE = 137;
int n, m;
ll D;
ll b[2 * N];
vector<ll> vals;
struct Segment_Tree {
struct Node {
ll mx, mn, cnt;
};
int m;
Node st[N << 3];
ll lz[N << 3];
void init (int n) {
m = n;
rep (i, 1, n << 2) st[i].mx = -INF, st[i].mn = INF, st[i].cnt = 0;
}
Node mer (Node lf, Node rt) {
return {max(lf.mx, rt.mx), min(lf.mn, rt.mn), lf.cnt + rt.cnt};
}
void down (int id){
rep (i, id << 1, id << 1 | 1) {
lz[i] += lz[id];
st[i].mn += lz[id];
st[i].mx += lz[id];
}
lz[id] = 0;
}
void update (int id, int l, int r, int pos, ll val) {
if (l > pos || r < pos) return;
if (l == r) {
st[id].mx = max(st[id].mx, val);
st[id].mn = min(st[id].mn, val);
st[id].cnt++;
return;
}
int mid = l + r >> 1;
down(id);
update (id << 1, l, mid, pos, val);
update (id << 1 | 1, mid + 1, r, pos, val);
st[id] = mer(st[id << 1], st[id << 1 | 1]);
}
void update (int id, int l, int r, int u, int v, ll val){
if (l > v || r < u) return;
if (l >= u && r <= v) {
st[id].mx += val;
st[id].mn += val;
lz[id] += val;
return;
}
int mid = l + r >> 1;
down(id);
update (id << 1, l, mid, u, v, val);
update (id << 1 | 1, mid + 1, r, u, v, val);
st[id] = mer(st[id << 1], st[id << 1 | 1]);
}
Node get (int id, int l, int r, int u, int v){
if (l > v || r < u) return {-INF, INF, 0};
if (l >= u && r <= v) return st[id];
int mid = l + r >> 1;
down(id);
return mer(get (id << 1, l, mid, u, v), get (id << 1 | 1, mid + 1, r, u, v));
}
void update (int pos, ll val) {
update (1, 1, m, pos, val);
}
void update (int u, int v, ll val) {
update (1, 1, m, u, v, val);
}
Node get (int u, int v) {
return get (1, 1, m, u, v);
}
}ST;
void solution (){
cin >> n >> m >> D;
m += n;
rep (i, 1, m) cin >> b[i], vals.push_back(b[i]);
sort (ALL(vals));
ll K; vals.resize(K = unique(ALL(vals)) - vals.begin());
ST.init(K);
ll res = 0;
rep (i, 1, m) {
int pos = lower_bound(ALL(vals), b[i]) - vals.begin() + 1;
ST.update (pos, (ST.get(1, pos).cnt + 1) * D - b[i]);
ST.update (pos + 1, K, D);
res = max (res, ST.get(pos, K).mx - ST.get(1, pos).mn);
if (i > n) {
if (res % 2 == 0)
cout << res / 2 <<" ";
else cout << fixed <<setprecision(1) <<1.0 * res / 2 <<" ";
}
}
}
#define file(name) freopen(name".inp", "r", stdin); \
freopen(name".out", "w", stdout);
/*
*/
int main () {
// file("c");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll num_Test = 1;
// cin >> num_Test;
while(num_Test--)
solution();
}
/*
no bug challenge +1
*/
Compilation message
Main.cpp: In member function 'void Segment_Tree::update(int, int, int, int, long long int)':
Main.cpp:64:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
64 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'void Segment_Tree::update(int, int, int, int, int, long long int)':
Main.cpp:79:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
79 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'Segment_Tree::Node Segment_Tree::get(int, int, int, int, int)':
Main.cpp:89:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
89 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
544 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
317 ms |
28536 KB |
Output is correct |
10 |
Correct |
311 ms |
28616 KB |
Output is correct |
11 |
Correct |
21 ms |
5584 KB |
Output is correct |
12 |
Correct |
259 ms |
28356 KB |
Output is correct |
13 |
Correct |
217 ms |
27972 KB |
Output is correct |
14 |
Correct |
227 ms |
28412 KB |
Output is correct |
15 |
Correct |
295 ms |
27848 KB |
Output is correct |
16 |
Correct |
268 ms |
28356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
27612 KB |
Output is correct |
2 |
Correct |
281 ms |
29400 KB |
Output is correct |
3 |
Correct |
70 ms |
8384 KB |
Output is correct |
4 |
Correct |
260 ms |
29180 KB |
Output is correct |
5 |
Correct |
251 ms |
30408 KB |
Output is correct |
6 |
Correct |
252 ms |
29516 KB |
Output is correct |
7 |
Correct |
310 ms |
30664 KB |
Output is correct |
8 |
Correct |
264 ms |
29384 KB |
Output is correct |
9 |
Correct |
263 ms |
29408 KB |
Output is correct |
10 |
Correct |
278 ms |
31536 KB |
Output is correct |
11 |
Correct |
312 ms |
30148 KB |
Output is correct |
12 |
Correct |
263 ms |
30924 KB |
Output is correct |
13 |
Correct |
263 ms |
29124 KB |
Output is correct |
14 |
Correct |
255 ms |
31176 KB |
Output is correct |
15 |
Correct |
259 ms |
30936 KB |
Output is correct |
16 |
Correct |
272 ms |
28912 KB |
Output is correct |
17 |
Correct |
302 ms |
30660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
27612 KB |
Output is correct |
2 |
Correct |
281 ms |
29400 KB |
Output is correct |
3 |
Correct |
70 ms |
8384 KB |
Output is correct |
4 |
Correct |
260 ms |
29180 KB |
Output is correct |
5 |
Correct |
251 ms |
30408 KB |
Output is correct |
6 |
Correct |
252 ms |
29516 KB |
Output is correct |
7 |
Correct |
310 ms |
30664 KB |
Output is correct |
8 |
Correct |
264 ms |
29384 KB |
Output is correct |
9 |
Correct |
263 ms |
29408 KB |
Output is correct |
10 |
Correct |
278 ms |
31536 KB |
Output is correct |
11 |
Correct |
312 ms |
30148 KB |
Output is correct |
12 |
Correct |
263 ms |
30924 KB |
Output is correct |
13 |
Correct |
263 ms |
29124 KB |
Output is correct |
14 |
Correct |
255 ms |
31176 KB |
Output is correct |
15 |
Correct |
259 ms |
30936 KB |
Output is correct |
16 |
Correct |
272 ms |
28912 KB |
Output is correct |
17 |
Correct |
302 ms |
30660 KB |
Output is correct |
18 |
Correct |
330 ms |
29656 KB |
Output is correct |
19 |
Correct |
356 ms |
31428 KB |
Output is correct |
20 |
Correct |
70 ms |
8392 KB |
Output is correct |
21 |
Correct |
270 ms |
29380 KB |
Output is correct |
22 |
Correct |
287 ms |
29636 KB |
Output is correct |
23 |
Correct |
242 ms |
29384 KB |
Output is correct |
24 |
Correct |
365 ms |
30020 KB |
Output is correct |
25 |
Correct |
243 ms |
29128 KB |
Output is correct |
26 |
Correct |
345 ms |
29096 KB |
Output is correct |
27 |
Correct |
382 ms |
31804 KB |
Output is correct |
28 |
Correct |
274 ms |
29728 KB |
Output is correct |
29 |
Correct |
347 ms |
30920 KB |
Output is correct |
30 |
Correct |
287 ms |
29492 KB |
Output is correct |
31 |
Correct |
260 ms |
31172 KB |
Output is correct |
32 |
Correct |
305 ms |
30836 KB |
Output is correct |
33 |
Correct |
337 ms |
28868 KB |
Output is correct |
34 |
Correct |
294 ms |
30664 KB |
Output is correct |