#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct node{
ll pref, suf, inf, sum;
};
constexpr int BASE = 1<<18;
constexpr ll oo = 1e16;
node TREE[BASE<<1];
pair<ll, int> Queries[BASE];
int who[BASE];
vector<pair<ll, int>> event;
set<int> S;
ll n, m, D;
void update(int v, ll val){
v+=BASE;
TREE[v].pref = TREE[v].suf = TREE[v].inf = TREE[v].sum = val;
v/=2;
while(v>0){
int l = 2*v, r = 2*v+1;
TREE[v].pref = max(TREE[l].pref, TREE[l].sum+TREE[r].pref);
TREE[v].suf = max(TREE[r].suf, TREE[l].suf+TREE[r].sum);
TREE[v].sum = TREE[l].sum + TREE[r].sum;
TREE[v].inf = max({TREE[l].inf, TREE[r].inf, TREE[l].suf+TREE[r].pref});
v/=2;
}
}
void compute(){
sort(event.begin(), event.end());
int pos = 0;
for(auto [a, i] : event){
Queries[i] = {a, ++pos};
who[pos] = i;
}
who[BASE-1] = BASE-1;
Queries[BASE-1] = {oo, BASE-1};
S.insert((BASE-1));
}
void add(pair<ll, int> x){
auto it = S.lower_bound(x.second);
update(x.second, x.first - Queries[who[*it]].first + D);
if(it != S.begin()){
it--;
update(Queries[who[*it]].second, Queries[who[*it]].first - x.first + D);
}
S.insert(x.second);
}
void quer(){
ll out = 0;
out = max({TREE[1].pref, TREE[1].suf, TREE[1].inf, TREE[1].sum});
cout << (out/2);
if(out&1) cout << ".5";
cout << " ";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> D;
for(int i = 1; i <= n+m; i++){
ll a;
cin >> a;
event.push_back({a, i});
}
compute();
for(int i = 1; i <= n; i++)
add(Queries[i]);
for(int i = n+1; i <= n+m; i++){
add(Queries[i]);
quer();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10844 KB |
Output is correct |
7 |
Correct |
2 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10840 KB |
Output is correct |
2 |
Correct |
2 ms |
10844 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
2 ms |
10844 KB |
Output is correct |
5 |
Correct |
3 ms |
10844 KB |
Output is correct |
6 |
Correct |
2 ms |
10844 KB |
Output is correct |
7 |
Correct |
2 ms |
10844 KB |
Output is correct |
8 |
Correct |
2 ms |
10844 KB |
Output is correct |
9 |
Correct |
221 ms |
35808 KB |
Output is correct |
10 |
Correct |
227 ms |
36056 KB |
Output is correct |
11 |
Correct |
123 ms |
35516 KB |
Output is correct |
12 |
Correct |
131 ms |
35460 KB |
Output is correct |
13 |
Correct |
108 ms |
35024 KB |
Output is correct |
14 |
Correct |
110 ms |
35592 KB |
Output is correct |
15 |
Correct |
216 ms |
34780 KB |
Output is correct |
16 |
Correct |
112 ms |
35520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
34684 KB |
Output is correct |
2 |
Correct |
124 ms |
37056 KB |
Output is correct |
3 |
Correct |
147 ms |
38328 KB |
Output is correct |
4 |
Correct |
124 ms |
36280 KB |
Output is correct |
5 |
Correct |
129 ms |
37544 KB |
Output is correct |
6 |
Correct |
121 ms |
36800 KB |
Output is correct |
7 |
Correct |
123 ms |
38204 KB |
Output is correct |
8 |
Correct |
120 ms |
37160 KB |
Output is correct |
9 |
Correct |
129 ms |
36880 KB |
Output is correct |
10 |
Correct |
154 ms |
39588 KB |
Output is correct |
11 |
Correct |
133 ms |
37180 KB |
Output is correct |
12 |
Correct |
152 ms |
38168 KB |
Output is correct |
13 |
Correct |
123 ms |
37012 KB |
Output is correct |
14 |
Correct |
122 ms |
38128 KB |
Output is correct |
15 |
Correct |
133 ms |
38080 KB |
Output is correct |
16 |
Correct |
132 ms |
35776 KB |
Output is correct |
17 |
Correct |
133 ms |
38560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
34684 KB |
Output is correct |
2 |
Correct |
124 ms |
37056 KB |
Output is correct |
3 |
Correct |
147 ms |
38328 KB |
Output is correct |
4 |
Correct |
124 ms |
36280 KB |
Output is correct |
5 |
Correct |
129 ms |
37544 KB |
Output is correct |
6 |
Correct |
121 ms |
36800 KB |
Output is correct |
7 |
Correct |
123 ms |
38204 KB |
Output is correct |
8 |
Correct |
120 ms |
37160 KB |
Output is correct |
9 |
Correct |
129 ms |
36880 KB |
Output is correct |
10 |
Correct |
154 ms |
39588 KB |
Output is correct |
11 |
Correct |
133 ms |
37180 KB |
Output is correct |
12 |
Correct |
152 ms |
38168 KB |
Output is correct |
13 |
Correct |
123 ms |
37012 KB |
Output is correct |
14 |
Correct |
122 ms |
38128 KB |
Output is correct |
15 |
Correct |
133 ms |
38080 KB |
Output is correct |
16 |
Correct |
132 ms |
35776 KB |
Output is correct |
17 |
Correct |
133 ms |
38560 KB |
Output is correct |
18 |
Correct |
285 ms |
36784 KB |
Output is correct |
19 |
Correct |
232 ms |
38336 KB |
Output is correct |
20 |
Correct |
144 ms |
38592 KB |
Output is correct |
21 |
Correct |
134 ms |
36836 KB |
Output is correct |
22 |
Correct |
201 ms |
36800 KB |
Output is correct |
23 |
Correct |
145 ms |
37148 KB |
Output is correct |
24 |
Correct |
261 ms |
37056 KB |
Output is correct |
25 |
Correct |
119 ms |
36292 KB |
Output is correct |
26 |
Correct |
245 ms |
37084 KB |
Output is correct |
27 |
Correct |
262 ms |
38844 KB |
Output is correct |
28 |
Correct |
214 ms |
37116 KB |
Output is correct |
29 |
Correct |
212 ms |
37968 KB |
Output is correct |
30 |
Correct |
158 ms |
36600 KB |
Output is correct |
31 |
Correct |
139 ms |
38820 KB |
Output is correct |
32 |
Correct |
162 ms |
38020 KB |
Output is correct |
33 |
Correct |
254 ms |
37060 KB |
Output is correct |
34 |
Correct |
146 ms |
38400 KB |
Output is correct |