bzoj2754 [SCOI2012] Meow name on the planet (suffix array + tree array)

Source: Internet
Author: User

2754: [SCOI2012] The name on the Meow planet Time limit:20 Sec Memory limit:128 MB submit:2745 solved:1190 [Submit] [Status] [Discuss] Description

A180285 was fortunate to have been chosen as an international student for the Earth to meow. He found that it was interesting to see the cat names before class. Suppose there are n cats in the class, and each meow name consists of a surname and a name. The teacher on the Meow Planet chooses M-string to roll the name, and each time a string is read out, if the string is a substring of the surname or name of a Mew, then the MEW must answer. However, because the loadline of the Mew are too eccentric to be expressed in ASCII. To facilitate the description, a180285 decided to use several strings to denote the name of the Mew.
Now can you help a180285 count the number of cats answered at each call, and how many times do each meow answer after the end of the M-roll?

Input

Now define the string given method on the Meow planet:
A positive integer l is given, representing the length of the string, followed by an L integer representing each character of the string.
The first line of input is two integers n and M.
Next there are n rows, each containing the first and last names of the I-Cat and two strings. The surname and the name are the standard meow strings on the planet.
Next there are m lines, each containing a string on the Meow planet, indicating the string the teacher named.

Output

For each teacher named string output How many cats should answer.
The last line then outputs how many times each meow is ordered.


Concatenate the name string and the inquiry together (sa\), the following is the meaning of \ (rk\) ;
Then for each query string two points to find \ (lcp\) equal to its length of the interval, and the query string appears in the position;
In this case, the first question is to ask for the number of different numbers in each interval, namely \ (hh\) necklace, MO Team/tree-like array;
The second question is that the multiple suffixes of the same string in an interval are repeated, so the contribution of the adjacent repeating suffix is poor;
For each query \ ([l,r]\), at \ (l\) the \ (w\) interval plus \ (1\),\ (r+1\) at the interval minus \ (1\), The suffix \ (i\) 's contribution is \ (w[i]-w[las[num[i]]]\);
\ (las[num[i]]\) is the same suffix as the \ (i\) parent string, and the tree array can be;
AC Get☆daze

#include <algorithm>#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <vector>#include <cmath>#include <queue>#include <map>#include <set>#define N 600039#define MOD 20070831#define INF 0x3f3f3f3f#define LL Long Longusing namespaceStdstructquestion{intSd,l,r,ans;} ask[n/6];intneko,wa,fir[n/3],len[n/3],bel[n],bit[n],ans[n];intn,m,num[n],sa[n],rk[n],height[n],las[n],buc[n],pw[ -],st[n][ -];BOOLCmp_hh (question I,question j) {returnI.R&LT;J.R;}BOOLCMP_SD (question I,question j) {returnI.SD&LT;J.SD;}voidGet_string (intSTP) {Fir[stp]=n+1; scanf"%d", &AMP;LEN[STP]); for(intA=1; a<=len[stp];a++) {scanf ("%d", &num[++n]);    NUM[N]++,BEL[N]=STP; } num[++n]=10001+STP;}BOOLJudgeintIintJintK) {returnLAS[I]==LAS[J] && las[i+k]==las[j+k];}voidRadix_sort () { for(intA=1; a<=m;a++) buc[a]=0; for(intA=1; a<=n;a++) buc[rk[las[a]]]++; for(intA=1; a<=m;a++) Buc[a]+=buc[a-1]; for(inta=n;a>=1; a--) sa[buc[rk[las[a]]]--]=las[a];}voidGet_sa () { for(intA=1; a<=n;a++) Rk[a]=num[a],las[a]=a; M=n-39, Radix_sort (); for(intA=1, b=0; M<n | | a==1; a<<=1, b=0)    { for(intC=n-a+1; c<=n;c++) Las[++b]=c; for(intC=1; c<=n;c++)if(Sa[c]>a) las[++b]=sa[c]-a; Radix_sort (), m=0; for(intC=1; c<=n;c++) Las[c]=rk[c]; for(intC=1; c<=n;c++) rk[sa[c]]= (judge (sa[c-1],sa[c],a)?    M: ++m); } for(intA=1, b=0; A<=n;a++,b=max (0B-1))    { while(Num[a+b]==num[sa[rk[a]-1]+B]) b++;    Height[rk[a]]=b; }}voidGet_st () {pw[0]=1; for(intA=1;p W[a-1]<=n;a++) Pw[a]=pw[a-1]<<1; for(intA=1; a<=n;a++) st[a][0]=height[a]; for(intA=1;p w[a]<=n;a++) { for(intb=1; b<=n;b++) {St[b][a]=min (st[b][a-1],st[b+pw[a-1]][a-1]); }    }}intRMQ (intLintR) {intStp=log ((Double) r-l+1)/log (2.0);returnMin (ST[L][STP],ST[R-PW[STP]+1][STP]);}intSearch_mae (intSTP) {intL=1, R=RK[FIR[STP]]-1, MID,RES=RK[FIR[STP]]; while(L&LT;=R) {mid=l+r>>1;if(RMQ (mid+1, RK[FIR[STP]]) L=mid &LT;LEN[STP])+1;ElseR=mid-1, Res=mid; }returnRes;}intSearch_ato (intSTP) {intL=RK[FIR[STP]]+1, R=N,MID,RES=RK[FIR[STP]]; while(L&LT;=R) {mid=l+r>>1;if(RMQ (RK[FIR[STP])+1, mid) &LT;LEN[STP]) R=mid-1;ElseL=mid+1, Res=mid; }returnRes;}voidUpdateintPintV) {if(!p)return; while(p<=n) bit[p]+=v,p+= (-p&p);}intQueryintP) {intres=0; while(p) res+=bit[p],p-= (-P&AMP;P);returnRes;}intMain () {scanf ("%d%d", &neko,&wa); for(intA=1, b;a<=neko;a++) {get_string (2*a-1); Get_string (2*A); } for(intA=1, b;a<=wa;a++) {get_string (2*NEKO+A); } get_sa (), Get_st (); for(intA=1; a<=wa;a++) {ask[a].sd=a; Ask[a].l=search_mae (2*NEKO+A); Ask[a].r=search_ato (2*NEKO+A); } sort (ask+1, Ask+wa+1, cmp_hh); for(intA=0; a<=neko;a++) las[a]=0; for(intA=1, b=1; a<=wa;a++) { while(B&LT;=ASK[A].R) {if(bel[sa[b]]<=2*neko) {update (las[bel[sa[b])+1>>1],-1); LAS[BEL[SA[B]]+1>>1]=b; Update (b,1);        } b++; } ask[a].ans=query (ASK[A].R)-query (ASK[A].L-1); } for(intA=0; a<=neko;a++) las[a]=0; for(intA=1; a<=n;a++) bit[a]=0; for(intA=1; a<=wa;a++) Update (ASK[A].L,1); for(intA=1, b=1; a<=n;a++) { while(B<=wa && Ask[b].r<a) {Update (ASK[B].L,-1);        b++; }if(bel[sa[a]]<=2*neko) {Ans[bel[sa[a]]+1>>1]+=query (a)-query (Las[bel[sa[a]+1>>1]); Las[bel[sa[a]]+1>>1]=a; }} sort (ask+1, Ask+wa+1, CMP_SD); for(intA=1; a<=wa;a++) printf ("%d\n", Ask[a].ans); for(intA=1; a<=neko;a++) {printf ("%d", Ans[a]);if(A<neko) printf (" "); }return 0;}

bzoj2754 [SCOI2012] Meow name on the planet (suffix array + tree array)

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.