相关链接
题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3998
离线版题目:http://paste.ubuntu.com/18145026/
数据生成器:http://paste.ubuntu.com/18145048/
解题报告
这个,SAM求k小串的板题,然而我这个纸张写了两次、调了7h+才过QAQ (浅谈模板写挂了的悲伤有多大.pdf
t==0 -> 后缀自动机的每一个节点只代表一个串
t==1 -> 后缀自动机的每一个节点代表|fail数的大小|个节点
然后顺着走一走就好。
Code
#include<iostream> #include<cstdio> #include<cstring> #define LL long long using namespace std; const int MAXN = 1000000+9; const int SGZ = 26; char pat[MAXN]; int n,t; LL k; namespace Suffix_Automaton{ #define SAM Suffix_Automaton int ch[MAXN][SGZ],fail[MAXN],sz[MAXN],len[MAXN]; int cnt,last,bot[MAXN],ord[MAXN]; LL cho[MAXN]; inline void extend(int c){ int w = last; last = ++cnt; len[last] = len[w]+1; sz[last]=1; while (w && !ch[w]) ch[w] = last, w=fail[w]; if (!w) fail[last] = 1; else { int nw = ch[w]; if (len[nw] == len[w]+1) fail[last] = nw; else { int nnw = ++cnt; len[nnw] = len[w]+1; for (int i=0;i<SGZ;i++) ch[nnw][i]=ch[nw][i]; fail[nnw] = fail[nw]; fail[nw] = fail[last] = nnw; while (w && ch[w]==nw) ch[w] = nnw, w = fail[w]; } } } inline void build(){ cnt = last = 1; n = strlen(pat+1); for (int i=1;i<=n;i++) extend(pat[i]-'a'); } inline void sign(){ for (int i=1;i<=cnt;i++) bot[len[i]]++; for (int i=1;i<=n;i++) bot[i] += bot[i-1]; for (int i=cnt;i;i--) ord[bot[len[i]]--] = i; if (t == 1) for (int j=cnt,i=ord[j];j;i=ord[--j]) sz[fail[i]] += sz[i]; else for (int i=2;i<=cnt;i++) sz[i] = 1; for (int j=cnt,i=ord[j];j;i=ord[--j]){ cho[i] += (LL)sz[i]; for (int c=0;c<SGZ;c++) cho[i] += cho[ch[i]]; } } inline void solve(){ if (cho[1] < k) printf("-1\n"); else { int w = 1; while (k > 0){ for (int c=0;c<SGZ && k>0;c++) if (cho[ch[w]] < k) k -= cho[ch[w]]; else {putchar(c+'a');w=ch[w];k-=sz[w];break;} } } } }; int main(){ scanf("%s%d%lld",pat+1,&t,&k); SAM::build(); SAM::sign(); SAM::solve(); return 0; }
Very good blog post.Much thanks again. Cool.
wow, awesome post.Much thanks again. Really Cool.
Enjoyed every bit of your blog post. Keep writing.
I cannot thank you enough for the article.Much thanks again. Fantastic.
Im obliged for the blog.Thanks Again. Want more.
I really like and appreciate your article post.Thanks Again. Will read on…
Wow, great post.Much thanks again. Great.
Major thanks for the post.Thanks Again. Really Great.
Great, thanks for sharing this blog post.Much thanks again. Will read on…
Very good article.Really thank you! Keep writing.
This is one awesome blog article.Thanks Again. Much obliged.
Thanks for sharing, this is a fantastic article.Much thanks again. Fantastic.
Major thanks for the post. Really Great.
This is one awesome blog.Really looking forward to read more. Really Great.
I appreciate you sharing this blog.Really thank you! Will read on…
Awesome blog article. Fantastic.
I really liked your blog.Really looking forward to read more. Fantastic.
I really like and appreciate your article.Much thanks again. Will read on…
Hello friends, its fantastic post about teachingand
fully defined, keep it up all the time.
I cannot thank you enough for the post.Much thanks again. Awesome.
Thanks a lot for the article.Really looking forward to read more. Really Great.
Thank you for the auspicious writeup. It actually was once a amusement account it.
Look complicated to far brought agreeable from you!
However, how can we be in contact?
Fantastic post.Really looking forward to read more. Really Great.
Thanks again for the blog post. Fantastic.
Hey, thanks for the post.Thanks Again. Really Cool.
This is one awesome article post.Much thanks again. Much obliged.
I really enjoy the article post.Much thanks again. Much obliged.
I really enjoy the blog.Really looking forward to read more. Much obliged.
I’ve been exploring for a bit for any high quality articles or
weblog posts on this sort of space . Exploring in Yahoo I eventually stumbled upon this site.
Reading this information So i am happy to show that I’ve a very good uncanny feeling I discovered exactly what
I needed. I such a lot indisputably will make sure to don?t put
out of your mind this web site and provides
it a look on a constant basis.
Thanks for the article post.Much thanks again. Cool.
I truly appreciate this article. Really Great.
A big thank you for your blog. Keep writing.
Very good post.Thanks Again. Awesome.
Awesome post.Really looking forward to read more. Awesome.
A big thank you for your blog.Much thanks again. Awesome.
Great blog.Much thanks again. Will read on…
This is one awesome article post.Really looking forward to read more. Want more.
I was suggested this website via my cousin. I’m now not certain whether or not this post is
written via him as nobody else recognise such special approximately my trouble.
You’re amazing! Thank you!
Thanks so much for the post.Really thank you! Will read on…
I really like and appreciate your blog.Much thanks again. Want more.
Muchos Gracias for your article.Thanks Again. Want more.
Appreciate you sharing, great blog post.Really thank you! Awesome.
Very informative blog article.Really looking forward to read more. Keep writing.
I visited many web pages but the audio feature for audio songs existing at this site is in fact wonderful.
Thank you a lot for sharing this with all of us you actually realize what you’re
speaking about! Bookmarked. Please additionally
discuss with my web site =). We can have a hyperlink trade arrangement among us
I value the post.Really thank you! Will read on…
Nice post. I was checking constantly this blog and I’m impressed!
Very helpful information specially the last part 🙂 I
care for such info much. I was seeking this certain info for a very long time.
Thank you and best of luck.
I am so grateful for your article.Thanks Again. Really Cool.
Hi, i feel that i saw you visited my website thus i came to return the choose?.I’m attempting to in finding things to improve my web site!I suppose its good
enough to use a few of your ideas!!
Really appreciate you sharing this blog article.Thanks Again. Awesome.
Say, you got a nice article.Thanks Again. Awesome.
Hi there! This is kind of off topic but I need some
help from an established blog. Is it very difficult to set up your own blog?
I’m not very techincal but I can figure things out pretty quick.
I’m thinking about creating my own but I’m not sure where
to start. Do you have any tips or suggestions? Many thanks
Hello There. I found your blog using msn. This is an extremely
well written article. I’ll make sure to bookmark it and come back
to read more of your useful information. Thanks for the post.
I will definitely comeback.
I am so grateful for your blog.Really thank you!
Hi there, just became alert to your blog through Google,
and found that it is really informative. I’m going to watch out for brussels.
I’ll be grateful if you continue this in future. A lot of people will be benefited from
your writing. Cheers!
Thanks a lot for the article.Thanks Again. Really Cool.
Thanks-a-mundo for the blog.Really looking forward to read more. Much obliged.
Enjoyed every bit of your post.Really thank you! Really Cool.
wow, awesome blog article.Much thanks again. Really Cool.
Thank you ever so for you blog post.Really looking forward to read more.
Enjoyed every bit of your blog post.Really looking forward to read more. Much obliged.
Hello! I could have sworn I’ve been to this web site before but after browsing through some of the
posts I realized it’s new to me. Nonetheless, I’m certainly
delighted I found it and I’ll be bookmarking
it and checking back regularly!
Very informative blog.Thanks Again. Keep writing.
I got this web site from my buddy who shared with me
concerning this web page and now this time I am browsing this
site and reading very informative articles or reviews here.
I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to design my own blog and would like to find out where u got this from. cheers
Looking forward to reading more. Great blog post.Much thanks again.
Awesome post.Thanks Again. Keep writing.
I have been browsing online more than 4 hours today, yet I never found any interesting article like yours.
It’s pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the web will
be much more useful than ever before.
Fantastic article post.Really looking forward to read more. Cool.
Hey, thanks for the blog.Much thanks again. Fantastic.
Im grateful for the blog post.Much thanks again. Will read on…
Thank you ever so for you blog. Much obliged.
Great blog.Really looking forward to read more. Really Great.
Hey, thanks for the article.Really thank you! Great.
Awesome blog post. Really Great.
Im obliged for the post.Thanks Again. Really Cool.
Thanks for sharing, this is a fantastic article post.Really thank you! Really Great.
This paragraph offers clear idea designed for the new viewers of blogging, that genuinely how to do blogging.
I really enjoy the blog post.Thanks Again. Much obliged.
A big thank you for your blog post.Thanks Again. Keep writing.
I loved your article post. Want more.
Really appreciate you sharing this article.Thanks Again. Awesome.
Im obliged for the article.Much thanks again. Great.
Say, you got a nice blog.Much thanks again. Cool.
Hello Dear, are you really visiting this web site regularly, if so then you will absolutely take nice know-how.
Thank you for your article.Thanks Again. Want more.
Major thankies for the blog article.Really looking forward to read more. Much obliged.
Wow, great article post.Really thank you! Will read on…
Just want to say your article is as surprising.
The clearness in your post is simply excellent and i can assume
you’re an expert on this subject. Well with
your permission let me to grab your RSS feed to keep up to date with forthcoming post.
Thanks a million and please keep up the gratifying
work.
Very informative blog article. Want more.
Awesome article.Thanks Again. Will read on…
I appreciate you sharing this blog.Thanks Again. Keep writing.
I value the blog article.Thanks Again. Really Great.
Muchos Gracias for your article post.Much thanks again. Much obliged.
Really enjoyed this blog.Really thank you! Really Great.
Im thankful for the blog post.Really looking forward to read more. Really Cool.
A round of applause for your post.Really looking forward to read more. Awesome.
Great post.Really thank you! Great.
Thank you for your article post.Really looking forward to read more.
Great, thanks for sharing this blog article.Much thanks again.
Major thankies for the blog.Much thanks again. Want more.
Im obliged for the blog post.Really looking forward to read more. Great.
This is one awesome post.Really thank you! Want more.
Thank you for your blog article.Much thanks again.
Im obliged for the article.Really thank you! Really Cool.
Thanks again for the article.Really looking forward to read more. Really Cool.
Thanks-a-mundo for the blog.Much thanks again.
Very good post.Really looking forward to read more. Really Great.
Thanks so much for the blog post. Keep writing.
wow, awesome article.Thanks Again. Much obliged.
Thanks for sharing your thoughts. I really appreciate your efforts and
I will be waiting for your next post thank you once again.
Awesome blog.Really looking forward to read more. Really Great.
Im obliged for the post. Really Cool.
Thanks again for the blog.Really looking forward to read more. Will read on…
Thanks-a-mundo for the blog.Much thanks again. Fantastic.
Thanks a lot for the blog. Keep writing.
Great, thanks for sharing this article. Keep writing.
Appreciate you sharing, great article.Really looking forward to read more. Will read on…
This is one awesome blog article. Want more.
Really informative blog article.Really looking forward to read more. Keep writing.
I cannot thank you enough for the blog article. Will read on…
Hello there, I do believe your site might be having
web browser compatibility issues. Whenever I look at your blog in Safari, it looks fine
however, when opening in IE, it’s got some overlapping issues.
I merely wanted to give you a quick heads up!
Besides that, excellent blog!
I appreciate you sharing this blog post.Really thank you! Really Cool.
A big thank you for your post.Thanks Again. Really Cool.
Really appreciate you sharing this blog. Keep writing.
Major thankies for the article.
I really like and appreciate your post. Fantastic.
Thanks a lot for the article post. Cool.
I am in fact glad to glance at this website posts which
contains tons of helpful information, thanks for providing these kinds of information.
wow, awesome article.Really thank you! Awesome.
Fantastic blog.Thanks Again. Awesome.
A big thank you for your blog. Really Great.
Major thanks for the article.Thanks Again. Fantastic.
I really enjoy the blog post.Really thank you! Really Cool.
Very informative blog article.Much thanks again. Great.
Really enjoyed this blog.Thanks Again.
Thank you ever so for you blog post.Thanks Again.
I appreciate you sharing this blog post.Really looking forward to read more. Really Great.
Great blog post.Really thank you! Keep writing.
This is one awesome blog post.Much thanks again. Cool.
Im thankful for the post.Really thank you! Awesome.
Appreciate you sharing, great post.Much thanks again. Fantastic.
Say, you got a nice blog post.Really thank you! Keep writing.
I cannot thank you enough for the blog post.Really looking forward to read more. Fantastic.
Im grateful for the article.Much thanks again.
I really enjoy the blog.Really thank you! Awesome.
Thank you ever so for you post.Really looking forward to read more. Much obliged.
Say, you got a nice article post. Much obliged.
I cannot thank you enough for the article.Really looking forward to read more. Want more.
Great article.Really thank you! Fantastic.
A round of applause for your article post.Much thanks again. Great.
Thanks a lot for the blog article. Want more.
Generally I do not read article on blogs, however I wish to say that this write-up very pressured me to try and do it! Your writing taste has been amazed me. Thanks, very nice article.
Im thankful for the blog.Really thank you! Will read on…
I really liked your article post. Want more.
Thanks-a-mundo for the article.Really looking forward to read more. Cool.
Very neat blog article.Much thanks again. Awesome.
Great, thanks for sharing this article.Really thank you! Great.
Great, thanks for sharing this post.Really thank you!
Thank you for your article.Really looking forward to read more. Fantastic.
Thanks for sharing, this is a fantastic article post.Much thanks again. Want more.
Wow, great blog.Much thanks again.
Hey, thanks for the article post.Much thanks again. Really Cool.
Thanks-a-mundo for the blog article. Great.
Hey, thanks for the article post. Great.
Really enjoyed this blog article.Really thank you! Want more.
Thanks for sharing, this is a fantastic blog.Thanks Again. Fantastic.
I really like and appreciate your article.Really looking forward to read more.
Really enjoyed this blog article.Thanks Again. Awesome.
Wow, great post.Really looking forward to read more. Want more.
Awesome blog post.Really looking forward to read more. Cool.
Thanks again for the blog.Thanks Again. Fantastic.
Thank you ever so for you article post.Really thank you! Want more.
wow, awesome blog. Want more.
I appreciate you sharing this post.Really thank you! Really Cool.
Really informative article post.Thanks Again. Will read on…
Thank you ever so for you article post.Thanks Again. Really Cool.
Thank you for your blog. Awesome.
Hey, thanks for the blog. Will read on…
wow, awesome blog post.Much thanks again. Really Great.
Really informative blog. Awesome.
Really informative article. Keep writing.
Thanks for sharing, this is a fantastic post. Cool.
I loved your blog post.Thanks Again. Will read on…
I value the blog.
Im thankful for the blog.Really thank you! Awesome.
Really informative article post.Much thanks again. Awesome.
Very neat blog.Really looking forward to read more. Much obliged.
A round of applause for your blog.Thanks Again. Want more.
Looking forward to reading more. Great blog.Thanks Again. Will read on…
I am so grateful for your post. Cool.
I cannot thank you enough for the article.Really looking forward to read more. Great.
I loved your blog post.Really looking forward to read more. Keep writing.
A big thank you for your article. Awesome.