您的位置:首页 > 其它

Codeforces 629D

2017-04-11 23:23 246 查看

树状数组

题目链接: http://codeforces.com/problemset/problem/629/D

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1e5+10;
const double PI = acos(-1.0);
typedef long long ll;
ll a
, b
, tree
;
void update(int k, ll c, int n)
{
while(k <= n)
{
tree[k] = max(tree[k], c);
k += k&(-k);
}
return ;
}
ll query(int k)
{
ll ans = 0;
while(k)
{
ans = max(tree[k], ans);
k -= k&(-k);
}
return ans;
}
int main()
{
int n;
cin >> n;
ll r, h;
for(int i = 1;i <= n;i++)
cin >> r >> h, b[i] = a[i] = r*r*h;
sort(b+1, b+1+n);
ll ans = 0;
for(int i = 1;i <= n;i++)
{
int pos = lower_bound(b+1, b+1+n, a[i]) - b;
ll tmp = query(pos-1) + a[i];
ans = max(ans, tmp);
update(pos, tmp, n);
}
printf("%.10f\n", PI*ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: