Submission #142989

#TimeUsernameProblemLanguageResultExecution timeMemory
142989popovicirobertBalloons (CEOI11_bal)C++14
20 / 100
189 ms65540 KiB
#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-3; 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) + (ya - yb) * (ya - yb) <= (ya + yb) * (ya + yb); } struct SegTree { struct Data { int pos; bool operator <(const Data &other) const { double a = cx[pos] + cy[pos], b = cx[other.pos] + cy[other.pos]; if(a - b == 0) return pos < other.pos; return a - b < 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, double x, double y) { if(right - left < eps) return 0; if(x - y - right >= 0) { auto it = aint[nod].mst.end(); while(it != aint[nod].mst.begin()) { it = prev(it); if(cx[it -> pos] + cy[it -> pos] < x - y) { return 0; } if(inter(x, y, cx[it -> pos], cy[it -> pos])) { return 1; } } return 0; } fix(aint[nod].st); fix(aint[nod].dr); double mid = (left + right) * 0.5; bool ans = 0; ans |= query(aint[nod].st, left, mid, x, y); if(x - y - mid > 0) ans |= query(aint[nod].dr, mid, right, x, y); 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, cx[i], cy[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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...