因为原序列是排列好了的,那么只要看一下给出的两个区间相交的情况,然后分类讨论一下,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. [ios] 微信订阅号: ios博文精选

    晚上下班后时间充裕,平时要么看电视剧,要么玩游戏 感觉浪费时间.  最后决定自己也搞一个微信订阅号分享技术方面的东西,也提升自己. 如果大家也是一样情况,欢迎大家关注我的订阅号. 微信订阅号: ios ...

  2. 在收购Sun六年后,Oracle终于瞄准了Java的非付费用户

    Java语言毫无疑问已经成为软件社区的一个品牌和开放的产业标准.自从2010年Oracle收购了Sun Microsystems公司之后,很多人就担心这在某种程度上是软件开源产业的一次失败,甚至会造成 ...

  3. html&css入门详解

    本系列主要讲解html与css的知识点,因为是参考的英文版的<html&css design and build websites>,所以可能会有个人翻译理解上的差错,希望观者能够 ...

  4. Virtualbox中的Linux:未能加载虚拟光驱 VBoxsGuestAdditions.iso到虚拟电脑

    安装增强功能 出现了 这个问题,需要弹出光盘,再次安装.

  5. 使用Asponse.Cell解决Excel科学计数法问题

    //fileName --文件路径 public DataSet DataSetGetDataFromExcel(string fileName) { DataSet dataset = new Da ...

  6. git commit

    使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中. Git 为你的每一个提交都记录你的名字与电子邮箱地址,所以第一步需要配置用户名和邮箱地 ...

  7. c# base和this在构造函数中的应用

    构造函数可以使用 base 关键字来调用基类的构造函数.例如: public class Manager : Employee{ public Manager(int annualSalary) : ...

  8. Word 2016插入公式快捷键

    实用的插入公式快捷键"Alt+=", 与君共享

  9. ios系统视频播放器MPMoviePlayerController应用遇到的坑

    最近在做视频播放时应用系统MPMoviePlayerController播放器播放视频,发现点击快进快退会出现黑屏现象,并且点击完成按钮也不会返回,代码以及界面如下所示: NSURL *url=[se ...

  10. 记录下 js各种证件的正则验证

    身份证 /(^\d{15}$)|(^\d{17}([0-9]|X)$)/    护照 /^[a-zA-Z0-9]{3,21}$/   /^(P\d{7})|(G\d{8})$/    军官证或士兵证 ...