This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
using namespace std;
///~~~~~~~~~~~~~~~~~~~~~~~~~~
template <typename H, typename T>
ostream& operator<<(ostream& os, pair<H, T> m){
return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H>
ostream& operator<<(ostream& os, vector<H> V){
os<<"{";
for(int i=0; i<V.size(); i++){
if(i)os<<" ";
os<<V[i];
}
os<<"}";
return os;
}
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
///~~~~~~~~~~~~~~~~~~~~~~~~~
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=2e5+5, mod=1e9+7;
const ld INF=1e9, EPS=1e-6;
struct line{
ld a, b;
line(ld a, ld b): a(a), b(b){}
ld isect(line L){
return (b-L.b)/(L.a-a);
}
ld val(ld x){return a*x+b;}
};
struct node{
node *L=nullptr, *R=nullptr;
line li=line(0, INF);
ld l=0, r=INF;
node(ld l, ld r): l(l), r(r){}
vector<pair<line, pair<ld, ld> > > todo;
void insert(line li2, ld l1, ld r1){
//deb(l, r, li.a, li.b);
//deb(l1, r1, li2.a, li2.b);
if(r1<l1+EPS)return;
if(li2.val(l)>li.val(l)-EPS && li2.val(r)>li.val(r)-EPS)return;
//deb("a");
if(l1==l && r1==r && li2.val(l)<li.val(l) && li2.val(r)<li.val(r)){
li=li2;
return;
}
ld m=(l+r)/2;
if(L==nullptr){
L=new node(l, m);
R=new node(m, r);
}
if(l1<=m)L->todo.pb({li2, {l1, min(r1, m)}});
if(r1>=m)R->todo.pb({li2, {max(l1, m), r1}});
return;
}
ld val(ld x){
ld ans=li.val(x);
if(todo.size()<200){
for(auto &i:todo){
if(x>=i.nd.st-EPS && x<=i.nd.nd+EPS)ans=min(ans, i.st.val(x));
}
}
else{
for(auto i:todo){
insert(i.st, i.nd.st, i.nd.nd);
}
todo.clear();
}
ans=min(ans, li.val(x));
ld m=(l+r)/2;
if(x<m && L)ans=min(ans, L->val(x));
else{
if(R)ans=min(ans, R->val(x));
}
return ans;
}
};
int main(){
//BOOST;
int n;
cin>>n;
node *root=new node(0, INF);
for(int i=0; i<n; i++){
int x, r;
cin>>x>>r;
ld r2=root->val(x);
r2=min(r2*r2, ld(r));
cout<<fixed<<setprecision(3)<<r2<<"\n";
if(r2>EPS){
root->insert(line(-1/ld(2*sqrt(r2)), x/ld(2*sqrt(r2))), 0, x);
root->insert(line(1/ld(2*sqrt(r2)), -x/ld(2*sqrt(r2))), x, INF);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |