Submission #653372

#TimeUsernameProblemLanguageResultExecution timeMemory
653372AntekbBalloons (CEOI11_bal)C++14
70 / 100
2066 ms65536 KiB
#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 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-4; 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;} }; vi L, R; vector<line> lines; vector<int> li; vector<ld> l, r; vector<vector<pair<int, pair<ld, ld> > > > todo; void insert(int v, int 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(lines[li2].val(l[v])>lines[li[v]].val(l[v])-EPS && lines[li2].val(r[v])>lines[li[v]].val(r[v])-EPS)return; //deb("a"); if(l1==l[v] && r1==r[v] && lines[li2].val(l[v])<lines[li[v]].val(l[v]) && lines[li2].val(r[v])<lines[li[v]].val(r[v])){ li[v]=li2; return; } ld m=(l[v]+r[v])/2; if(!L[v]){ L[v]=L.size(); L.pb(0), R.pb(0); l.pb(l[v]); r.pb(m); todo.pb({}); li.pb(0); R[v]=L.size(); L.pb(0), R.pb(0); r.pb(r[v]); l.pb(m); todo.pb({}); li.pb(0); } if(l1<=m)todo[L[v]].pb({li2, {l1, min(r1, m)}}); if(r1>=m)todo[R[v]].pb({li2, {max(l1, m), r1}}); return; } ld val(int v, ld x){ ld ans=lines[li[v]].val(x); if(todo[v].size()<5000){ for(auto &i:todo[v]){ if(x>=i.nd.st-EPS && x<=i.nd.nd+EPS)ans=min(ans, lines[i.st].val(x)); } } else{ for(auto &i:todo[v]){ insert(v, i.st, i.nd.st, i.nd.nd); } todo[v].clear(); } ans=min(ans, lines[li[v]].val(x)); ld m=(l[v]+r[v])/2; if(x<m && L[v])ans=min(ans, val(L[v], x)); else{ if(R[v])ans=min(ans, val(R[v], x)); } return ans; } /*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()<500){ 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; int root=0; L.pb(0), R.pb(0); l.pb(0); r.pb(INF); todo.pb({}); li.pb(0); lines.pb(line(0, INF)); for(int i=0; i<n; i++){ int x, rr; cin>>x>>rr; ld r2=val(root, x); r2=min(r2*r2, ld(rr)); cout<<fixed<<setprecision(3)<<r2<<"\n"; if(r2>EPS){ lines.pb(line(-1/ld(2*sqrt(r2)), x/ld(2*sqrt(r2)))); insert(root, lines.size()-1, 0, x); lines.pb(line(1/ld(2*sqrt(r2)), -x/ld(2*sqrt(r2)))); insert(root, lines.size()-1, x, INF); } } }
#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...