这题一开始写的线段数是从中间开始查找 k个 导致是nlogn 每次查找应该都是从头找每次找的个数不同就好了

还有一种递推的写法我放下面了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e6+5;
const int MOD = 1e9+7; int N,K,Q;
int ans[MAXN];
int turn[MAXN];
int dp[MAXN];
int a[MAXN];
int main(){
int T; scanf("%d",&T);
while(T--) {
scanf("%d %d %d",&N,&K,&Q); int tt = N;
int tot = 0;
turn[0] = 0;
while(tt) {
++tot;
turn[tot] = turn[tot-1] + (tt-1) / K + 1;
tt = tt-1-(tt-1)/K;
} for(int i = 0; i < N; ++i) {
dp[i] = i%K? dp[i - i/K -1]+1 : 0;
a[i] = i%K? a[i - i/K -1] : i/K+1;
}
for(int i = 0; i < N; ++i) {
int tmp = turn[dp[i]] + a[i];
ans[tmp] = i+1;
} for(int i = 0; i < Q; ++i) {
int a; scanf("%d",&a);
printf("%d\n",ans[a]);
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int MAXN = 3e6+5;
int N,K,Q;
int tree[MAXN<<2];
int st[MAXN];
void Build(int l,int r,int rt){
tree[rt] = r-l+1;
if(l == r) {
return;
}
int m = (l+r)>>1;
Build(lson); Build(rson);
} int Ed;
void Find(int sum,int l,int r,int rt) {
if(l == r) {
tree[rt] = 0; Ed = r; return;
}
int m = (l+r) >>1;
if(tree[rt<<1] >= sum) Find(sum,lson);
else Find(sum-tree[rt<<1],rson);
tree[rt] = tree[rt<<1] + tree[rt<<1|1];
} int main(){
int T; scanf("%d",&T);
while(T--){
memset(tree,0,sizeof(tree));
scanf("%d %d %d",&N,&K,&Q);
Build(1,N,1); int sz = N; int cnt = 0;
while(sz>0) {
int mx = (sz-1)/K;
for(int i = 0; i <= mx; ++i) {
int sum = 1+i*K-i;
Find(sum,1,N,1);
st[++cnt] = Ed; sz--;
}
} for(int i = 1; i <= Q; ++i){
int a; scanf("%d",&a);
printf("%d\n",st[a]);
}
}
return 0;
}

hdu5860 Death Sequence的更多相关文章

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

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

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

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

  3. HDU 5860 Death Sequence(递推)

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

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

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

  5. HDU 5860 Death Sequence

    用线段树可以算出序列.然后o(1)询问. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<c ...

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

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

  7. HDU5860 (递推)

    Problem Death Sequence 题目大意 排成一行的约瑟夫问题. n个人排成一行,从第一个人开始,每个k个人报数,报到数的人被杀死,剩下的人重新排成一行再报数. 一共q个询问,每次询问第 ...

  8. 2016 Multi-University Training Contest 10

    solved 7/11 2016 Multi-University Training Contest 10 题解链接 分类讨论 1001 Median(BH) 题意: 有长度为n排好序的序列,给两段子 ...

  9. The Kernel Newbie Corner: Kernel Debugging with proc "Sequence" Files--Part 3

    转载:https://www.linux.com/learn/linux-career-center/44184-the-kernel-newbie-corner-kernel-debugging-w ...

随机推荐

  1. Tomcat部署war应用总结

    前言:罗列在Tomcat部署web应用的几种方法,供以后翻阅,其中的以helloapp为例 Tomcat目录介绍 简单目录介绍: bin目录:包含tomcat启动/关闭等脚本,支持linux.wind ...

  2. DaemonSet 典型应用场景 - 每天5分钟玩转 Docker 容器技术(129)

    Deployment 部署的副本 Pod 会分布在各个 Node 上,每个 Node 都可能运行好几个副本.DaemonSet 的不同之处在于:每个 Node 上最多只能运行一个副本. DaemonS ...

  3. Azure Automation (5) 调整Azure SQL Database DTU

    <Windows Azure Platform 系列文章目录> 之前有客户提了需求,在9点以后,把Azure SQL Database DTU提高 在凌晨,把Azure SQL Datab ...

  4. Python tutorial阅读之使用 Python 解释器

    配置环境变量后,一般可以直接通过Python或指定Python版本号来调用Python. Python 解释器有些操作类似 Unix shell:当使用终端设备(tty)作为标准输入调用时,它交互的解 ...

  5. 蛋疼的_after_insert

    这两天在做一个素材类的网站,用的依旧是TP3.2,在做到发布话题这部分的时候,发现了一个问题,我在添加话题的时候在模型里写了个钩子函数_after_insert(),希望在新增话题数据之后同时将话题的 ...

  6. 【linux之bash】

    bash的发展 1974年 贝尔实验室 Bourne Bourne Shell --> Bsh.sh 1978年 berke bill jey C shell --> Csh tcsh 8 ...

  7. LeetCode - 620. Not Boring Movies

    X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a ...

  8. [Python Study Notes]进程信息(丁丁软件监控进程,http-post)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  9. LNMP搭建03 -- 编译安装PHP

    [编译安装PHP]  为了顺利安装PHP,先安装下面这些: [CentOS 编译 PHP 前要做的事情] yum install -y gcc gcc-c++  make zlib zlib-deve ...

  10. 洛谷P1962 斐波那契数列【矩阵运算】

    洛谷P1962 斐波那契数列[矩阵运算] 题目背景 大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) ( ...