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)/);
- }
- }
HDU 6070 Dirt Ratio(线段树)的更多相关文章
- hdu 6070 Dirt Ratio 线段树+二分
Dirt Ratio Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Spe ...
- HDU 6070 - Dirt Ratio | 2017 Multi-University Training Contest 4
比赛时会错题意+不知道怎么线段树维护分数- - 思路来自题解 /* HDU 6070 - Dirt Ratio [ 二分,线段树 ] | 2017 Multi-University Training ...
- HDU 6070 Dirt Ratio(分数规划+线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=6070 题意: 找出一个区间,使得(区间内不同数的个数/区间长度)的值最小,并输出该值. 思路: 因为是要求$\f ...
- 2017ACM暑期多校联合训练 - Team 4 1004 HDU 6070 Dirt Ratio (线段树)
题目链接 Problem Description In ACM/ICPC contest, the ''Dirt Ratio'' of a team is calculated in the foll ...
- hdu 6070 Dirt Ratio
题 OvO http://acm.hdu.edu.cn/showproblem.php?pid=6070 (2017 Multi-University Training Contest - Team ...
- HDU 6070题解(二分+线段树)
题面 传送门 此题的题意不是很清晰,要注意的一点是在区间[L,R]中,默认题目编号最后一次出现的时候是AC的 比如1 2 1 2 3 ,在区间[1,4]中,第3次提交时AC第1题,第4次提交时AC第2 ...
- hdu 5700区间交(线段树)
区间交 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- HDU 5091---Beam Cannon(线段树+扫描线)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies bro ...
随机推荐
- mysql创建用户,并授权
1.创建用户 CREATE USER 'username'@'host' IDENTIFIED BY 'password'; host分下列3种情况:'%' - 所有情况都能访问‘localhost’ ...
- Strand Sort
Strand sort是思路是这样的,它首先需要一个空的数组用来存放最终的输出结果,给它取个名字叫"有序数组" 然后每次遍历待排数组,得到一个"子有序数组",然 ...
- 「6月雅礼集训 2017 Day7」电报
[题目大意] 有n个岛屿,第i个岛屿有有向发射站到第$p_i$个岛屿,改变到任意其他岛屿需要花费$c_i$的代价,求使得所有岛屿直接或间接联通的最小代价. $1 \leq n \leq 10^5, 1 ...
- 【BZOJ】1607: [Usaco2008 Dec]Patting Heads 轻拍牛头
[算法]模拟 #include<cstdio> #include<algorithm> using namespace std; ,maxm=; int a[maxn],A[m ...
- quick-cocos2dx 悬浮节点(NotificationNode)
cocos2dx 开发游戏时,有时某些节点不需要随着场景的切换而销毁.但cocos2dx的机制只允许同时只有一个运行的场景,如果你的所有节点都是依附于这个场景的,那场景的切换必然带来节点的销毁. 比如 ...
- python学习笔记(一)之为什么学习python
python的特点: 跨平台 实现同一个功能是Java代码的1/5 python应用范围: 操作系统 web 3D动画 企业应用 云计算 如何学习python? 学习语法 验证例子 学会总结 课外实践
- Spring总结以及在面试中的一些问题(山东数漫江湖)
1.谈谈你对spring IOC和DI的理解,它们有什么区别? IoC Inverse of Control 反转控制的概念,就是将原本在程序中手动创建UserService对象的控制权,交由Spri ...
- 【洛谷 P3899】 [湖南集训]谈笑风生 (主席树)
题目链接 容易发现\(a,b,c\)肯定是在一条直链上的. 定义\(size(u)\)表示以\(u\)为根的子树大小(不包括\(u\)) 分两种情况, 1.\(b\)是\(a\)的祖先,对答案的贡献是 ...
- Python模块学习 - Argparse
argparse模块 在Python中,argparse模块是标准库中用来解析命令行参数的模块,用来替代已经过时的optparse模块.argparse模块能够根据程序中的定义从sys.argv中解析 ...
- 【LabVIEW技巧】策略模式
前言 在之前的文章提到了如何学习OOP以及对应的简单工厂模式,由于时间比较长,我们先回顾一下原有内容,然后继续了解新的模式. 为什么学习OOP 在测控系统的软件开发过程中,LabVIEW工程师一直认为 ...