日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

spoj7258 SUBLEX Lexicographical Substring Search

發布時間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spoj7258 SUBLEX Lexicographical Substring Search 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://www.elijahqi.win/archives/3001
題意翻譯
給定一個字符串,求排名第k小的串
注意樣例的\n是換行
輸入格式:
第一行給定主串(len<=90000)
第二行給定詢問個數T<=500
隨后給出T行T個詢問,每次詢問排名第k小的串,范圍在int內
輸出格式:
對于每一個詢問,輸出T行,每行為排名第k小的串
感謝@Creeper_LKF 提供的翻譯
題目描述
Little Daniel loves to play with strings! He always finds different ways to have fun with strings! Knowing that, his friend Kinan decided to test his skills so he gave him a string S and asked him Q questions of the form:
If all distinct substrings of string S were sorted lexicographically, which one will be the K-th smallest?
After knowing the huge number of questions Kinan will ask, Daniel figured out that he can’t do this alone. Daniel, of course, knows your exceptional programming skills, so he asked you to write him a program which given S will answer Kinan’s questions.
Example:
S = “aaa” (without quotes)
substrings of S are “a” , “a” , “a” , “aa” , “aa” , “aaa”. The sorted list of substrings will be:
“a”, “aa”, “aaa”.
Input
In the first line there is Kinan’s string S (with length no more than 90000 characters). It contains only small letters of English alphabet. The second line contains a single integer Q (Q <= 500) , the number of questions Daniel will be asked. In the next Q lines a single integer K is given (0 < K < 2^31).
Output
Output consists of Q lines, the i-th contains a string which is the answer to the i-th asked question.
輸入輸出格式
輸入格式:
輸出格式:
輸入輸出樣例
輸入樣例#1: 復制
\naaa\n2\n2\n3\n\n
輸出樣例#1: 復制
aa\naaa\n
類似tjoi2015弦論 處理之后類似二分 針對每次詢問 暴力去sam中處理即可

#include<cstdio> #include<cstring> #include<algorithm> #define N 180010 using namespace std; inline char gc(){static char now[1<<16],*S,*T;if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}return *S++; } inline int read(){int x=0,f=1;char ch=gc();while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=gc();return x*f; } char s[N>>1];int c[N>>1],sum[N],size[N],fa[N],len[N],root=1,cnt=1,last=1,rk[N],ch[N][26]; inline void read_s(){int op=0;char ch=gc();while(ch<'a'||ch>'z') ch=gc();while(ch<='z'&&ch>='a') s[op++]=ch,ch=gc(); } inline void insert1(int x){int np=++cnt,p=last;fa[np]=p;len[np]=len[p]+1;for (;p&&!ch[p][x];p=fa[p]) ch[p][x]=np;if (!p) fa[np]=root;else{int q=ch[p][x];if (len[p]+1==len[q]) fa[np]=q;else{int nq=++cnt;memcpy(ch[nq],ch[q],sizeof(ch[q]));fa[nq]=fa[q];fa[q]=fa[np]=nq;len[nq]=len[p]+1;for (;p&&ch[p][x]==q;p=fa[p]) ch[p][x]=nq;}}last=np; } inline void dfs(int x,int k){if(k<=size[x]) return;k-=size[x];for (int i=0;i<26;++i)if(ch[x][i]){if (k<=sum[ch[x][i]]){putchar('a'+i);dfs(ch[x][i],k);return;}k-=sum[ch[x][i]];} } int main(){ // freopen("spoj7258.in","r",stdin);read_s();int le=strlen(s);for (int i=0;i<le;++i) insert1(s[i]-'a');for (int i=1;i<=cnt;++i) ++c[len[i]];for (int i=1;i<=le;++i) c[i]+=c[i-1];for (int i=1;i<=cnt;++i) rk[c[len[i]]--]=i;for (int i=cnt;i;--i){int p=rk[i];size[p]=1;}size[1]=0;for (int i=cnt;i;--i){int p=rk[i];sum[p]=size[p];for (int j=0;j<26;++j) sum[p]+=sum[ch[p][j]];}int T=read(),k;while(T--) k=read(),dfs(root,k),puts("");return 0; }

總結

以上是生活随笔為你收集整理的spoj7258 SUBLEX Lexicographical Substring Search的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。