답안 #673096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673096 2022-12-19T15:09:17 Z ghostwriter Balloons (CEOI11_bal) C++17
100 / 100
262 ms 35980 KB
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
    #include <debug.h>
#else
    #define debug(...)
#endif
#define ft front
#define bk back
#define st first
#define nd second
#define ins insert
#define ers erase
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define bg begin
#define ed end
#define all(x) (x).bg(), (x).ed()
#define sz(x) (int)(x).size()
// #define int long long
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
#define FOR(i, l, r) for (int i = (l); i <= (r); ++i)
#define FOS(i, r, l) for (int i = (r); i >= (l); --i)
#define FRN(i, n) for (int i = 0; i < (n); ++i)
#define FSN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define EACH(i, x) for (auto &i : (x))
#define WHILE while
template<typename T> T gcd(T a, T b) { T d2 = (a | b) & -(a | b); a /= d2; b /= d2; WHILE(b) { a = a % b; swap(a, b); } return a * d2; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
void _assert(bool statement) { if (statement) return; cerr << "\n>> Assertion failed!\n"; exit(0); }
void _assert(bool statement, const str &message) { if (statement) return; cerr << "\n>> Assertion failed: " << message << '\n'; exit(0); }
void _error(const str &message) { cerr << "\n>> Error: " << message << '\n'; exit(0); }
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Tran The Bao - ghostwriter
    Training for VOI23 gold medal
----------------------------------------------------------------
    GOAT
----------------------------------------------------------------
*/
struct Point {
	ldb x, y;
	Point() {}
	Point(ldb x, ldb y) : x(x), y(y) {}
};
const int N = 2e5 + 5;
const int T = 8e5 + 5;
const ldb eps = 1e-6;
const ldb oo = sqrt(1e9) + 1;
int n, x[N], r[N], x1[N];
ldb ans[N];
Point tr[T];
void input(int test_id) {
	cin >> n;
	FOR(i, 1, n) {
		cin >> x[i] >> r[i];
		x1[i] = x[i];
	}
	sort(x1 + 1, x1 + 1 + n);
}
ldb f(const Point &a, ldb x) { return a.x * x + a.y; }
void upd(int i, int l, int r, Point v) {
	int mid = l + (r - l) / 2, lv = x1[l], mv = x1[mid];
	if (f(v, lv) < f(tr[i], lv)) swap(tr[i], v);
	if (l == r) return;
	if (f(tr[i], mv) < f(v, mv)) upd(i * 2 + 1, mid + 1, r, v);
	else {
		swap(tr[i], v);
		upd(i * 2, l, mid, v);
	}
}
ldb get(int i, int l, int r, int v) {
	ldb rs = f(tr[i], x1[v]);
	if (l == r) return rs;
	int mid = l + (r - l) / 2;
	if (v <= mid) rs = min(rs, get(i * 2, l, mid, v));
	else rs = min(rs, get(i * 2 + 1, mid + 1, r, v));
	return rs;
}
int getp(int v) { return lb(x1 + 1, x1 + 1 + n, v) - x1; }
void upd(int pos) {
	ldb tmp = sqrt((ldb)ans[pos]);
	tmp = max(tmp, (ldb)1 / oo);
	upd(1, 1, n, Point((ldb)0.5 / tmp, (ldb)-0.5 * x[pos] / tmp));
}
void solve(int test_id) {
	FOR(i, 1, n << 2) tr[i] = Point(0, oo + 1);
	ans[1] = r[1];
	upd(1);
	FOR(i, 2, n) {
		int cpos = getp(x[i]);
		ans[i] = min(sqrt((ldb)r[i]), get(1, 1, n, cpos));
		ans[i] *= ans[i];
		upd(i);
	}
	FOR(i, 1, n) cout << setprecision(3) << fixed << ans[i] << '\n';
}
void reinit(int test_id) {

}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);
    int test_num = 1;
    // cin >> test_num; // comment if the problem does not requires multitest
    FOR(i, 1, test_num) {
        input(i); // input in noninteractive problems for case #i
        solve(i); // main function to solve case #i
        reinit(i); // reinit global data to default used in case #i
    }
    #ifdef LOCAL
        cerr << "\nTime: " << setprecision(5) << fixed << (ldb)clock() / CLOCKS_PER_SEC << "ms.\n";
    #endif
    return 0;
}
/*
----------------------------------------------------------------
From Benq:
    stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * DON'T GET STUCK ON ONE APPROACH
----------------------------------------------------------------
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB 10 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB 2 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB 505 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB 2000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 3768 KB 20000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 9060 KB 50000 numbers
2 Correct 58 ms 9216 KB 49912 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 17828 KB 100000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 20580 KB 115362 numbers
2 Correct 140 ms 21684 KB 119971 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 206 ms 27516 KB 154271 numbers
2 Correct 237 ms 35916 KB 200000 numbers
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 35032 KB 200000 numbers
2 Correct 240 ms 35980 KB 199945 numbers