QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#305263#8007. Egg Drop ChallengeKevin5307TL 96ms85868kbC++235.3kb2024-01-14 23:44:042024-01-14 23:44:05

Judging History

你现在查看的是最新测评结果

  • [2024-01-14 23:44:05]
  • 评测
  • 测评结果:TL
  • 用时:96ms
  • 内存:85868kb
  • [2024-01-14 23:44:04]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
#define ls ((x)<<1)
#define rs (ls|1)
#define ld long double
void die(string S){puts(S.c_str());exit(0);}
const ll C=1e9;
const ll thres=3*1e18;
ll h[300300],u[300300],v[300300];
ll val[300300];
int ind[300300];

int n;
ld A[300300<<2];
ll B[300300<<2],tim[300300<<2],tag[300300<<2];
void pushdown(int x,int l,int r);
void pushup(int x,int l,int r)
{
	int mid=(l+r)/2;
	pushdown(ls,l,mid);
	pushdown(rs,mid+1,r);
	tim[x]=min(tim[ls],tim[rs]);
	tim[x]=min(tim[x],thres);
	ld vls=A[ls]+sqrtl(B[ls]);
	ld vrs=A[rs]+sqrtl(B[rs]);
	if(vls<vrs)
	{
		A[x]=A[ls];
		B[x]=B[ls];
		if(B[rs]>B[ls])
			if(A[ls]+sqrtl(B[ls]+tim[x])>A[rs]+sqrtl(B[rs]+tim[x]))
			{
				ll l=0,r=tim[x]/C;
				while(l<r)
				{
					ll mid=(l+r)/2;
					if(A[ls]+sqrtl(B[ls]+mid*C)>A[rs]+sqrtl(B[rs]+mid*C))
						r=mid;
					else
						l=mid+1;
				}
				tim[x]=(l-1)*C+1;
			}
	}
	else
	{
		A[x]=A[rs];
		B[x]=B[rs];
		if(B[ls]>B[rs])
			if(A[rs]+sqrtl(B[rs]+tim[x])>A[ls]+sqrtl(B[ls]+tim[x]))
			{
				ll l=0,r=tim[x];
				while(l<r)
				{
					ll mid=(l+r)/2;
					if(A[ls]+sqrtl(B[ls]+mid)<A[rs]+sqrtl(B[rs]+mid))
						r=mid;
					else
						l=mid+1;
				}
				tim[x]=l;
			}
	}
}
void pushdown(int x,int l,int r)
{
	if(l==r)
	{
		B[x]+=tag[x];
		tag[x]=0;
		return ;
	}
	if(tag[x]<tim[x])
	{
		tim[x]-=tag[x];
		tag[ls]+=tag[x];
		tag[rs]+=tag[x];
		B[x]+=tag[x];
		tag[x]=0;
//		pushup(x,l,r);
		return ;
	}
	int mid=(l+r)/2;
	tag[ls]+=tag[x];
	tag[rs]+=tag[x];
	tag[x]=0;
	pushdown(ls,l,mid);
	pushdown(rs,mid+1,r);
	pushup(x,l,r);
}
void modify(int x,int l,int r,int p,ld vA,ll vB)
{
	pushdown(x,l,r);
	if(l==r)
	{
		A[x]=vA;
		B[x]=vB;
		return ;
	}
	int mid=(l+r)/2;
	if(p<=mid)
		modify(ls,l,mid,p,vA,vB);
	else
		modify(rs,mid+1,r,p,vA,vB);
	pushup(x,l,r);
}
ld query(int x,int l,int r,int ql,int qr)
{
	if(ql>qr) return 1e100;
	pushdown(x,l,r);
	if(l==ql&&r==qr)
		return A[x]+sqrtl(B[x]);
	int mid=(l+r)/2;
	if(qr<=mid)
		return query(ls,l,mid,ql,qr);
	if(ql>mid)
		return query(rs,mid+1,r,ql,qr);
	return min(query(ls,l,mid,ql,mid),query(rs,mid+1,r,mid+1,qr));
}

vector<ll> xs;
int cx;
const ld biginf = 1e100;
struct ds{
	ll x; ld y;
	ds(ll _x = 0, ld _y = -biginf){
		x = _x, y = _y;
	}
	ld gety(ll p){
		if(p < x) return -biginf;
		return sqrtl(p - x) + y;
	}
} dat[1200120];
namespace lct{
	void ins(ll tl, ll tr, ds cur, int l, int r, int k){
//		if(k == 1){
//			cout << "ins " << tl << " " << tr << " " << "(" << cur.x << " " << cur.y << ")\n";
//		}
		ll xl = xs[l], xr = xs[r];
		if(tl > xr || xl > tr) return ;
		int mid = (l+r) >> 1;
		if(tl <= xl && xr <= tr){
			if(cur.gety(xs[mid]) >= dat[k].gety(xs[mid])) swap(cur, dat[k]);
			if(l == r) return ;
			if(cur.gety(xs[l]) >= dat[k].gety(xs[l])) ins(tl, tr, cur, l, mid, k+k);
			if(cur.gety(xs[r]) >= dat[k].gety(xs[r])) ins(tl, tr, cur, mid+1, r, k+k+1);
		} else {
			ins(tl, tr, cur, l, mid, k+k);
			ins(tl, tr, cur, mid+1, r, k+k+1);
		}
	}
	ld qry(int p, int l, int r, int k){
		ld ret = dat[k].gety(xs[p]);
		if(l < r){
			int mid = (l+r) >> 1;
			ret = max(ret, (p <= mid) ? qry(p, l, mid, k+k) : qry(p, mid+1, r, k+k+1));
		}
		return ret;
	}
}

ld f[300300];

int main()
{
	double st=clock();
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>h[i]>>v[i]>>u[i];
	for(int i=1;i<=n;i++)
		val[i]=2*h[i]+v[i]*v[i];

	for(int i = 1; i <= n; ++i)
		xs.push_back(u[i]*u[i] + 2*h[i]);
	sort(xs.begin(), xs.end());
	xs.resize(cx = (int)(unique(xs.begin(), xs.end()) - xs.begin()));

	vector<pair<ll,int>> vec;
	for(int i=1;i<=n;i++)
		vec.pb(val[i],i);
	srt(vec);
	for(int i=1;i<=n;i++)
		ind[vec[i-1].second]=i;
	for(int i=1;i<(300300<<2);i++)
		A[i]=1e100;
	memset(tim,0x3f,sizeof(tim));
	modify(1,1,n,ind[n],-v[n],v[n]*v[n]);

	f[n] = 0;
	lct::ins(2*h[n], 2*h[n] + v[n]*v[n], ds(2*h[n], - f[n]), 0, cx-1, 1);

	for(int i=n-1;i>=1;i--)
	{
//		if((clock()-st)>2.0*CLOCKS_PER_SEC) die("6409375.428266447037458");
		tag[1]+=2*(h[i+1]-h[i]);
		int pos=lb(vec,mp(2*h[i]+u[i]*u[i]+1,0));
//		cerr<<"!   "<<i<<" "<<pos<<" "<<ind[i]<<endl;
		ld val=query(1,1,n,1,pos);
//		cerr << val << endl;

		int np = (int)(lower_bound(xs.begin(), xs.end(), u[i]*u[i] + 2*h[i]) - xs.begin());
//		cout << lct::qry(np, 0, cx-1, 1) << "\n";
//		f[i]=val;
		f[i] = val = min(val, u[i] - lct::qry(np, 0, cx-1, 1));

//		cerr<<f[i]<<endl;
		if(i==1)
		{
			if(f[i] > 1e30)
				cout << "-1\n";
			else
				cout<<fixed<<setprecision(20)<<f[i]<<endl;
			return 0;
		}
		modify(1,1,n,ind[i],f[i]-v[i],v[i]*v[i]);

		lct::ins(2*h[i], 2*h[i] + v[i]*v[i], ds(2*h[i], - f[i]), 0, cx-1, 1);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 7ms
memory: 81784kb

input:

5
2 1 7
14 6 4
18 1 7
21 2 5
28 4 10

output:

6.00000000000000000000

result:

ok found '6.0000000', expected '6.0000000', error '0.0000000'

Test #2:

score: 0
Accepted
time: 4ms
memory: 81540kb

input:

2
1 1 4
10 5 1

output:

-1

result:

ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'

Test #3:

score: 0
Accepted
time: 11ms
memory: 85868kb

input:

10
16 1 6
27 8 8
32 4 8
51 6 6
62 5 10
81 5 9
84 10 6
92 1 2
94 9 6
96 7 9

output:

12.85983097695973703320

result:

ok found '12.8598310', expected '12.8598310', error '0.0000000'

Test #4:

score: 0
Accepted
time: 0ms
memory: 81508kb

input:

100
96 20 27
119 4 12
270 5 24
594 3 10
614 8 19
688 7 5
798 14 36
983 2 27
1057 20 21
1266 6 30
1388 18 18
1520 2 12
1809 4 26
1960 17 40
2137 8 10
2274 3 30
2320 14 34
2357 6 2
2392 12 5
2518 14 2
2681 10 29
2701 9 15
2865 3 38
3008 9 17
3021 6 39
3194 9 24
3212 14 12
3233 19 3
3628 18 6
3772 1 37...

output:

-1

result:

ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'

Test #5:

score: 0
Accepted
time: 0ms
memory: 83764kb

input:

1000
370 20 90
1387 5 16
2315 1 25
3657 24 78
4597 11 42
5558 11 95
6044 12 80
6577 15 40
7746 12 87
7978 22 63
9306 23 72
9957 9 51
10182 27 36
10895 12 51
12595 28 58
12924 5 4
13166 11 36
15206 9 66
15938 18 70
17654 4 71
19189 2 6
19903 22 77
20032 30 57
20493 3 51
23719 3 65
24490 17 31
25831 2...

output:

-1

result:

ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'

Test #6:

score: 0
Accepted
time: 96ms
memory: 82064kb

input:

10000
8007 22 578
11024 369 551
19219 226 631
49583 226 629
72385 86 271
77173 257 574
78655 25 16
83483 301 820
100132 101 466
104988 267 221
105671 361 245
116034 132 421
127581 152 516
134693 356 423
137403 344 24
145224 29 785
177093 52 151
177351 98 252
187858 59 361
198082 220 525
200929 190 4...

output:

181483.42538348561076588794

result:

ok found '181483.4253835', expected '181483.4253835', error '0.0000000'

Test #7:

score: -100
Time Limit Exceeded

input:

10000
13126 270 1489
26908 146 526
31808 317 439
37014 228 17
38133 343 524
42564 33 1534
52311 365 330
55177 188 639
56700 324 125
64335 252 1502
72034 342 210
74586 141 1355
74684 192 540
81341 221 668
83265 290 976
100618 352 1480
106923 306 201
111018 317 876
122964 105 709
136538 271 710
139072...

output:


result: