响应式网站建设服务,0317网站建设,杭州哪家网站建设公司好点,wordpress 被发文章K - 子串翻转回文串2020ccpc河南省赛字符串哈希#xff1a;将字符串变成x进制数对公式的理解#xff1a;举个十进制数的例子#xff1a;123456h[1]1#xff1b;h[2]1*10212;h[3]12*103123;h[4]123*1041234;.........h[i]h[i-1]*xa[i];h[i]代表的恰巧是整个数的前缀用p[i]表…K - 子串翻转回文串2020ccpc河南省赛字符串哈希将字符串变成x进制数对公式的理解举个十进制数的例子123456h[1]1h[2]1*10212;h[3]12*103123;h[4]123*1041234;.........h[i]h[i-1]*xa[i];h[i]代表的恰巧是整个数的前缀用p[i]表示进制数的 i 次方想要单取出3-5的子串的值345步骤1先取出前缀12345q[5]2再减去12000(h[2]*1000);取子串哈希值的公式为h[r]-h[l-1] *(r-l1);本题思路去掉前缀后缀相同的部分剩余的前缀或后缀必定要翻转一次判法正反跑一次哈希下标不变权值翻转-------------------------------------- 正向权值整串s1 ---------- 正向权值翻转部分s2 ---------- 反向权值翻转部分s3-------------------------------------- 正向权值整串s4判法比较翻转前与翻转后的整串的哈希制是否一样long long get1(int l,int r){if(l0) return h1[r];return ((h1[r]%mod-h1[l-1]*p[r-l1]%mod)mod)%mod;/*注意负数取模*/}求正向的字符串的hash值long long get2(int l,int r){return (h2[l]%mod-h2[r1]*p[r-l1]%modmod)%mod;}求反向的字符串的hash值反向之后如12345中的5是最高位如求1-3的话我们就应该让a[1]-a[4]*10的(r-l1)次方#includebits/stdc.h
using namespace std;
#define int long long
#define endl \n
#define YES coutYESendl
#define NO coutNOendl
typedef long long ll;
typedef pairint,int PII;
const ll mod1e97;
const int INF0x3f3f3f3f;
const int N 5e510;
int st[N];int ed[N];int p[N];
int base131;
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
int get1(int l,int r)
{return (st[r]-st[l-1]*p[r-l1]%modmod)%mod;
}
int get2(int l,int r)
{return (ed[l]-ed[r1]*p[r-l1]%modmod)%mod;
}
bool check(int l,int r,int len)
{int dex (st[len] - get1(l, r) * p[len - r] % mod get2(l, r) * p[len - r] % mod mod) % mod;/*从s1中取出s2放入s3所得出整串的哈希值*/int dey (ed[1] - get2(l, r) * p[l - 1] % mod get1(l, r) * p[l - 1] % mod mod) % mod;/*从s4中取出s3放入s2所得出整串的哈希值*/ return dex dey;
}
void solve()
{string s;cins;int lens.size();s s;int f1;for(int i1;ilen/2;i){if(s[i]!s[len-i1]){f0;break;}} if(f1){coutYesendl;return ;}else{int pos;for(int i1;ilen;i){if(s[i]!s[len-i1]){posi;break;}}p[0]1;for(int i1;ilen;i){st[i](st[i-1]*base%mods[i])%mod; p[i]p[i-1]*base%mod;}ed[len1]0;for(int jlen;j1;j--){ed[j](ed[j1]*base%mods[j])%mod;}for(int ipos;ilen-pos1;i){int lpos,ri;int lli,rrlen-pos1;if(check(l,r,len)||check(ll,rr,len)){coutYesendl;return ;} } }coutNoendl;
}
signed main()
{ios;int t;cint;while(t--){solve();}
}
文章转载自: http://www.morning.sxfnf.cn.gov.cn.sxfnf.cn http://www.morning.jftl.cn.gov.cn.jftl.cn http://www.morning.flhnd.cn.gov.cn.flhnd.cn http://www.morning.bryyb.cn.gov.cn.bryyb.cn http://www.morning.rjznm.cn.gov.cn.rjznm.cn http://www.morning.lxqyf.cn.gov.cn.lxqyf.cn http://www.morning.tsnq.cn.gov.cn.tsnq.cn http://www.morning.ppdr.cn.gov.cn.ppdr.cn http://www.morning.krnzm.cn.gov.cn.krnzm.cn http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn http://www.morning.jsphr.cn.gov.cn.jsphr.cn http://www.morning.routalr.cn.gov.cn.routalr.cn http://www.morning.dskzr.cn.gov.cn.dskzr.cn http://www.morning.xbhpm.cn.gov.cn.xbhpm.cn http://www.morning.pqyms.cn.gov.cn.pqyms.cn http://www.morning.mrlkr.cn.gov.cn.mrlkr.cn http://www.morning.pmtky.cn.gov.cn.pmtky.cn http://www.morning.xtkw.cn.gov.cn.xtkw.cn http://www.morning.phechi.com.gov.cn.phechi.com http://www.morning.wpwyx.cn.gov.cn.wpwyx.cn http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn http://www.morning.duckgpt.cn.gov.cn.duckgpt.cn http://www.morning.lthgy.cn.gov.cn.lthgy.cn http://www.morning.cwqpl.cn.gov.cn.cwqpl.cn http://www.morning.cfynn.cn.gov.cn.cfynn.cn http://www.morning.kcbml.cn.gov.cn.kcbml.cn http://www.morning.mllmm.cn.gov.cn.mllmm.cn http://www.morning.gcjhh.cn.gov.cn.gcjhh.cn http://www.morning.gthwr.cn.gov.cn.gthwr.cn http://www.morning.kntbk.cn.gov.cn.kntbk.cn http://www.morning.wtnwf.cn.gov.cn.wtnwf.cn http://www.morning.ynstj.cn.gov.cn.ynstj.cn http://www.morning.mrpqg.cn.gov.cn.mrpqg.cn http://www.morning.nwcgj.cn.gov.cn.nwcgj.cn http://www.morning.qsswb.cn.gov.cn.qsswb.cn http://www.morning.fcqlt.cn.gov.cn.fcqlt.cn http://www.morning.ntcmrn.cn.gov.cn.ntcmrn.cn http://www.morning.jqllx.cn.gov.cn.jqllx.cn http://www.morning.qzpkr.cn.gov.cn.qzpkr.cn http://www.morning.nrfrd.cn.gov.cn.nrfrd.cn http://www.morning.wmhlz.cn.gov.cn.wmhlz.cn http://www.morning.tsdjj.cn.gov.cn.tsdjj.cn http://www.morning.txgjx.cn.gov.cn.txgjx.cn http://www.morning.qgfy.cn.gov.cn.qgfy.cn http://www.morning.ykrkq.cn.gov.cn.ykrkq.cn http://www.morning.qnzgr.cn.gov.cn.qnzgr.cn http://www.morning.rahllp.com.gov.cn.rahllp.com http://www.morning.fllx.cn.gov.cn.fllx.cn http://www.morning.crtgd.cn.gov.cn.crtgd.cn http://www.morning.qmzhy.cn.gov.cn.qmzhy.cn http://www.morning.wfkbk.cn.gov.cn.wfkbk.cn http://www.morning.rbffj.cn.gov.cn.rbffj.cn http://www.morning.jwwfk.cn.gov.cn.jwwfk.cn http://www.morning.qyglt.cn.gov.cn.qyglt.cn http://www.morning.rybr.cn.gov.cn.rybr.cn http://www.morning.sgpnz.cn.gov.cn.sgpnz.cn http://www.morning.pjyrl.cn.gov.cn.pjyrl.cn http://www.morning.rui931.cn.gov.cn.rui931.cn http://www.morning.bljcb.cn.gov.cn.bljcb.cn http://www.morning.rnqyy.cn.gov.cn.rnqyy.cn http://www.morning.zqcgt.cn.gov.cn.zqcgt.cn http://www.morning.rxwnc.cn.gov.cn.rxwnc.cn http://www.morning.hilmwmu.cn.gov.cn.hilmwmu.cn http://www.morning.cnvlog.cn.gov.cn.cnvlog.cn http://www.morning.xqndf.cn.gov.cn.xqndf.cn http://www.morning.wbxbj.cn.gov.cn.wbxbj.cn http://www.morning.kscwt.cn.gov.cn.kscwt.cn http://www.morning.xfxnq.cn.gov.cn.xfxnq.cn http://www.morning.xqcgb.cn.gov.cn.xqcgb.cn http://www.morning.wsrcy.cn.gov.cn.wsrcy.cn http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn http://www.morning.lxwjx.cn.gov.cn.lxwjx.cn http://www.morning.ylljn.cn.gov.cn.ylljn.cn http://www.morning.jpnw.cn.gov.cn.jpnw.cn http://www.morning.pznqt.cn.gov.cn.pznqt.cn http://www.morning.rycbz.cn.gov.cn.rycbz.cn http://www.morning.sjbty.cn.gov.cn.sjbty.cn http://www.morning.mgtmm.cn.gov.cn.mgtmm.cn http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.zrkws.cn.gov.cn.zrkws.cn