#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
/*const int MOD = ;
inline int lgput(int a, int b) {
int ans = 1;
while(b > 0) {
if(b & 1) ans = (1LL * ans * a) % MOD;
b >>= 1;
a = (1LL * a * a) % MOD;
}
return ans;
}
inline void mod(int &x) {
if(x >= MOD)
x -= MOD;
}
inline void add(int &x, int y) {
x += y;
mod(x);
}
inline void sub(int &x, int y) {
x += MOD - y;
mod(x);
}
inline void mul(int &x, int y) {
x = (1LL * x * y) % MOD;
}
inline int inv(int x) {
return lgput(x, MOD - 2);
}*/
/*int fact[], invfact[];
inline void prec(int n) {
fact[0] = 1;
for(int i = 1; i <= n; i++) {
fact[i] = (1LL * fact[i - 1] * i) % MOD;
}
invfact[n] = lgput(fact[n], MOD - 2);
for(int i = n - 1; i >= 0; i--) {
invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
}
}
inline int comb(int n, int k) {
if(n < k) return 0;
return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/
using namespace std;
const double eps = 1e-4;
const int MAXN = (int) 2e5;
double cx[MAXN + 1], cy[MAXN + 1];
inline bool inter(double xa, double ya, double xb, double yb) {
return (xa - xb) * (xa - xb) - 4 * ya * yb < 0;
}
struct SegTree {
struct Data {
int pos;
bool operator <(const Data &other) const {
return cx[pos] + cy[pos] - cx[other.pos] - cy[other.pos] >= 0;
}
};
struct Node {
int st, dr;
set <Data> mst;
Node() {
st = dr = -1;
}
};
vector <Node> aint;
inline void init() {
aint.resize(1);
}
inline void fix(int &x) {
if(x == -1) {
x = aint.size();
aint.push_back(Node());
}
}
void update(int nod, double left, double right, int pos) {
if(right - left < eps) { return ; }
aint[nod].mst.insert({pos});
fix(aint[nod].st);
fix(aint[nod].dr);
double mid = (left + right) * 0.5;
if(mid - (cx[pos] - cy[pos]) >= 0) update(aint[nod].st, left, mid, pos);
else update(aint[nod].dr, mid, right, pos);
}
bool query(int nod, double left, double right, int pos) {
if(right - left < eps) return 0;
if(cx[pos] + cy[pos] - right >= 0) {
auto it = aint[nod].mst.begin();
while(it != aint[nod].mst.end() && cx[it -> pos] + cy[it -> pos] >= cx[pos] - cy[pos]) {
if(inter(cx[pos], cy[pos], cx[it -> pos], cy[it -> pos])) {
return 1;
}
it = next(it);
}
return 0;
}
double mid = (left + right) * 0.5;
bool ans = 0;
if(aint[nod].st != -1) ans |= query(aint[nod].st, left, mid, pos);
if(aint[nod].dr != -1 && cx[pos] + cy[pos] - mid > 0) ans |= query(aint[nod].dr, mid, right, pos);
return ans;
}
};
int main() {
#if 0
ifstream cin("A.in");
ofstream cout("A.out");
#endif
int i, n;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n;
SegTree st; st.init();
for(i = 1; i <= n; i++) {
double r;
cin >> cx[i] >> r;
cx[i] += 1e9;
double l = 0;
while(r - l > eps) {
double mid = (l + r) * 0.5;
cy[i] = mid;
if(st.query(0, 0, 2e9, i) == 0) {
l = mid;
}
else {
r = mid;
}
}
cy[i] = (l + r) * 0.5;
st.update(0, 0, 2e9, i);
cout << fixed << setprecision(10) << cy[i] << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
10 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
2 numbers |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
3148 KB |
345th numbers differ - expected: '215.0530000000', found: '215.0503585339', error = '0.0026414661' |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
10688 KB |
1777th numbers differ - expected: '385.5980000000', found: '385.5999499559', error = '0.0019499559' |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
250 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
199 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
221 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
213 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
254 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |