#include <bits/stdc++.h>
using namespace std;
set<pair<double, int>> steigungen;
set<pair<double, int>> endpunkt;
vector<double> ende;
vector<double> steigung;
double max_r(double r1, double x1, double x2){
return ((x1-x2) * (x1-x2)) / (4 * r1);
}
long long find_interval(double x1){
pair<int, int> interval = *lower_bound(endpunkt.begin(), endpunkt.end(), make_pair(x1, 0));
return interval.second;
}
double schnittstelle(double a1, double b1, double a2, double b2){
double a = b2 - b1;
double b = 2*a2*b1 - 2*a1*b2;
double c = b2*a1*a1 - b1*a2*a2;
//cout << "a, b, c: " << a << " " << b << " " << c << endl;
double radikand = sqrt(b*b - 4.0 * a * c);
//cout << radikand << endl;
double x1 = (-b + radikand) / (2 * a);
double x2 = (-b - radikand) / (2 * a);
return max(x1, x2);
}
void del(long long idx){
//cout << "del: " << idx << endl;
//for (auto x : endpunkt) cout << x.first << " " << x.second << endl;
///cout << "steigung: " << endl;
//for (auto x : steigungen) cout << x.first << " " << x.second << endl;
//cout << ende[idx] << endl;
//cout << steigung[idx] << endl;
endpunkt.erase(endpunkt.find(make_pair(ende[idx], idx)));
//cout << "test" << endl;
steigungen.erase(steigungen.find(make_pair(steigung[idx], idx)));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
long long n; cin >> n;
vector<double> x(n), r(n);
for (long long i=0; i<n; i++){
cin >> x[i] >> r[i];
}
vector<double> res(n);
res[0] = r[0];
//long long last_idx = 0;
ende.resize(n);
steigung.resize(n);
ende[0] = 1e9;
steigung[0] = res[0]*4;
steigungen.insert(make_pair(4*res[0], 0));
endpunkt.insert(make_pair(1e9, 0));
for (long long i=1; i<n; i++){
//cout << "i: " << i << endl;
//for (auto x : endpunkt) cout << x.first << " " << x.second << endl;
long long idx = find_interval(x[i]);
//cout << "idx: " << idx << endl;
res[i] = min(max_r(res[idx], x[idx], x[i]), (double)r[i]);
//cout << "radius: " << res[i] << endl;
//steigungen.erase(steigungen.end(), steigungen.upper_bound({4.0 * res[i], 0}));
steigung[i] = res[i] * 4.0;
// alle steileren aus steigungen UND endpunkten löschen
//cout << steigungen.size() << " " << endpunkt.size() << endl;
while(steigungen.size() > 0 && (*steigungen.begin()).first <= steigung[i]){
//cout << steigungen.size() << " " << endpunkt.size() << endl;
long long idx2 = (*steigungen.begin()).second;
del(idx2);
//cout << steigungen.size() << " " << endpunkt.size() << endl;
}
//cout << steigungen.size() << " " << endpunkt.size() << endl;
if(steigungen.size() == 0){
steigungen.insert(make_pair(res[i]*4.0, i));
endpunkt.insert(make_pair(1e9, i));
ende[i] = 1e9;
continue;
}
idx = find_interval(x[i]);
//cout << x[idx] << " " << steigung[idx] << " " << x[i] << " " << steigung[i] << endl;
double s = schnittstelle(x[idx], steigung[idx], x[i], steigung[i]);
//cout << "s: " << s << endl;
auto interval = lower_bound(endpunkt.begin(), endpunkt.end(), make_pair(x[i], 0));
//cout << steigungen.size() << " " << endpunkt.size() << endl;
while(s > (*interval).first){
long long idx2 = (*interval).second;
interval++;
del(idx2);
idx2 = (*interval).second;
s = schnittstelle(x[idx2], steigung[idx2], x[i], steigung[i]);
if (s >= 1e9){
endpunkt.clear();
steigung.clear();
break;
}
}
//cout << steigungen.size() << " " << endpunkt.size() << endl;
ende[i] = s;
endpunkt.insert(make_pair(ende[i], i));
steigungen.insert(make_pair(steigung[i], i));
}
//for (auto x : endpunkt) cout << x.first << " " << x.second << endl;
for (double a : res) cout << fixed << setprecision(3) << a << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |