用线段树可以算出序列。然后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,k,q,sz,cnt,p;
int s[*maxn],ans[maxn]; void build(int l,int r,int rt)
{
s[rt]=;
if(l==r){ s[rt]=; return;}
int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+);
s[rt]=s[*rt]+s[*rt+];
} void get(int sum,int l,int r,int rt)
{
if(l==r) { s[rt]=, p=l; return; }
int m=(l+r)/;
if(s[*rt]>=sum) get(sum,l,m,*rt);
else get(sum-s[*rt],m+,r,*rt+);
s[rt]=s[*rt]+s[*rt+];
} int main()
{
// File();
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&k,&q);
build(,n,); sz=n; cnt=;
while(sz>)
{
int mx=(sz-)/k;
for(int i=;i<=mx;i++)
{
int sum=+i*k-i;
get(sum,,n,); ans[++cnt]=p; sz--;
}
}
for(int i=;i<=q;i++)
{
int x; scanf("%d",&x);
printf("%d\n",ans[x]);
}
}
return ;
}

HDU 5860 Death Sequence的更多相关文章

  1. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5860 Death Sequence(递推)

    HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...

  3. hdu 5860 Death Sequence(递推+脑洞)

    Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historian liv ...

  4. 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...

  5. 2016暑假多校联合---Death Sequence(递推、前向星)

    原题链接 Problem Description You may heard of the Joseph Problem, the story comes from a Jewish historia ...

  6. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  7. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  8. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  9. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

随机推荐

  1. MySQL索引类型

    一.简介 MySQL目前主要有以下几种索引类型:1.普通索引2.唯一索引3.主键索引4.组合索引5.全文索引 二.语句 CREATE TABLE table_name[col_name data ty ...

  2. [ios2]tableView去除空行的singleLine

    http://www.winddisk.com/2013/03/29/tableview%E5%8E%BB%E9%99%A4%E7%A9%BA%E8%A1%8C%E7%9A%84singleline/ ...

  3. Git学习笔记(一)创建版本库并添加文件

    最近从廖雪峰老师的个人网站上学习git,做点笔记. ★★★★★ 先注册自己的username和email,否则会报如下错误: 注册:git config --global user.name &quo ...

  4. Hadoop集群搭建步骤

    实验性操作是在虚拟机里进行的,除了搭建hadoop本身的操作之外,遇到的其它问题总结如下: 1. 虚拟机挂载windows磁盘: 添加硬件,要保证该硬件此时没有被读写访问等,因为挂载后,该磁盘在宿主机 ...

  5. http缓存与cdn相关技术

    阅读目录 一 http缓存 二.Http缓存概念解析 三.cdn相关技术 摘要:最近要做这个主题的组内分享,所以准备了一个星期,查了比较多的资料.准备的过程虽然很烦很耗时间,不过因为需要查很多的资料, ...

  6. MATLAB编译器

    1. mcc filename.cpp 或者mcc filename.c 可以将cpp或者c源程序文件,编译为filename.mexw32(32位系统)或者filename.mexw64(64位系统 ...

  7. CentOS+OpenCV图像的读入、显示

    以管理员身份运行su root输入密码 定位到自己的桌面目录 gedit 1.cpp 编辑内容 #include<opencv2/opencv.hpp>using namespace cv ...

  8. delphi 程序输出文件夹存放位置

  9. Signalr 实现心跳包

    项目分析: 一个实时的IM坐席系统,客户端和坐席使用IM通信,客户端使用android和ios的app,坐席使用web. web端可以保留自己的登录状态,但为防止意外情况的发生(如浏览器异常关闭,断网 ...

  10. WinForm笔记一:文本框只允许输入数字

    在WinForm的文本框中,有时候只允许数字,而不能输入除数字以外的其他字符,要调用TextBox的KeyPress事件,代码如下: //只允许输入数字 if (e.KeyChar<'0'||e ...