#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m, d;
class stree {
public:
int lp, rp;
stree *l = nullptr, *r = nullptr;
ll mx = INT_MIN, mn = INT_MAX, best = INT_MIN;
int pos_add = 0;
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();
}
};
const int MAXN = 2e5+5;
pair<int, int> sortable[MAXN];
int cord[MAXN], 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));
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Incorrect |
177 ms |
28412 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
29520 KB |
Output is correct |
2 |
Correct |
105 ms |
31568 KB |
Output is correct |
3 |
Correct |
102 ms |
31532 KB |
Output is correct |
4 |
Correct |
116 ms |
29220 KB |
Output is correct |
5 |
Correct |
103 ms |
30800 KB |
Output is correct |
6 |
Correct |
96 ms |
29564 KB |
Output is correct |
7 |
Correct |
98 ms |
30696 KB |
Output is correct |
8 |
Correct |
95 ms |
29460 KB |
Output is correct |
9 |
Correct |
100 ms |
29196 KB |
Output is correct |
10 |
Correct |
101 ms |
31596 KB |
Output is correct |
11 |
Correct |
97 ms |
30036 KB |
Output is correct |
12 |
Correct |
100 ms |
31224 KB |
Output is correct |
13 |
Correct |
99 ms |
29576 KB |
Output is correct |
14 |
Correct |
99 ms |
31160 KB |
Output is correct |
15 |
Correct |
100 ms |
31204 KB |
Output is correct |
16 |
Correct |
94 ms |
29288 KB |
Output is correct |
17 |
Correct |
99 ms |
30548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
29520 KB |
Output is correct |
2 |
Correct |
105 ms |
31568 KB |
Output is correct |
3 |
Correct |
102 ms |
31532 KB |
Output is correct |
4 |
Correct |
116 ms |
29220 KB |
Output is correct |
5 |
Correct |
103 ms |
30800 KB |
Output is correct |
6 |
Correct |
96 ms |
29564 KB |
Output is correct |
7 |
Correct |
98 ms |
30696 KB |
Output is correct |
8 |
Correct |
95 ms |
29460 KB |
Output is correct |
9 |
Correct |
100 ms |
29196 KB |
Output is correct |
10 |
Correct |
101 ms |
31596 KB |
Output is correct |
11 |
Correct |
97 ms |
30036 KB |
Output is correct |
12 |
Correct |
100 ms |
31224 KB |
Output is correct |
13 |
Correct |
99 ms |
29576 KB |
Output is correct |
14 |
Correct |
99 ms |
31160 KB |
Output is correct |
15 |
Correct |
100 ms |
31204 KB |
Output is correct |
16 |
Correct |
94 ms |
29288 KB |
Output is correct |
17 |
Correct |
99 ms |
30548 KB |
Output is correct |
18 |
Correct |
194 ms |
29776 KB |
Output is correct |
19 |
Correct |
213 ms |
33248 KB |
Output is correct |
20 |
Correct |
102 ms |
33364 KB |
Output is correct |
21 |
Correct |
129 ms |
31336 KB |
Output is correct |
22 |
Correct |
150 ms |
31700 KB |
Output is correct |
23 |
Correct |
102 ms |
31500 KB |
Output is correct |
24 |
Correct |
191 ms |
31964 KB |
Output is correct |
25 |
Correct |
104 ms |
31164 KB |
Output is correct |
26 |
Correct |
190 ms |
31568 KB |
Output is correct |
27 |
Correct |
199 ms |
33620 KB |
Output is correct |
28 |
Correct |
155 ms |
31572 KB |
Output is correct |
29 |
Correct |
176 ms |
32884 KB |
Output is correct |
30 |
Correct |
130 ms |
31312 KB |
Output is correct |
31 |
Correct |
129 ms |
33252 KB |
Output is correct |
32 |
Correct |
113 ms |
33100 KB |
Output is correct |
33 |
Correct |
187 ms |
30764 KB |
Output is correct |
34 |
Correct |
128 ms |
32596 KB |
Output is correct |