Submission #649969

#TimeUsernameProblemLanguageResultExecution timeMemory
649969ymmBalloons (CEOI11_bal)C++17
90 / 100
431 ms2212 KiB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

typedef pair<double, double> pdd;

pdd in()
{
	ll x, y;
	cin >> x >> y;
	return {x, y};
}

const int N = 200'010;
const int S = 8192;

double a[N], b[N];
double x[N], r[N];
double x_off = 0;
int len = 0;

void insert(pdd f)
{
	a[len] = f.first;
	b[len] = f.second;
	++len;
}

__attribute__((optimize("Ofast,unroll-loops"),target("avx2,fma")))
double get(double x)
{
	#define MIN(x, y) ((x)>(y)?(y):(x))
	double ans = 1e30;
	Loop (i,0,len) {
		double tmp = a[i]*x + b[i];
		ans = MIN(ans, tmp);
	}
	return ans;
	#undef MIN
}

double eval(pdd f, double x)
{
	return f.first * x + f.second;
}

void trim(double x)
{
	static pdd f[N];
	Loop (i,0,len)
		f[i] = {a[i], b[i]};
	sort(f, f+len);
	reverse(f, f+len);
	int j = 0;
	Loop (i,0,len) {
		while (j && eval(f[j-1], x) >= eval(f[i], x))
			--j;
		f[j++] = f[i];
	}
	len = j;
	Loop (i,0,len) {
		f[i].second = eval(f[i], x);
		tie(a[i], b[i]) = f[i];
	}
	x_off += x;
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cout << fixed << setprecision(3);
	int n;
	cin >> n;
	for (int s = 0; s < n; s += S) {
		int f = min(s+S, n);
		Loop (i,s,f) {
			auto [x, r] = in();
			x -= x_off;
			if (i == s) {
				trim(x);
				x = 0;
			}
			r = sqrt(r);
			r = min(r, get(x));
			cout << r*r << '\n';
			insert({0.5/r, -x*0.5/r});
		}
	}
}
#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...