/*
HDU 6040 - Hints of sd0061 [ 第k小数查询,剪枝 ]
题意:
给出随机数列 a[N] (N < 1e7)
询问 b[M] (M < 100) ,对于每个询问输出第 b[i]+1小的数字
满足对任意 i,j,k,若b[i] <= b[k] && b[j] <= b[k] 则一定有 b[i]+b[j] <= b[k]
分析:
用 nth_element() 解决第k小数问题
先将询问排序,可以从小到大或从大到小解决,就能每次不断缩小枚举区间
根据询问的限制条件,选择从大到小解决,这样每次剪去的区间至少是一半
*/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
unsigned x, y, z;
unsigned rng61() {
unsigned t;
x ^= x << 16;
x ^= x >> 5;
x ^= x << 1;
t = x;
x = y;
y = z;
z = t ^ x ^ y;
return z;
}
const int N = 1e7+5;
unsigned a[N];
unsigned A, B, C, n, m;
void init()
{
x = A, y = B, z = C;
for (int i = 0; i < n; i++) a[i] = rng61();
}
struct Q{
int id, x;
}q[105];
bool cmp(Q a, Q b) {
return a.x < b.x;
}
unsigned ans[105];
int main()
{
int tt = 0;
while (~scanf("%u%u%u%u%u", &n, &m, &A, &B, &C))
{
for (int i = 0; i < m; i++)
{
scanf("%d", &q[i].x);
q[i].id = i;
}
init();
sort(q, q+m, cmp);
q[m].x = n;
for (int i = m-1; i >= 0; i--)
{
if (q[i].x == q[i+1].x) {
ans[q[i].id] = ans[q[i+1].id]; continue;
}
nth_element(a, a+q[i].x, a+q[i+1].x);
ans[q[i].id] = a[q[i].x];
}
printf("Case #%d:", ++tt);
for (int i = 0; i < m; i++) printf(" %u", ans[i]);
puts("");
}
}

  

HDU 6040 - Hints of sd0061 | 2017 Multi-University Training Contest 1的更多相关文章

  1. HDU 6040 Hints of sd0061 —— 2017 Multi-University Training 1

    Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  2. hdu 6040 Hints of sd0061(stl: nth_element(arr,arr+k,arr+n))

    Hints of sd0061 Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  3. HDU 6040 Hints of sd0061 nth_element函数

    Hints of sd0061 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired ...

  4. HDU 6040 Hints of sd0061(划分高低位查找)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...

  5. HDU 6040 Hints of sd0061(nth_element)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6040 [题目大意] 给出一个随机数生成器,有m个询问,问第bi小的元素是啥 询问中对于bi< ...

  6. HDU 6162 - Ch’s gift | 2017 ZJUT Multi-University Training 9

    /* HDU 6162 - Ch’s gift [ LCA,线段树 ] | 2017 ZJUT Multi-University Training 9 题意: N节点的树,Q组询问 每次询问s,t两节 ...

  7. 2017 Wuhan University Programming Contest (Online Round) Lost in WHU 矩阵快速幂 一个无向图,求从1出发到达n最多经过T条边的方法数,边可以重复经过,到达n之后不可以再离开。

    /** 题目:Lost in WHU 链接:https://oj.ejq.me/problem/26 题意:一个无向图,求从1出发到达n最多经过T条边的方法数,边可以重复经过,到达n之后不可以再离开. ...

  8. 2017 Wuhan University Programming Contest (Online Round) C. Divide by Six 分析+模拟

    /** 题目:C. Divide by Six 链接:https://oj.ejq.me/problem/24 题意:给定一个数,这个数位数达到1e5,可能存在前导0.问为了使这个数是6的倍数,且没有 ...

  9. 2017 Wuhan University Programming Contest (Online Round) B Color 树形dp求染色方法数

    /** 题目:Color 链接:https://oj.ejq.me/problem/23 题意:给定一颗树,将树上的点最多染成m种颜色,有些节点不可以染成某些颜色.相邻节点颜色不同.求染色方法数. 思 ...

随机推荐

  1. Kudu建表语句

    --建表CREATE TABLE kudu_testdb.perf_test_t1( id string ENCODING PLAIN_ENCODING COMPRESSION SNAPPY, int ...

  2. sqarkSQL hiveSql

    查看数据库 show databases; 进入数据库 use 库名 查看表 show tables: select * from 表名 hdfs传输spark sql查询 hive找到指定路径sql ...

  3. python入门小结

    以下划线开头的标识符是有特殊意义的.以单下划线开头(_foo)的代表不能直接访问的类属性,需通过类提供的接口进行访问,不能用"from xxx import *"而导入: 以双下划 ...

  4. 后缀数组 LCP--模板题

    题意: 给你S串和T串,用T串的所有前缀去匹配S串(匹配值是最长公共子串). 问你总值相加是多少. 思路: 先把两个S,T串倒过来,再拼接 S#T 合成一串,跑一下后缀数组 在排序好的rank里计算每 ...

  5. linux常用终端命令(一)终端命令格式(二)文件和目录常用命令

    一.linux终端命令格式 1.终端命令格式 command  [-options]  [parameter] 说明: command :命令名,相应功能的英文单词或单词的缩写 [-options] ...

  6. 从入门到自闭之Python--RESTful API规范与序列化

    RESTful API规范 REST全称是Representational State Transfer,中文意思是表述(编者注:通常译为表征)性状态转移. 它首次出现在2000年Roy Fieldi ...

  7. Ruby Rails学习中:网站导航,Bootstrap和自定义的CSS,局部视图

    添加一些结构 一.网站导航 1.添加一些结构后的网站布局文件 打开文件:app/views/layouts/application.html.erb 简单介绍一下,添加的代码: 我们从上往下看一下这段 ...

  8. pb datawindow 类型

    DataWindow.Processing 判断 DataWindow 对象的类型 可用 DataWindow.Processing 判断 DataWindow 对象的类型,dw的类型如下:     ...

  9. THUWC2020游记

    Day0 找了旅馆吃了东西才发现明天要去西郊宾馆,换旅馆?? 清华还安排住宿? asas了. 下午出去和kx&face报PKU的名.然后门卫不让进,老吕开启忽悠模式,然后很快就忽悠过去了.(我 ...

  10. Struts2 流程原理

    一.流程图 (转) 二.流程详解 1.服务器传递来的请求,通过ActionContextClearUp.other filters.最后到达StrutsPrepareAndExecuteFilter ...