这题一开始写的线段数是从中间开始查找 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. 洛谷 [P2764]最小路径覆盖问题

    二分图应用模版 #include <iostream> #include <cstdio> #include <algorithm> #include <cs ...

  2. bzoj 1598: [Usaco2008 Mar]牛跑步 [k短路 A*] [学习笔记]

    1598: [Usaco2008 Mar]牛跑步 题意:k短路 ~~貌似A*的题目除了x数码就是k短路~~ \[ f(x) = g(x) + h(x) \] \(g(x)\)为到达当前状态实际代价,\ ...

  3. js小知识点

    1.setTimeout(function(num){ alert(num);},1000,123); 第三个参数为实参. 2.拼接字符串: document.body.innerHTML = '&l ...

  4. 让js调试更简单—console

    一.显示信息的命令 console.log 用于输出普通信息 console.info 用于输出提示性信息 console.error用于输出错误信息 console.warn用于输出警示信息 最常用 ...

  5. Eclipse Java,debug模式无法调试,调试按钮不可用时解决办法

    经常出现debug模式进入后,debug的几个按钮置灰,F5,6,8,没有任何反应时,这样操作: 退出 Eclipse.打开 Eclipse 目录下的 configuration 下的 org.ecl ...

  6. [HNOI2009] 梦幻布丁

    [HNOI2009] 梦幻布丁 标签: 链表 题解 可以直接用链表启发式合并做. 合并的细节处理稍微有点麻烦. 假如需要变成另一种颜色的那个颜色的个数更多,那么就肯定不能直接合. 维护一个color数 ...

  7. java-redis集合数据操作示例(三)

    redis系列博文,redis连接管理类的代码请跳转查看<java-redis字符类数据操作示例(一)>. 一.集合类型缓存测试类 public class SetTest { /** * ...

  8. ios音乐播放器demo

    闲暇时间,写了一个音乐播放器. 个人认为,基于Demo 的学习是最有效果的. 想学习的同学,欢迎下载.知识,只有在传播的时候才有价值. 不懂之处,欢迎留言询问,将热情解答. 运行图 项目结构图 Git ...

  9. Yii高级模板的安装

    1,如果你使用composer来安装的话,执行下边两条命令. composer global require "fxp/composer-asset-plugin:^1.2.0" ...

  10. Django静态文件路径设置

    提示 : Error fetching command 'collectstatic': You're using the staticfiles app without having set the ...