Submission #897273

# Submission time Handle Problem Language Result Execution time Memory
897273 2024-01-02T20:45:58 Z FanOfWilliamLin Balloons (CEOI11_bal) C++14
100 / 100
149 ms 7096 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()

ll FIRSTTRUE(function<bool(ll)> f, ll lb, ll rb) {
	while(lb<rb) {
		ll mb=(lb+rb)/2;
		f(mb)?rb=mb:lb=mb+1; 
	} 
	return lb;
}
ll LASTTRUE(function<bool(ll)> f, ll lb, ll rb) {
	while(lb<rb) {
		ll mb=(lb+rb+1)/2;
		f(mb)?lb=mb:rb=mb-1; 
	} 
	return lb;
}

const ll INF=1000000000000000000LL;
const ll MOD=1e9+7;
//const ll MOD=998244353; //sometimes need to be used

ll bpow(ll a, ll b) {
	a%=MOD;
	ll res=1;
	while(b>0) {
		if(b&1)
			res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int gcd_x, gcd_y, gcd_d;

int gcd(int a, int b) {
	if (!b) {
        gcd_x=1;
        gcd_y=0;
        return a;
    }
    gcd_d=gcd(b, a%b);
	int tmp=gcd_x;
	gcd_x=gcd_y;
	gcd_y=tmp-(a/b)*gcd_y;
    return gcd_d;
}

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

double calc_r(pair<double, double> a, double bx) {
	return (a.first-bx)*(a.first-bx)/(4*a.second);
}

void solve() {
	//solve here
	int n;
	cin >> n;
	vt<double> ans(n);
	stack<pair<double, double>> st;	
	for(int i=0; i<n; ++i) {
		double x, r;
		cin >> x >> r;
		double mx_r=r;
		while(!st.empty()) {
			pair<double, double> last=st.top();
			double to_last_r=calc_r(last, x);
			mx_r=min(mx_r, to_last_r);
			if(mx_r>=last.second) {
				st.pop();
				continue;
			}
			else {
				break;
			}
		}
		st.push({x, mx_r});
		ans[i]=mx_r;
	}	
	cout << fixed << setprecision(3);
	for(auto& a: ans) {
		cout << a << "\n";
	}
}
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("template.inp", "r", stdin);
	//freopen("template.out", "w", stdout);	

	int TC=1;
	//cin >> TC;
	while(TC--) {
		solve();
	}
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB 10 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB 2 numbers
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB 505 numbers
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB 2000 numbers
# Verdict Execution time Memory Grader output
1 Correct 15 ms 860 KB 20000 numbers
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2136 KB 50000 numbers
2 Correct 36 ms 2012 KB 49912 numbers
# Verdict Execution time Memory Grader output
1 Correct 98 ms 3776 KB 100000 numbers
# Verdict Execution time Memory Grader output
1 Correct 92 ms 4180 KB 115362 numbers
2 Correct 88 ms 4484 KB 119971 numbers
# Verdict Execution time Memory Grader output
1 Correct 119 ms 5208 KB 154271 numbers
2 Correct 140 ms 7096 KB 200000 numbers
# Verdict Execution time Memory Grader output
1 Correct 149 ms 6132 KB 200000 numbers
2 Correct 140 ms 6992 KB 199945 numbers