因为原序列是排列好了的,那么只要看一下给出的两个区间相交的情况,然后分类讨论一下,O(1)输出。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
int T,n,m,a[maxn]; int get(int l1,int r1,int l2,int r2 ,int x)
{
if(l2>r1)
{
if(r1-l1+>=x) return a[l1+x-];
else return a[l2+x-(r1-l1+)-];
} else if(r2<=r1)
{
if(l2-l1>=x) return a[l1+x-];
else if(*(r2-l2+)+l2-l1>=x) return a[l2+(x-(l2-l1)-)/];
else return a[r2++x-(*(r2-l2+)+l2-l1)-];
} else
{
if(l2-l1>=x) return a[l1+x-];
else if(*(r1-l2+)+l2-l1>=x) return a[l2+(x-(l2-l1)-)/];
else return a[r1++x-(*(r1-l2+)+l2-l1)-];
}
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++)
{
int l1,r1,l2,r2;
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
if(l1>l2) { swap(l1,l2); swap(r1,r2); }
if((r1-l1++r2-l2+)%==)
{
printf("%.1lf\n",1.0*get(l1,r1,l2,r2,(r1-l1++r2-l2+)/+));
}
else
{
double num1=1.0*get(l1,r1,l2,r2,(r1-l1++r2-l2+)/);
double num2=1.0*get(l1,r1,l2,r2,(r1-l1++r2-l2+)/+);
printf("%.1lf\n",1.0*(num1+num2)/2.0);
}
}
}
return ;
}

HDU 5857 Median的更多相关文章

  1. HDU 5857 Median (推导)

    Median 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5857 Description There is a sorted sequ ...

  2. hdu 3648 Median Filter (树状数组)

    Median Filter Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU5857 Median 模拟

    Median HDU - 5857 There is a sorted sequence A of length n. Give you m queries, each one contains fo ...

  4. hdu 3282 Running Median

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you ...

  5. HDU 4981 Goffi and Median(水)

    HDU 4981 Goffi and Median 思路:排序就能够得到中间数.然后总和和中间数*n比較一下就可以 代码: #include <cstdio> #include <c ...

  6. HDU 3282 Running Median 动态中位数,可惜数据范围太小

    Running Median Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  7. HDU 4981 Goffi and Median

    题解:排序取中位数,然后与平均数比较即可. #include <cstdio> #include <algorithm> using namespace std; double ...

  8. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  9. hdu 4908(思路题)

    BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. zoom:1的作用

    兼容IE6.IE7.IE8浏览器,经常会遇到一些问题,可以使用zoom:1来解决,有如下作用:触发IE浏览器的haslayout解决ie下的浮动,margin重叠等一些问题. 如下使用DIV做一行两列 ...

  2. JMS(java消息服务)整合Spring项目案例

    转载自云栖社区 摘要: Sprng-jms消息服务小项目 所需的包: spring的基础包 spring-jms-xx包 spring-message–xx包 commons-collection-x ...

  3. awk-模式匹配

    使用awk作为文本处理工具,正则表达式是少不了的. 要掌握这个工具的正则表达式使用.其实,我们不必单独去学习它的正则表达式.正则表达式就像一门程序语言,有自己语法规则已经表示意思. 对于不同工具,其实 ...

  4. java基础:int和integer区别

    int是基础数据类型: integer是包装类,里面包含一些基础的方法,最常见的就是数据转换: 比如int转String: int a=0: String b=Integer.toString(a):

  5. springMVC Helloword 入门程序

    1  首先是在web.xml 中配置 <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-cl ...

  6. Python网络编程学习_Day10

    一.进程与线程 1.区别 进程:一个程序要运行时所需要的所有资源的集合,进程是资源的集合. 一个进程至少需要一个线程,这个线程称为主线程 一个进程里面可以有多个线程 两个进程之间的数据是完全独立,不能 ...

  7. Malware Defender(HIPS主动防御软件) V2.8 免费版

    软件名称: Malware Defender(HIPS主动防御软件) V2.8 免费版 软件语言: 简体中文 授权方式: 免费软件 运行环境: Win7 / Vista / Win2003 / Win ...

  8. PHP检测文件能否下载

    用php代码检测一个文件是否可以下载,网上没有找到合适的代码,自己实现了一个还挺好用的,分享给有需要的朋友. 基本原理:使用http的HEAD方法,检测报文的头里httpcode是否为200. pub ...

  9. CodeForces 669E Little Artem and Time Machine

    树状数组,$map$. 可以理解为开一个数组$f[i][j]$记录:$i$这个数字在时间$j$的操作情况. 操作$1$:$f[x][t]++$.操作$2$:$f[x][t]--$.操作$3$:$f[x ...

  10. Hadoop优先级调度

    当同时在集群中运行多个作业时,默认情况下,Hadoop将提交的作业放入一个FIFO,一个作业结束后,Hadoop就启动下一个作业. 当一个运行时间长但是优先级较低的作业先于运行时间短而优先级较高的作业 ...