HDU 6070 Dirt Ratio(线段树)
Dirt Ratio
Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1473 Accepted Submission(s): 683
Special Judge
Picture from MyICPCLittle Q is a coach, he is now staring at the submission list of a team. You can assume all the problems occurred in the list was solved by the team during the contest. Little Q calculated the team's low ''Dirt Ratio'', felt very angry. He wants to have a talk with them. To make the problem more serious, he wants to choose a continuous subsequence of the list, and then calculate the ''Dirt Ratio'' just based on that subsequence.
Please write a program to find such subsequence having the lowest ''Dirt Ratio''.
In each test case, there is an integer n(1≤n≤60000) in the first line, denoting the length of the submission list.
In the next line, there are n positive integers a1,a2,...,an(1≤ai≤n), denoting the problem ID of each submission.
5
1 2 1 2 3
For every problem, you can assume its final submission is accepted.
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = 6e4+;;
const int M = ;
const int mod = 1e9+;
const double pi= acos(-1.0);
typedef pair<int,int>pii;
int n,k,ans;
int a[N],lazy[N*];
int pre[N],pos[N];
double dp[N];
double mx[N*];
void pushUp(int rt){
mx[rt]=min(mx[rt<<],mx[rt<<|]);
}
void pushDown(int rt){
if(lazy[rt]){
lazy[rt<<]+=lazy[rt];
lazy[rt<<|]+=lazy[rt];
mx[rt<<]+=lazy[rt];
mx[rt<<|]+=lazy[rt];
lazy[rt]=;
}
}
void build(int l,int r,int rt,double x){
lazy[rt]=;
if(l==r){
mx[rt]=x*l;
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<,x);
build(mid+,r,rt<<|,x);
pushUp(rt);
}
void upd(int L,int R,int l,int r,int x,int rt){
if(L<=l&&r<=R){
mx[rt]+=x;
lazy[rt]+=x;
return;
}
pushDown(rt);
int mid=(l+r)>>;
if(L<=mid)upd(L,R,l,mid,x,rt<<);
if(R>mid) upd(L,R,mid+,r,x,rt<<|);
pushUp(rt);
}
double qry(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R){
return mx[rt];
}
pushDown(rt);
double ret=;
int mid=(l+r)>>;
if(L<=mid)ret=min(ret,qry(L,R,l,mid,rt<<));
if(R>mid)ret=min(ret,qry(L,R,mid+,r,rt<<|));
return ret;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
met(pos,);
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
pre[i]=pos[a[i]];
pos[a[i]]=i;
}
double l=,r=;
for(int i=;i<=;i++){
double mid = (l+r)/;
build(,n,,mid);
bool ok=true;
for(int j=;j<=n;j++){
upd(pre[j]+,j,,n,,);
dp[j]=qry(,j,,n,);
if(dp[j]<=mid*(j+)){
ok=false;break;
}
}
if(!ok)r=mid;
else l=mid;
}
printf("%.9f\n",(l+r)/);
}
}
最新文章
- 记从安装centos系统在到使用mono3.2部署MVC过程遇到的问题
- iOS 短信分享 邮件分享
- VS2010 项目引用了DLL文件,也写了Using,但是编译时提示:未能找到类型或命名空间名称 <;转>;
- 密码太多记不住?SSO帮你轻松访问VDI及外部资源
- GIT在Linux上的安装和使用简介
- 灰度图像的自动阈值分割(Otsu 法)(转载)
- Linux之zsh
- 网络子系统53_ip协议分片重组_内存阈值
- oracle sys sysman system 介绍
- UITableView类用法大全:UITableView属性
- 再叙ASM
- ionic开发中,输入法键盘弹出遮挡住div元素
- 网络编程初识和socket套接字
- day30 item系列
- Python爬虫之PyQuery使用(六)
- Django之视图层介绍
- 从零开始学Kotlin-操作符(3)
- 【转】一件有趣的事:我用 Python 爬了爬自己的微信朋友
- NTP服务器时间集群借节点之间同步
- php--------ThinkPHP3.2验证码使用
热门文章
- PowerDesigner16 把设计图导出成图片
- CAS(硬件CPU同步原语)
- Linux 文件编码问题及iconv命令
- Oracle 导出空表的新方法(彻底解决)
- application.properties 文件的优先级
- Python自动化运维 - Django(二)Ajax基础 - 自定义分页
- /proc/diskstats文件注解
- Optimizing TLB entries for mixed page size storage in contiguous memory
- 终于解决了Linux下运行OCCI程序一直报Error while trying to retrieve text for error ORA-01804错误
- 生命周期(vue的钩子函数)