建立后缀树(即反序插入字符串的parent树),然后可以发现按照dfs序排列满足其反串按字典序从小到大排列,那么就可以维护出每一刻子树的串长和,然后直接在dfs序上二分确定节点,再在节点内部乱搞即可求出答案。

 1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 200005
4 #define ll long long
5 int V,last,ans,a[N<<1],sz[N<<1],mi[N<<1],id[N<<1],len[N<<1],fa[N<<1],ch[N<<1][31];
6 ll k,mod,l[N<<1],sum[N<<1];
7 char s[N];
8 void add(int c){
9 int p=last,np=last=++V;
10 len[np]=len[p]+1;
11 sz[np]=1;
12 for(;(p)&&(!ch[p][c]);p=fa[p])ch[p][c]=V;
13 if (!p)fa[np]=1;
14 else{
15 int q=ch[p][c];
16 if (len[q]==len[p]+1)fa[np]=q;
17 else{
18 int nq=++V;
19 len[nq]=len[p]+1;
20 memcpy(ch[nq],ch[q],sizeof(ch[q]));
21 fa[nq]=fa[q];
22 fa[np]=fa[q]=nq;
23 for(;(p)&&(ch[p][c]==q);p=fa[p])ch[p][c]=nq;
24 }
25 }
26 }
27 void dfs(int k){
28 a[++a[0]]=k;
29 for(int i=0;i<26;i++)
30 if (ch[k][i])dfs(ch[k][i]);
31 }
32 int main(){
33 int t;
34 scanf("%s%d",s,&t);
35 V=last=1;
36 int n=strlen(s);
37 for(int i=n-1;i>=0;i--)add(s[i]-'a');
38 for(int i=1;i<=V;i++)a[len[i]]++;
39 for(int i=1;i<=n;i++)a[i]+=a[i-1];
40 for(int i=1;i<=V;i++)id[a[len[i]]--]=i;
41 for(int i=1,j=n;i<=V;i++)
42 if (sz[i])mi[i]=--j;
43 memset(a,0,sizeof(a));
44 for(int i=V;i;i--){
45 sz[fa[id[i]]]+=sz[id[i]];
46 mi[fa[id[i]]]=mi[id[i]];
47 }
48 for(int i=V;i;i--)l[i]=(len[fa[i]]+len[i]+1LL)*(len[i]-len[fa[i]])/2*sz[i];
49 memset(ch,0,sizeof(ch));
50 for(int i=1;i<=V;i++)ch[fa[i]][s[mi[i]+len[fa[i]]]-'a']=i;
51 dfs(1);
52 for(int i=1;i<=V;i++)sum[i]=sum[i-1]+l[a[i]];
53 while (t--){
54 scanf("%lld%lld",&k,&mod);
55 k=k*ans%mod+1;
56 int p=lower_bound(sum+1,sum+V+1,k)-sum;
57 k-=sum[p-1];
58 p=a[p];
59 int x=len[fa[p]]+1,y=len[p];
60 while (x<y){
61 int mid=(x+y>>1);
62 if ((mid+len[fa[p]]+1LL)*(mid-len[fa[p]])/2*sz[p]>=k)y=mid;
63 else x=mid+1;
64 }
65 k-=(x+len[fa[p]])*(x-1LL-len[fa[p]])/2*sz[p];
66 printf("%c\n",s[(k-1)%x+mi[p]]);
67 ans+=s[(k-1)%x+mi[p]];
68 }
69 }

[ccKILLKTH]Killjee and k-th letter的更多相关文章

  1. 【干货】”首个“ .NET Core 验证码组件

    前言 众所周知,Dotnet Core目前没有图形API,以前的System.Drawing程序集并没有包含在Dotnet Core 1.0环境中.不过在dotnet core labs项目里可以见到 ...

  2. PHPExcel使用体会

    PHPExcel使用体会 因为毕设导师智能分配系统的需要,系负责人在管理学生和导师时,希望可以使用Excel批量导入学生和导师的信息,学长的报课系统使用的是PHPExcel的类库,于是我也抽空花了2天 ...

  3. Android学习笔记(十)——ListView的使用(上)

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! ListView绝对可以称得上是 Android中最常用的控件之一,ListView允许用户通过手指上下滑动的 ...

  4. CCF认证(1)

    #include <iostream> #include <windows.h> using namespace std; typedef struct letter{ int ...

  5. 424. Longest Repeating Character Replacement

    以最左边为开始,往右遍历,不一样的个数大于K的时候停止,回到第一个不一样的地方,以它为开始,继续.. 用QUEUE记录每次不一样的INDEX,以便下一个遍历开始, 从左往右,从右往左各来一次..加上各 ...

  6. ASCII 码对应表

    Macron symbol ASCII CODE 238 : HTML entity : [ Home ][ español ] What is my IP address ? your public ...

  7. [Swift]LeetCode880. 索引处的解码字符串 | Decoded String at Index

    An encoded string S is given.  To find and write the decodedstring to a tape, the encoded string is ...

  8. CF613E Puzzle Lover

    题意 英文版题面 Problems Submit Status Standings Custom test .input-output-copier { font-size: 1.2rem; floa ...

  9. P1540 机器翻译 模拟

    题目背景 小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章. 题目描述 这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换.对于每个英文单词,软件会先 ...

随机推荐

  1. react之组件数据挂在方式

    1.属性(props) 组件间传值,在React中是通过只读属性 props 来完成数据传递的. props:接受任意的入参,并返回用于描述页面展示内容的 React 元素. import React ...

  2. 题解 [HNOI/AHOI2018]毒瘤

    题目传送门 题目大意 给出一个 \(n\) 个点 \(m\) 条边的无向图,问有多少个点集满足点集中任意两点均不存在边相连. \(n\le 10^5,m-n\le 10\),答案对 \(9982443 ...

  3. xpath helper插件安装提示程序包无效

    参考链接:https://www.jianshu.com/p/b7d782ef81e0 刚学到爬虫,需要在Chrome浏览器安装xpath helper插件结果一直提示"程序包无效" ...

  4. .Net2.0连接PG数据注意事项

    .Net2.0连接PG数据注意事项 第一次用.net操作PG[.NET2.0] 一:Npgsql版本问题 1:如果是.net2.0  建议用2.0.11.0[NuGet搜索npgsql第一个的最低版本 ...

  5. 为什么阿里巴巴开发手册中强制要求 POJO 类使用包装类型?NPE问题防范

    封面:学校内的秋天 背景:写这个的原因,也是我这两天凑巧看到的,虽然我一直有 alibaba Java 开发手册,也看过不少次,但是一直没有注意过这个问题 属于那种看过,但又没完全看过 一起来看看吧冲 ...

  6. 谈谈BEM规范(含代码)

    css规范之BEM规范 前言 引用一句经典名言在编程的世界里其中一件最难的事情就是命名,不管是设计到编程语言还是标记语言都会有命名的需求.今天聊的就是关于css的命名规范的发展过程以及演变. 命名的发 ...

  7. [no_code][Beta] 中期组内总结

    $( "#cnblogs_post_body" ).catalog() 目前scrum meeting beta阶段目前共7次.在alpha阶段我们博客发布时间比较匆忙,是扣分项, ...

  8. gdal3.1.0+VS2017+geos+kml编译总结

    1.简介 gdal3.1.0编译过程中必须依赖proj,编译gdal必须要编译proj,proj的编译需要sqlite3,因此想要编译gdal3.1.0需要先编译proj和sqlite3 2.关于sq ...

  9. 如何清理history

    工作中,需要清理history 清理当前会话历史命令    history -c 清理当前用户所有历史命令     echo > .bash_history     #在用户主目录执行此操作

  10. IE浏览器——网络集合代理无法启动

    用管理员身份运行cmd然后输入 sc config diagnosticshub.standardcollector.service start=demand