#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0);
#define FILE freopen("test.in", "r", stdin);
#define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";}
#define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;}
#define debug cout << "-----------------------------------------------" << endl;
#define print1(a) cout << "{ " << a << " }" << endl;
#define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl;
#define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl;
#define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl;
using namespace std;
#define int long long
#define double long double
const double INF = 1e11 + 228;
const int MAXN = 2e5 + 228;
double ans[MAXN];
const double eps = 1e-13;
const double eps2 = 0;
double intersect1(double x1, double x2, double t1, double t2) {
//print4(x1, x2, t1, (((x2 / (2 * t2)) - (x1 / (2 * t1))) * 2 * t1 * t2) / (t1 - t2));
return ((((x2 / (2 * t2)) - (x1 / (2 * t1))) * 2 * t1 * t2) / (t1 - t2));
}
double get(pair<double, double> to, double h) {
double xx = (to.S / (4 * to.F)) * to.S - ((2.0 * to.S) / (4 * to.F)) * h + ((h / (4 * to.F)) * h);
return xx;//(to.S * to.S + h * h - 2.0 * h * to.S) / (4 * to.F);// + (h * h) / (4 * to.F) - (2 * h * to.S) / (4 * to.F);
}
double sqr(double x) {
double l = 0, r = 1e9 + 1;
while (r - l > eps) {
double mid = (l + r) / 2;
if (mid * mid > x) {
r = mid;
} else {
l = mid;
}
}
return l;
}
signed main()
{
#ifdef LOCAL
FILE;
#endif
sh;
int n;
cin >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
int aa, bb;
cin >> aa >> bb;
v.pb({aa, bb});
}
vector<pair<double, double>> s;
vector<double> x1;
for (int i = 0; i < n; i++) {
double now = v[i].S;
//print1(i);
while (x1.size() > 0 && x1.back() <= (double)v[i].F) {
x1.pop_back();
s.pop_back();
}
int id = x1.size();//upper_bound(all(x1), (double)v[i].F) - x1.begin();
//print2(i, id);
/*for (auto oo : s) {
cout << oo.S << ' ';
}
cout << endl;*/
if (s.size() > 0) {
assert((int)(s.size()) - id - 1 >= 0);
//print4("t", s.size(), id, x1.size());
pair<double, double> to = s[id];
double cl = get(to, v[i].F);
now = min(now, cl);
}
while (s.size() > 0 && s.back().F <= now) {
s.pop_back();
}
while (x1.size() + 1 > s.size() && s.size() != 0) {
x1.pop_back();
}
if (s.size() == 0) {
x1.clear();
}
while (s.size() >= 2 && get(s.back(), intersect1(s.back().S, (double)v[i].F, sqr(s.back().F), sqr(now))) >= get(s[s.size() - 2], intersect1(s.back().S, (double)v[i].F, sqr(s.back().F), sqr(now))) /*intersect1(s[s.size() - 2].S, s.back().S, sqr(s[s.size() - 2].F), sqr(s.back().F))*/) {
s.pop_back();
x1.pop_back();
}
ans[i] = now;
//print1(now);
if (s.size() > 0) {
x1.pb(intersect1(s.back().S, (double)v[i].F, sqr(s.back().F), sqr(now)));
}
//print1("ok");
s.pb({now, (double)v[i].F});
}
for (int i = 0; i < n; i++) {
cout << fixed << setprecision(5) << ans[i] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
10 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
2 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
376 KB |
505 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
504 KB |
2000 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
1604 KB |
20000 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
350 ms |
3312 KB |
14044th numbers differ - expected: '0.4860000000', found: '0.4882800000', error = '0.0022800000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
848 ms |
5948 KB |
14857th numbers differ - expected: '7169.6020000000', found: '7169.5856900000', error = '0.0163100000' |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
996 ms |
6484 KB |
17577th numbers differ - expected: '0.4600000000', found: '0.4580100000', error = '0.0019900000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1436 ms |
8420 KB |
12335th numbers differ - expected: '4957.2960000000', found: '4957.3015800000', error = '0.0055800000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1409 ms |
10000 KB |
23259th numbers differ - expected: '2317.1810000000', found: '2317.1789600000', error = '0.0020400000' |
2 |
Halted |
0 ms |
0 KB |
- |