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>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef tree<
ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define db double
#define pii pair<ll,ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b,c) for(ll i=a;i<b;i+=c)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define fri(i,a,b,c) for(ll i=a;i>=b;i-=c)
#define pb push_back
#define ss second
#define ff first
#define in insert
#define sq(x) (x*x)
#define all(a) a.begin(),a.end()
#define nl '\n'
#define npii pair<ll,pair<ll,ll>>
#define mnpq priority_queue <npii, vector<npii>, greater<npii> >
ll gcd(ll a,ll b){
if(b==0)return a;
return gcd(b,a%b);
}
int getRandom(int L,int R)
{
return rng()%(R-L+1) + L;
}
ll lcm(ll a,ll b){
return ((a)/gcd(a,b))*b;
}
ll bigmod(ll a,ll n,ll md){
if(n==0){
return 1;
}
if(n==1){
return a%md;
}
ll d= bigmod(a,n/2,md);
if(n%2==0){
return (d*d)%md;
}
else{
return ( ((d*d)%md) * (a%md) )%md;
}
}
bool sortbysec(const pair<int,int> &a,
const pair<int,int> &b)
{
if(a.first==b.first){
return (a.second > b.second);
}
return (a.first< b.first);
}
const ll N = 200004;
const ll mod = 1e9 + 7;
const ll neginf= -1e18;
const ll inf = 1e18;
const ld eps= 1e-9;
/// avoid Wrong answer
/// think 2 minute before submission
/// check input output before submission
///use binary search for maximum minimum problem
ll sqr(ll d){
return d*d;
}
void solve(){
ll n;
cin>>n;
ld x[n],r[n];
ld ans[n];
f(i,0,n){
cin>>x[i]>>r[i];
}
ld val;
stack<pair<ld,ld> >st;
f(i,0,n){
if(i==0){
st.push({x[i],r[i]});
ans[i]=r[i];
}
else{
ld nwh=r[i];
pair<ld,ld>ab;
while(!st.empty()){
ab=st.top();
ld rd=ab.ss;
ld dis=x[i]-ab.ff;
ld nw= (dis*dis)/(4.0*rd);
nw=min(nw,nwh);
nwh=nw;
if(nw<rd){
break;
}
else{
st.pop();
}
}
ans[i]=nwh;
st.push({x[i],nwh});
}
}
cout<<fixed<<setprecision(3);
f(i,0,n){
cout<<ans[i]<<nl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t=1;
// cin>>t;
while(t--){
solve();
}
}
Compilation message (stderr)
bal.cpp: In function 'void solve()':
bal.cpp:108:8: warning: unused variable 'val' [-Wunused-variable]
108 | ld val;
| ^~~
# | 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... |