CF629D:树状数组

CF629D

题解

  • 相当于求最大上升子序和。dp超时,树状数组处理。
  • 数组数组维护的是有pos为末的最大子序和。

代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const N = 100000 + 10;
int const inf = 0x7f7f7f7f;
double const PI = acos(-1);
int n;
ll c[N],d[N];
vector<ll>t;
int lowbit(int x){return x&-x;}
void updata(int i,ll x){
	while(i <= n){
		d[i] = max(d[i],x);
		i += lowbit(i);
	}
}
ll query(int i){
	ll ans = 0;
	while(i){
		ans = max(ans,d[i]);
		i -= lowbit(i);
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		ll r,h;
		scanf("%lld%lld",&r,&h);
		c[i] = r * r * h;
		t.push_back(c[i]);
	}
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	ll ans = 0;
	for(int i=1;i<=n;i++){
		int pos = lower_bound(t.begin(),t.end(),c[i]) - t.begin() + 1;
		ll res = query(pos-1) + c[i];
		ans = max(ans,res);
		updata(pos,res);		
	}
	printf("%.9f\n",PI * ans);
	return 0;
}

 

posted @ 2019-04-10 08:17  月光下の魔术师  阅读(81)  评论(0)    收藏  举报