#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 long double eps = 1e-4;
const int MAXN = (int) 2e5;
long double cx[MAXN + 1], cy[MAXN + 1];
inline bool inter(long double xa, long double ya, long double xb, long double yb) {
return (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb) < (ya + yb) * (ya + yb);
}
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, long double left, long 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, long double left, long 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++) {
long double r;
cin >> cx[i] >> r;
cx[i] += 1e9;
long double l = 0;
while(r - l > eps) {
long 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(3) << cy[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
10 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
2 numbers |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
3148 KB |
15th numbers differ - expected: '0.8630000000', found: '8957.0000000000', error = '8956.1370000000' |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
10812 KB |
14th numbers differ - expected: '108.0020000000', found: '762.0000000000', error = '653.9980000000' |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
401 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
299 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
330 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
324 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
326 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
378 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |