[SCU 4503] Tooeasy Or Toodifficult (Manacher+xor-trie)

Source: Internet
Author: User

SCU-4503

Board question, according to test instructions description is divided into three steps
1. For each location-centered palindrome string, and the maximum palindrome string
2. For each palindrome string the length of the XOR prefix and
3. Ask for two different or prefix and XOR maximum (Xor-trie)

Then use the quick power to calculate the JD, and then the size of the FJD

Take a look at the trie. Insert a 0 first

#pragma COMMENT (linker, "/stack:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <map>#include <set>#include <queue>using namespace STD;typedefpair<int,int> Pii;typedef Long LongLL;typedef unsigned Long LongULL;typedef DoubleDBL;typedef Long DoubleLdbl;#define MST (A, B) memset (A,b,sizeof (a) )#define CLR (a) MST (a,0)#define SQR (a) (a*a)Const intMaxl=1e5+Ten;structmanacher{Char*STR;int*mana,len,res; Manacher (Char*,int); ~manacher () {Delete[]str;Delete[]mana;}intQueryint);};structtrie{structNode {CharChrintval,nxt[2]; } *trie;intSiz Trie (intSize) {trie=NewNode[size];memset(Trie,0,sizeof(node) *size); siz=0;} ~trie () {Delete[]trie;}intChnum (Charx) {returnX-' 0 ';}voidADDSTR (Char*);intQueryChar*STR);};CharINPT[MAXL];intMANA[MAXL];Charstr01[ -];intSpr_pow (int, LL,int);Char* NTS (int,Char*);intMain () {intTscanf("%d", &t); for(intck=1; ck<=t; ck++) {scanf('%s ', INPT);intlen=strlen(INPT); Manacher Mana (Inpt,len);intJd= (LL) Spr_pow (Mana.res, (LL) len*len*len,mana.res/3*5+1) +mana.res*4/5; Trie Trie (3e5);intPxor=0, Fjd=pxor; TRIE.ADDSTR (NTS (0, Str01));#ifdef LOCAL         for(intI=1; i<2*len+2; i++)printf("%c", Mana.str[i]);puts(""); for(intI=1; i<2*len+1; i++)printf("%d", Mana.mana[i]);puts("");#endif         for(intI=0; i<len; i++) {pxor^=mana.query (i);//printf ("I_len:%d\n", Mana.query (i));NTS (PXOR,STR01);            Fjd=max (FJD, Trie.query (Str01));        Trie.addstr (STR01); }if(JD&GT;FJD)puts("LIUJC");Else puts("Luoxinchen"); }return 0;}intSpr_pow (intNum,ll mi,intMOD) {intres=1; while(MI) {if(mi&1) res= (LL) res*num)%mod;        Num= (LL) num*num)%mod; mi>>=1; }returnRes;} Manacher::manacher (Char*TSTR,intTlen): Len (tlen) {str=New Char[2*len+Ten]; Mana=New int[2*len+Ten]; res=0; str[0]='! '; for(intI=0; i<len; i++) {str[2*i+1]=' # '; str[2*i+2]=tstr[i]; } str[2*len+1]=' # '; str[2*len+2]=0; mana[1]=1;intp=1, rm=1; for(intI=2; i<2*len+1; i++) {if(rm>i) Mana[i] = min (rm-i+1, mana[2*p-i]);Elsemana[i]=1; while(Str[i-mana[i]] = = Str[i+mana[i]]) mana[i]++;if(i+mana[i]-1&GT;RM) {rm=i+mana[i]-1;        P=i; }if(Res<mana[i]) res=mana[i]; } res--;}intManacher::query (intNP) {returnmana[2*np+2]-1;}voidTRIE::ADDSTR (Char*STR) {intlen=strlen(str), np=0; for(intI=0; i<len; i++) {intCh=chnum (Str[i]);if(Trie[np].nxt[ch]) np=trie[np].nxt[ch];Else{trie[np].nxt[ch]=++siz;            Np=siz;        Trie[np].chr=str[i]; }    }}intTrie::query (Char*STR) {intres=0, np=0; for(intI=0; i< to; i++) {intnow=str[i]-' 0 ';if(trie[np].nxt[now^1]) {np=trie[np].nxt[now^1]; res^=1<< ( --I.); }Else if(Trie[np].nxt[now])        {Np=trie[np].nxt[now]; }    }returnRes;}Char* NTS (intNumCharStr[]) { for(intI= -; i>=0; i--) {str[i]= (num&1)+' 0 '; num>>=1;} str[ to]=0;returnSTR;}

[SCU 4503] Tooeasy Or Toodifficult (Manacher+xor-trie)

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.