Problem Description
In ACM/ICPC contest, the ”Dirt Ratio” of a team is calculated in the following way. First let’s ignore all the problems the team didn’t pass, assume the team passed X problems during the contest, and submitted Y times for these problems, then the ”Dirt Ratio” is measured as XY. If the ”Dirt Ratio” of a team is too low, the team tends to cause more penalty, which is not a good performance.

Picture from MyICPC

Little 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”.

Input
The first line of the input contains an integer T(1≤T≤15), denoting the number of test cases.

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.

Output
For each test case, print a single line containing a floating number, denoting the lowest ”Dirt Ratio”. The answer must be printed with an absolute error not greater than 10−4.

Sample Input
1
5
1 2 1 2 3

Sample Output
0.5000000000
Hint

For every problem, you can assume its final submission is accepted.
感觉现在的数据结构越来越不单纯了,看来还是得全面发展,这样一个东西我都没有想到:
sum(l,r)/(l+r−1)<=mid==sum(l,r)+l∗mid<=(r+1)∗midsum(l,r)/(l+r−1)<=mid==sum(l,r)+l∗mid<=(r+1)∗midsum(l,r)/(l+r-1)
sum指的是l到r之间有多少不相同的数,然后就for一遍r,居然不会tQAQ

#include<bits/stdc++.h>
using namespace std;
const int maxn=6e4+5;
double sum[maxn*4],flag[maxn*4];
int n;
void pushup(int root)
{sum[root]=min(sum[root<<1],sum[root<<1|1]);
}
void pushdown(int root)
{if(!flag[root])return;sum[root<<1]+=flag[root];sum[root<<1|1]+=flag[root];flag[root<<1]+=flag[root];flag[root<<1|1]+=flag[root];flag[root]=0;
}
void build(int l,int r,int root,double m)
{flag[root]=sum[root]=0;if(l==r){sum[root]=(double)l*m;return ;}int mid=l+r>>1;build(l,mid,root<<1,m);build(mid+1,r,root<<1|1,m);pushup(root);
}
void update(int l,int r,int root,int ql,int qr,double val)
{if(l>=ql&&r<=qr){flag[root]+=val;sum[root]+=val;return ;}pushdown(root);int mid=l+r>>1;if(mid>=ql)update(l,mid,root<<1,ql,qr,val);if(mid<qr)update(mid+1,r,root<<1|1,ql,qr,val);pushup(root);
}
double query(int l,int r,int root,int ql,int qr)
{if(l>=ql&&r<=qr)return sum[root];int mid=l+r>>1;double ans=1e7;if(mid>=ql)ans=min(ans,query(l,mid,root<<1,ql,qr));if(mid<qr)ans=min(ans,query(mid+1,r,root<<1|1,ql,qr));return ans;
}
int pre[maxn],last[maxn];
int check(double m)
{build(1,n,1,m);for(int i=1;i<=n;i++){update(1,n,1,pre[i]+1,i,1);//cout<<i<<" "<<query(1,n,1,1,i)<<endl;if(query(1,n,1,1,i)<=(double)m*(i+1))return 1;}return 0;
}
int main()
{int t;scanf("%d",&t);while(t--){scanf("%d",&n);memset(last,0,sizeof(last));int x;for(int i=1;i<=n;i++){scanf("%d",&x);pre[i]=last[x];last[x]=i;}double low=0,high=1,mid;while(high-low>=1e-5){mid=(low+high)/2;if(check(mid)==1)high=mid-1e-6;elselow=mid+1e-6;}printf("%.10f\n",high);}return 0;
}

hdu 6070 Dirt Ratio —— 二分+线段树相关推荐

  1. HDU 6070 Dirt Ratio(线段树、二分)

    http://acm.hdu.edu.cn/showproblem.php?pid=6070 题解 首先不难看出错误率是单调的,那么我们可以直接二分答案x,某个区间的错误率=区间数的种类cnt/区间长 ...

  2. HDU - 6070 Dirt Ratio (二分 + 线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6070 题目大意:给定一个序列a,对于任何一个区间 [l,r],它的"Dirt Ratio&q ...

  3. HDU 6070 Dirt Ratio

    暑假多校赛的一道题,印象深刻,今天终于补了,现在感觉也不是特别难,题意是很经典的那种问题,就是给你一个数列,问一个区间不同的个数比区间的长度的值,在这个数列里的最小值.之前搜过区间不同数的个数的查询问 ...

  4. 线段树分裂与合并 ----- P2824 [HEOI2016/TJOI2016]排序 [线段树分裂合并 OR 01序列排序+二分线段树]

    题目链接 题目大意: 对一个序列,每次按照升序或者降序排序序列某一段,问你最后的序列是什么? 解法1:二分+线段树 首先我们知道对一个01序列进行排序是很快的!我们只要知道里面有多少个1和多少个0,那 ...

  5. HDU 1166 敌兵布阵(线段树:点更新,区间求和)

    HDU 1166 敌兵布阵(线段树:点更新,区间求和) http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意: 给你n个整数,然后给你多条命令,每条命令如 ...

  6. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  7. 2019CCPC网络赛 1002 HDU 6703(权值线段树)

    2019CCPC网络赛 1002 HDU 6703(权值线段树) 思路:用权值线段树存题目给的数据后,2操作就是求权值线段树中大于等于k的部分中,靠近左端点的第一个大于r的值(这个求出来的只是原序列中 ...

  8. HDU - 4614 Vases and Flowers 线段树+二分

    题目链接 思路:线段树维护区间和,当k=1时,询问二分询问[x-(x~n-1)]找到最小位置,复杂度n*logn*logn卡过 #include<stdio.h> #include< ...

  9. 【HDU - 5875】Function(线段树,区间第一个小于某个数的数 或 RMQ二分)

    题干: The shorter, the simpler. With this problem, you should be convinced of this truth.        You a ...

  10. HDU 6089 Rikka with Terrorist (线段树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6089 题解 这波强行维护搞得我很懵逼... 扫描线,只考虑每个点能走到左上方(不包括正上方,但包括正左 ...

最新文章

  1. 小程序webview跳转页面后没有返回按钮完美解决方案
  2. mysql could not create connection_mysql8.0 Could not create connection to database server.解决办法...
  3. Understand分析Kinect SDK 1.7自带例子(C++)图集一
  4. Spring Session使用
  5. 【BZOJ1899】[Zjoi2004]Lunch 午餐 贪心+DP
  6. 使用内置的Gallery应用程序选择图形
  7. vue点击切换类名_vue 新用户引导(vue-dirver)
  8. 架构设计工作笔记005---微服务架构中的服务编排了解
  9. python的xlwt库的作用_Python:使用第三方库xlwt来写Excel
  10. Qt翻译文件(.ts)的使用
  11. linux版本搜狗,搜狗输入法linux版下载
  12. 标准MIDI文件格式
  13. 51单片机usb烧录电路_51单片机怎么用usb烧写程序
  14. PCB板材的基础知识
  15. 不允许指针指向不完整的类类型
  16. C# 图形处理-缩略图,图片合并,图片写文字,图片调整
  17. Python案例分析之客户信贷预测模型
  18. java 完全匹配_全序列匹配(java)
  19. windows cmd sqlplus访问Oracle数据库显示?胧淙胗没? SP2-0306: ?∠钗扌А?的问题
  20. 《财富》杂志评选的75本必读的最睿智的图书

热门文章

  1. Solidity----状态修饰符view、pure
  2. 代做assignment分享高分Essay写作攻略
  3. 计算机软件硬件和应用知识论文,有关计算机及应用毕业论文
  4. 恢复计算机注册表命令,恢复电脑注册表的方法
  5. 新手学编程,是学c还是java呢?
  6. 【超实用】各种单位换算表大全
  7. jQuery 仿iGoogle视频的列表拖动缓冲特效
  8. 百度与谷歌地图坐标转换
  9. 我在华为做外包的真实经历!
  10. Office Web Add-in的技术原理和开发常见问题剖析