这题一开始写的线段数是从中间开始查找 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. iterator和for of 循环

    JavaScript 原有的表示"集合"的数据结构,主要是数组(Array)和对象(Object),ES6 又添加了Map和Set.这样就有了四种数据集合,用户还可以组合使用它们, ...

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

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

  3. 2018/1/21 Netty通过解码处理器和编码处理器来发送接收POJO,Zookeeper深入学习

    package com.demo.netty; import org.junit.Before;import org.junit.Test; import io.netty.bootstrap.Boo ...

  4. 关于ssh登录出现异常警告:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

    提示警告信息如下: arnold@WSN:~$ ssh 10.18.46.111 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...

  5. neo-thinsdk-cs 之 thinWallet 接入私链

    neo-thinsdk-cs 之 thinWallet 接入私链 2017年底刚开始接触区块链,目前在被 NEO 折磨. 一开始被官方文档和 NEO-GUI 搞得体无完肤(尤其是传说中的 F12),也 ...

  6. 图论算法-最小费用最大流模板【EK;Dinic】

    图论算法-最小费用最大流模板[EK;Dinic] EK模板 const int inf=1000000000; int n,m,s,t; struct node{int v,w,c;}; vector ...

  7. php 高并发下 秒杀处理思路

    1.用额外的单进程处理一个队列,下单请求放到队列里,一个个处理,就不会有并发的问题了,但是要额外的后台进程以及延迟问题,不予考虑. 2.数据库乐观锁,大致的意思是先查询库存,然后立马将库存+1,然后订 ...

  8. python进阶学习笔记(一)

    python进阶部分要学习的内容: 学习目标: 1.函数式编程 1.1,什么是函数式编程 函数式编程是一种抽象计算的编程模式 不同语言的抽象层次不同: 函数式编程的特点: python支持的函数式编程 ...

  9. 记一次内存溢出的分析经历——thrift带给我的痛orz

    说在前面的话 朋友,你经历过部署好的服务突然内存溢出吗? 你经历过没有看过Java虚拟机,来解决内存溢出的痛苦吗? 你经历过一个BUG,百思不得其解,头发一根一根脱落的烦恼吗? 我知道,你有过! 但是 ...

  10. Java语言的分支

    JavaSE:(标准版)是java基础,早期叫j2se,2005改名叫JavaSE(必须). JavaME:(移动版)适合移动端的开发.j2me,2005改名叫java ME(不学) JavaEE:( ...