The key of MC in "bzoj3439" KPM

Source: Internet
Author: User

Main topic:

There are n strings, numbered 1~n, that each string in the other string is numbered in a string that is suffixed with the number K small string.

Ideas:

Trie the string upside down, recording the number of each end node (there may be duplicates, so open a vector record). The trie tree is then Dfs ordered, and the sub-tree interval of the end node is recorded. The interval k is small, naturally with the persistence of the segment tree (since the weight is the ID, so it does not need to be discretized). Note: The DFS sequence at the end of the node is encountered only when the serial number of the variable cnt, and the same string of DFS serial number is the same (that is, a tail node may contain many different numbered strings), the left interval takes the first one (such as DFS to x node, numbered 2,x node has two strings, Then their left interval is 2, and the sequence number will be added two times.

Reference from: http://blog.csdn.net/xym_CSDN/article/details/51340321

Code:

1#include <vector>2#include <cstdio>3#include <cstring>4#include <iostream>5 #defineM 5000096 using namespacestd;7Vector <int>Q[m];8 intcnt,trie[m][ -],num[m],com[m], out[m],dat[m],sum[m<<2],lc[m<<2],rc[m<<2];9 CharS[m];Ten  One voidInsintIdChar*str) A { -     intI,l=strlen (str), j=0, K; -      for(i=l-1; i>=0; I--, j=Trie[j][k]) the         if(!trie[j][k=str[i]-'a']) trie[j][k]=++CNT; -num[j]++; q[j].push_back (ID); - } -  + voidDfsintx) - { +     inti; A      for(i=0; i<num[x];i++) com[q[x][i]]=cnt+1; at      for(i=0; i<num[x];i++) dat[++cnt]=Q[x][i]; -      for(i=0;i< -; i++)if(Trie[x][i]) DFS (trie[x][i]); -      for(i=0; i<num[x];i++) out[q[x][i]]=CNT; - } -  - voidBuildintLintRintCurint_cur,intx) in { -sum[cur]=sum[_cur]+1; to     if(L==R)return;intMid=l+r>>1; +     if(X<=mid) lc[cur]=++cnt,rc[cur]=Rc[_cur],build (l,mid,lc[cur],lc[_cur],x); -     ElseLc[cur]=lc[_cur],rc[cur]=++cnt,build (mid+1, r,rc[cur],rc[_cur],x); the } *  $ intAskintLintRintLintRintk)Panax Notoginseng { -     if(L==R)returnL; the     intMid=l+r>>1, t=sum[lc[r]]-Sum[lc[l]]; +     if(t>=k)returnAsk (l,mid,lc[l],lc[r],k); A     Else returnAsk (mid+1, r,rc[l],rc[r],k-t); the } +  - intMain () $ { $     intN,i,x; scanf"%d",&n); -      for(i=1; i<=n;i++) scanf ("%s", s), INS (i,s); -      for(cnt=0, DFS (0), cnt=n+1, i=1; i<=n;i++) Build (1, n,i+1, I,dat[i]); the      for(i=1; i<=n;i++) -     {Wuyiscanf"%d",&x); the         if(sum[ out[i]+1]-SUM[COM[I]]&LT;X) printf ("-1\n"); -         Elseprintf"%d\n", Ask (1, N,com[i], out[i]+1, x)); Wu     } -     return 0; About}

"bzoj3439" KPM the MC cipher key

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.