#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int n, m, d;
class stree {
public:
int lp, rp;
stree *l = nullptr;
stree *r = nullptr;
ll mx = -inf;
ll mn = inf;
ll best = -inf;
int pos_add = 0; // applies to everything in subtree incl root
stree(int lv, int rv) {
lp = lv;
rp = rv;
if (lp < rp) {
int mid = (lp+rp)/2;
l = new stree(lp, mid);
r = new stree(mid+1, rp);
}
}
void reupd() {
best = max(r->mx-l->mn, max(l->best, r->best));
mx = (ll)pos_add*d+max(l->mx, r->mx);
mn = (ll)pos_add*d+min(l->mn, r->mn);
}
void set_val(int p, ll v) {
if (lp > p || rp < p) return;
if (lp == rp) {
mx = mn = (ll)d*pos_add-v;
return;
}
l->set_val(p, v);
r->set_val(p, v);
reupd();
}
void inc_pos(int lv, int rv) {
if (lp > rv || rp < lv) return;
if (lp >= lv && rp <= rv) {
mx += d;
mn += d;
pos_add++;
return;
}
l->inc_pos(lv, rv);
r->inc_pos(lv, rv);
reupd();
}
};
typedef pair<int, int> pii;
const int MAXN = 2e5+5;
pii sortable[MAXN];
int cord[MAXN];
int pos[MAXN];
void print(ll ans) {
cout << ans/2;
if (ans&1) cout << ".5";
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m >> d;
m += n;
for (int i = 0; i < m; i++) {
cin >> cord[i];
sortable[i].first = cord[i];
sortable[i].second = i;
}
sort(sortable, sortable+m);
for (int i = 0; i < m; i++) pos[sortable[i].second] = i;
stree *tree = new stree(0, m-1);
for (int i = 0; i < m; i++) {
tree->set_val(pos[i], cord[i]);
tree->inc_pos(pos[i]+1, m-1);
if (i > n) cout << ' ';
if (i >= n) print(max(0ll, tree->best));
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
592 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
2 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Incorrect |
180 ms |
28916 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
31168 KB |
Output is correct |
2 |
Correct |
108 ms |
33372 KB |
Output is correct |
3 |
Correct |
103 ms |
33352 KB |
Output is correct |
4 |
Correct |
95 ms |
31160 KB |
Output is correct |
5 |
Correct |
107 ms |
32376 KB |
Output is correct |
6 |
Correct |
96 ms |
31564 KB |
Output is correct |
7 |
Correct |
104 ms |
32464 KB |
Output is correct |
8 |
Correct |
97 ms |
31196 KB |
Output is correct |
9 |
Correct |
97 ms |
31148 KB |
Output is correct |
10 |
Correct |
110 ms |
33680 KB |
Output is correct |
11 |
Correct |
100 ms |
31896 KB |
Output is correct |
12 |
Correct |
102 ms |
32976 KB |
Output is correct |
13 |
Correct |
98 ms |
31196 KB |
Output is correct |
14 |
Correct |
105 ms |
33196 KB |
Output is correct |
15 |
Correct |
101 ms |
32892 KB |
Output is correct |
16 |
Correct |
96 ms |
30772 KB |
Output is correct |
17 |
Correct |
100 ms |
32468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
31168 KB |
Output is correct |
2 |
Correct |
108 ms |
33372 KB |
Output is correct |
3 |
Correct |
103 ms |
33352 KB |
Output is correct |
4 |
Correct |
95 ms |
31160 KB |
Output is correct |
5 |
Correct |
107 ms |
32376 KB |
Output is correct |
6 |
Correct |
96 ms |
31564 KB |
Output is correct |
7 |
Correct |
104 ms |
32464 KB |
Output is correct |
8 |
Correct |
97 ms |
31196 KB |
Output is correct |
9 |
Correct |
97 ms |
31148 KB |
Output is correct |
10 |
Correct |
110 ms |
33680 KB |
Output is correct |
11 |
Correct |
100 ms |
31896 KB |
Output is correct |
12 |
Correct |
102 ms |
32976 KB |
Output is correct |
13 |
Correct |
98 ms |
31196 KB |
Output is correct |
14 |
Correct |
105 ms |
33196 KB |
Output is correct |
15 |
Correct |
101 ms |
32892 KB |
Output is correct |
16 |
Correct |
96 ms |
30772 KB |
Output is correct |
17 |
Correct |
100 ms |
32468 KB |
Output is correct |
18 |
Correct |
206 ms |
31484 KB |
Output is correct |
19 |
Correct |
196 ms |
33188 KB |
Output is correct |
20 |
Correct |
105 ms |
33244 KB |
Output is correct |
21 |
Correct |
124 ms |
31344 KB |
Output is correct |
22 |
Correct |
152 ms |
31672 KB |
Output is correct |
23 |
Correct |
104 ms |
31468 KB |
Output is correct |
24 |
Correct |
215 ms |
31984 KB |
Output is correct |
25 |
Correct |
102 ms |
31060 KB |
Output is correct |
26 |
Correct |
194 ms |
31140 KB |
Output is correct |
27 |
Correct |
216 ms |
33664 KB |
Output is correct |
28 |
Correct |
162 ms |
31504 KB |
Output is correct |
29 |
Correct |
184 ms |
32848 KB |
Output is correct |
30 |
Correct |
134 ms |
31052 KB |
Output is correct |
31 |
Correct |
128 ms |
33096 KB |
Output is correct |
32 |
Correct |
107 ms |
32956 KB |
Output is correct |
33 |
Correct |
197 ms |
30780 KB |
Output is correct |
34 |
Correct |
126 ms |
32444 KB |
Output is correct |