因为原序列是排列好了的,那么只要看一下给出的两个区间相交的情况,然后分类讨论一下,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. learning english

    distortion 英[dɪ'stɔ:ʃn] 美[dɪˈstɔrʃən]n. 扭曲,变形; 失真,畸变; [心理学] 扭转;[例句]I think it would be a gross disto ...

  2. 《Hexo+github搭建个人博客》

    <Hexo+github搭建个人博客> 文/冯皓林 完稿:2016.4.22-2016.4.23 注意:本节教程只针对Windows用户.本教程由无人赞助,赞助写出. <Hexo+g ...

  3. HDU 1728 逃离迷宫(DFS||BFS)

    逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...

  4. on事件绑定阻止冒泡的问题

    当使用on进行事件绑定时当要给document绑定click,而子元素要禁止冒泡,那么子元素里面的子元素的click事件就会无效了, 下面无效版: $('#queue').on('click', '. ...

  5. zabbix 布署实践【4 服务器自动探索发现,并且自动关联模版】

    使用管理员登录zabbix后,在配置---自动发现--创建发现规则 如下:我们的需求是监听办公网内openstack的所有虚拟机,在其VM创建后,自动加到zabbix监控中来,并自动关联监控模版 可以 ...

  6. Facebook FB.init() status参数的作用

    意思是 status 设为 ture 之后调用 FB.getLoginStatus() 不再产生网络请求,数据已经在 FB.init() 调用的时候被请求回来,缓存住了.

  7. crontab 添加sh文件定时

    (1)编写sh文件,比如/orcl/test/export.sh 编写crond文件 chmod 755 /orcl/test/*      //复制所有权限 [root@postest test]# ...

  8. OSI参考模型初识

    纪念我曾今热爱的数通(^o^). 1.osi参考模型 2.数据的封装和解封装 3.主机和主机间通信

  9. GNU/Linux超级本ZaReason Ultralap 440体验

    老早就在网上看到有关ZaReason公司推出了业界首款Linux超级本Ultralap 430的新闻.通过网上搜索,我了解到ZaReason是一家专门制作与销售预装Linux台式机.笔记本.超级本.平 ...

  10. spring 四种依赖注入方式以及注解注入方式

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...