QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866011#1219. 你的名字sjchsk0 0ms0kbC++265.5kb2025-01-22 10:39:002025-01-22 10:39:00

Judging History

你现在查看的是最新测评结果

  • [2025-01-22 10:39:00]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2025-01-22 10:39:00]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e5 + 3, SIZ = 1.2e6 + 3;
int n, q, res[N], dfn[N], pdfn, siz[N];
string s;

struct Qry{
    string s;
    int l, id;
};
vector<Qry> qr[N];
vector<int> t[N];

namespace sgt{
    #define lc (u << 1)
    #define rc (u << 1 | 1)
    #define mid ((l + r) >> 1)
    int s[SIZ << 2];
    void modify(int u, int l, int r, int x, int val){
        cerr<<x<<endl;
        s[u] = max(s[u], val);
        if(l == r)return;
        if(x <= mid)modify(lc, l, mid, x, val);
        else modify(rc, mid + 1, r, x, val);
    }
    int qry(int u, int l, int r, int L, int R){
        if(L <= l && r <= R)
            return s[u];
        int res = 0;
        if(L <= mid)res = max(res, qry(lc, l, mid, L, R));
        if(R > mid)res = max(res, qry(rc, mid + 1, r, L, R));
        return res;
    }
}

namespace sam{
    int ch[SIZ][26], len[SIZ], fail[SIZ], tot = 1, lst = 1;
    int pos[SIZ], ans[SIZ];
    bool vis[SIZ];
    void append(char x){
        cerr<<"append: "<<x<<endl;
        int p = lst, u = ++tot;lst = u, len[u] = len[p] + 1;
        for(; p && !ch[p][x - 'a']; p = fail[p])ch[p][x - 'a'] = u;
        if(!p)fail[u] = 1;
        else{
            int q = ch[p][x - 'a'];
            if(len[q] == len[p] + 1)fail[u] = q;
            else{
                int nq = ++tot;
                len[nq] = len[p] + 1;
                memcpy(ch[nq], ch[q], sizeof ch[q]);
                fail[nq] = fail[q], fail[u] = fail[q] = nq;
                for(; p && ch[p][x - 'a'] == q; p = fail[p])ch[p][x - 'a'] = nq;
            }
        }
        pos[len[u]] = u;
    }
    void dfs(int u){
        dfn[u] = ++pdfn, siz[u] = 1;
        for(int v: t[u])
            dfs(v), siz[u] += siz[v];
    }
    void build(){
        for(int i = 2; i <= tot; i++)
            t[fail[i]].emplace_back(i), cerr<<i<<' '<<fail[i]<<endl;
        dfs(1);
    }
}

namespace sa{
    int len, sa[N], rk[N], ork[N], base[N], cnt[N], ht[N];
    int getsuf(string &s) {
        len = s.size() - 1;
        for (int i = 1; i <= len; i++) sa[i] = i, rk[i] = s[i];
        for (int len = 1; len <= len; len <<= 1) {
            sort(sa + 1, sa + len + 1, [&](const int &x, const int &y) {
                return rk[x] == rk[y] ? rk[x + len] < rk[y + len] : rk[x] < rk[y];
            });
            memcpy(ork, rk, sizeof rk);
            int cur = 0;
            for (int i = 1; i <= len; i++) {
                if (ork[sa[i]] != ork[sa[i - 1]] || ork[sa[i] + len] != ork[sa[i - 1] + len])
                    cur++;
                rk[sa[i]] = cur;
            }
            if (cur == len)
                break;
        }
        int cht = 0, tot = (len + 1) * len / 2;
        for (int i = 1; i <= len; i++) {
            if (rk[i] == 1)continue;
            if (cht)cht--;
            while (s[i + cht] == s[sa[rk[i] - 1] + cht]) cht++;
            ht[rk[i]] = cht, tot -= cht;
        }
        return tot;
    }
}

int rendpos(int u){
    cerr<<u<<": "<<dfn[u]<<' '<<dfn[u] + siz[u] - 1<<endl;
    return sgt::qry(1, 1, sam::tot, dfn[u], dfn[u] + siz[u] - 1);
}

void solve(){
    for(int i = 1; i <= n; i++)
        sam::append(s[i]);
    sam::build();
    for(int r = 1; r <= n; r++){
        sgt::modify(1, 1, sam::tot, dfn[sam::pos[r]], r);
        for(auto &[qr, l, id]: qr[r]){
            int tot = sa::getsuf(qr), len = qr.size() - 1;
            int cur = 1, clen = 0;
            for(int i = 1; i <= len; i++){
                while(cur && !sam::ch[cur][qr[i] - 'a'])cur = sam::fail[cur];
                clen = min(clen, sam::len[cur]);
                if(!cur)
                    cur = 1, clen = 0;
                else cur = sam::ch[cur][qr[i] - 'a'], clen++;

                int u = cur;
                if(!sam::ans[u]){
                    int p = rendpos(u);
                    int tmp = min({clen, sam::len[u], p - l + 1}) - sam::len[sam::fail[u]];
                    tot -= max(0ll, tmp - sam::ans[u]);
                    sam::ans[u] = max(sam::ans[u], tmp);
                }
                u = sam::fail[u];
                while(u && !sam::vis[u]){
                    sam::vis[u] = 1;
                    int p = rendpos(u);
                    int tmp = min(p - l + 1, sam::len[u]) - sam::len[sam::fail[u]];
                    tot -= tmp, sam::ans[u] = max(sam::ans[u], tmp);
                    u = sam::fail[u];
                }
            }
            res[id] = tot;
        }
        for(auto &[qr, l, id]: qr[r]){
            int len = qr.size() - 1;
            int cur = 1, clen = 0;
            for(int i = 1; i <= len; i++){
                while(cur && !sam::ch[cur][qr[i] - 'a'])cur = sam::fail[cur];
                clen = min(clen, sam::len[cur]);
                if(!cur)
                    cur = 1, clen = 0;
                else cur = sam::ch[cur][qr[i] - 'a'], clen++;

                int u = cur;
                sam::ans[u] = 0, sam::vis[u] = 0;
                u = sam::fail[u];
                while(u && sam::vis[u]){
                    sam::vis[u] = 0;
                    u = sam::fail[u];
                }
            }
        }
    }
}

main(){
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> s, n = s.size(), s = ' ' + s;
    cin >> q;
    for(int i = 1; i <= q; i++){
        string tmp;cin >> tmp, tmp = ' ' + tmp;
        int l, r;cin >> l >> r;
        qr[r].push_back({tmp, l, i});
    }
    solve();
    for(int i = 1; i <= q; i++)
        printf("%lld\n", res[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 0
Runtime Error

input:

aadccabccdcddcdabbbdbdaabcadbcadcccdcadbadaabaaacbacdcdccdcdabbbdbdaadcabdabdbacabdadadbdadbdcddbcbcbaddaaaabccdaddcaaabdbabbcabdbcdccaaddbdcdbbcaccdababdbbdabdcbcccacbddddaacbaccaacadbdbdcabc
190
acdabdbcdcabbacbdacaccbcaddadabccdaabdcdcbcdaadccadcdcaccdcaadcaaddccddbbbadbadbdcaacccdbbbcbdbabcacacb...

output:


result:


Test #2:

score: 0
Runtime Error

input:

adbdadddcaddcdaacabadbbbacccaadddcdabaaccbbcbacccbdcdbaabbcbddcdadcabcacccccddbdabbbaacaadcdaddbabcabbbddcdccbaddbbbcdbcabdaaabbdaaadcdacbabccdadbabbdaddcbccddadbdcabcdaabbbabcdacbcaaccabcbaabcbcddcddbbbbaadacbddabbdddabbddbcbdabccbbdacbbdccdbddcdcdcadadbbacbdabbbcddcbadcdddaaabdbbdadddaabbdbaaccdab...

output:


result:


Test #3:

score: 0
Runtime Error

input:

abbabcabadbcbbccbabdcbbacdddcccddadabcadabaadcaddbaaccacaabcbbbcabbbdcbadbaadccdbbdbaaccadbbabdccbcaabbaaccabcbabbcaacbdbbadadbdcbddbbcddcaaacbadabbaacaadddacbadbbddaabbcaccdbdabbcdbbccadccaadabccdaddcabbabadadabdbbadacadcaacbcdccdccaddaacdccbacadaccdbccddacbdcabadbcbbaaccbbabcddccdaabacbcbdbcbdbddb...

output:


result:


Test #4:

score: 0
Runtime Error

input:

ddadbccdbdaacdacabdadadcbdbbadddcadbdadddcaddbbacbddddacccccbcabbbdaddcacbbcaaadaaddadadddbadabbadcdbacbdaddadbbbbccdbacaaabcacccdccaaabaddababacdbaccbbbddaabaacadbcddbbcaaccbbbbbdaddaabddbcdbaacbcadbdbccbcbbdacdacbbbcdccadcdbaacbcaadbabadcaccabdddacacabdbcdadccaddcdcaaabcacccbdbdadcbdcabddabbdabdcd...

output:


result:


Test #5:

score: 0
Runtime Error

input:

bacccaaabdacddbbabdabccbdabddccdbcdcdbdbccbddbbcaaddaacdcaaadcbcaddbabbaddaaaddaaccdcaccacababccaddaccbcacbbdccabaacacdcbccbdbadcdbbbbacacdcbbbbaadbcbaadbcadadbbddbccaadbdbcbabdaacdcdacdbcdbdccdabbacbddabcabccbbabcddbdddcaabbcaddbbdabcaddbbcaadabcbdcabcacdaabbdddadaacbbccdbccdabbdcaddddcccdaaaaddada...

output:


result:


Test #6:

score: 0
Runtime Error

input:

jmoifvagmonbuxznpdxtcgfycygerridhihasxonifvcorwbbadpyjvgyveicsfcrcjjecfktxuumtvfjxocbgeoeefrzlykfqeaarrlhkjovevehnezlcjikjjjfuxfoclvirrbctlicoitgwnphfzgzepxyejlsijruxxdvzahqjpaqhgcumtjnwkbskyengdgzbtxteacjoyvndwiturrdtlcyccbckhmlfyqohfcjvzhtcuqxxpexkvlckohvidmwkghiijakocqyjskcfoxxzffzgtylbiyythobvdx...

output:


result:


Test #7:

score: 0
Runtime Error

input:

jxfsgnlqidcnbfleihizzderbbyzminbutjjknmojrymnghyunksfsqtfijisxyxfaygactkupfrpnugcrvhseqxpdiyrzrzanctqtygvhpumvlxwmvduwbysmkzpckcgbjxmlgyfhdpdjqehloisnpilhpshexuljbjlnkcbkjcnpudmycjigdirokeyvcvkmkrsyjbftizewmcfyuxghxqmwmqdvhswdnsjvybvefdnupdkrqcvnlnfbybifdovvapsdjoppvzvkmxjzevqifzclignjponvndafghncmm...

output:


result:


Test #8:

score: 0
Runtime Error

input:

lbmckmhibhhmgglmcbfkclhacldibgaadakchjabmimjlidhhldljfmkegaieahdbjccdhjefbfebedjiefeflbejkihgjbfgeflchegbamekdlaaacfgabdabmfgjgfmjailbdgbhfbmaaclcidkkgldmejjhcmahhmgkimgfclcgkkalgdcmaiieakmkmflhbdmmibkbkfcjieekbccheahgegkfchfchemgkfghmiabllamichbbdbhjlcfafkijgihgmekhkdebkfbkdagdbhcgjmkamlfhmkjgmfafl...

output:


result:


Test #9:

score: 0
Runtime Error

input:

uwhchfeaycdqlasqdrbylqxaridtgcmyrmkdfdahthdwvkojhqxacqomockaqqoanitzhkmcgcdvniteghvxiyjrqziqjiuljewrdwaabtqwfrfalgloikpxcllbngrzphwcsdmiflqvznvuvxivxsvpqfgkefowexaoplhqfenuwawvwhtmocrmqifqdbyudhmkgiucudnxbjaucppbzobxpmqufhvexdvyjiefmxlfpczvqiuqucvnryxicvusurdiaavudphnnmfqgtichpwfvpaglqqzlmbwwwjohdgx...

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

kimblfhedhamehaaacifgbgflkkldkalaakkhlaiejmeccmcffablhblmggjdmkbhljkkhgfjklieakmkjaamgikmccfkfghljahlkijgjdaechcbifailjcglkkedlgicjebfhiebkfciljkeacceejmkaalhcajfhfmkcecdklbdajdlfikkhiekdbebjbbdfgjcjhfbkclbhbbhjfdffegebkjfkcdilemclilbhflaihgihcgkldcbaakhdjhbekibbigibjdmjbbfalhccmddmckgljfmhgjbalbdjg...

output:


result:


Test #11:

score: 0
Time Limit Exceeded

input:

hpfxngoxndlosbzylksgzehfhkodfvqwwbtwlreetgeusomoymlaukhqqeqhfawfvuqjbwyrtwwjzmrtrnhvibtibiachlutcqbsydmynzxzdrkydyyekbmezwhvvfngnlklzdjpgbpjatahwuvoluqjoefktvlwdtynwprfekbpvgqtwmwneaofpktxfudwpibhlqmiybqbvsfsywlbktjcqvzwxtddkmliwukvkqsdssszsbmtnpynoohpgclvufblcdvqwrpjtuayinwqppbuidyynbpaolisqodbrqqt...

output:


result:


Test #12:

score: 0
Time Limit Exceeded

input:

cdfmjmimggmlmabjlakafafdgkbdkaclfemhajdamjkliajhmajfidkghmejelfkjedddkcgbdidelhghbabckiihdjhdjhakmeldjbikdagdfhalfikeggefcmehhgccilmaehhkagafafaegjgakjekcbhbbjgfhimhmlblgmeddfffdhfgmiacadfhglhjaekdaeacdbfmlcjfffbkcbffljjkbhigejmmmhkaljcljibgekjfhefmbjilcahefblblgeledddgemdgihfecclicgbkmilmifflllhmmc...

output:


result:


Test #13:

score: 0
Time Limit Exceeded

input:

ophmmxojwyabxitozutwdxkmleazyhkqzfhqtdjggpjclzkhcerzmpdkprqjkmnpvccyajlwcohqgzqticihosjhxmwymdzoqnawgmtegjqyrngnqcheacmkgbrwsfldsmlnqjkocblhrnwguaexvnfvrceexfqpzumxsuuhfhdhujqoqdxrkknnhiygrabiqspaqdqreiswbcqdjnyqijdzolltfiiismxltjukwuixllitlyjglwwqekrlbkbwutvnifampunpzmpmwyclwxwgrowvnbqqmkreqhrwgvey...

output:


result:


Test #14:

score: 0
Runtime Error

input:

lbmafbiicbjcmhbbmbabkgmbafmmhjldiifkmhejgmdcbijilcaidajjjebklkikjdjefalfkemjmbifalacllkcehbgkdkabiiefmhjcimlmckcbebidhddclhhlabdalegkfhcdbejbdmbhbfgelmkfdbkbdaclahbfggijmbgigilebmbijddfkjbafdjghijiibljgclgbciijhmjdhcjelmhiecaiahkhledfbekdlmcdceecckhkebclhilgbikmfgjmjgflmffkdjjkbcaemagedmcjajgikgefga...

output:


result:


Test #15:

score: 0
Runtime Error

input:

dsppfaesydhozppylwmfzcvsllhggovukeeepvtiodzzdcmlauhymvxijszrobdecuhxjsivtwjtmvphssgvyifmixgddeuofabohugyfnnqbtsjrynkvtvcqkrhwovooktcfwmxagrxgekxdgldaqffybwmdkeykyocudevwdojhcbhipfwclhzmtoyznnbdadomffoaxihkuojezabjppeyzkgwjgcpvuuxvojahfrdeybcklvqwvfftcwkxqfhbddbxfduvitycznkuzgukryyhktzoslzqiiggugpwvr...

output:


result:


Test #16:

score: 0
Runtime Error

input:

lgcjmilcjkfljihhadhcgcljecggdihjjihgdmbgggmdmfligahflfffcbcmfjlfmamfmcllfgffcciihhcfdihlbgbklmkjacjkhjajhaijifebillabigdeichhklajlechjhbeaiahhidemiaaaehkkaelabbdchficchchdcljbbbdmjfldkmjledjkkhldjjagdimadbdkkmcblkgfbmghieiiaamicjlemabecdemjbbhjjadfhlbaaglbfbbbilljmfjmadcmckfegfalkacbkjkafcgaklgabjkm...

output:


result:


Test #17:

score: 0
Runtime Error

input:

crouxgkvirnjrytirundlljrgfwtazivrwzxxwditbfcooymmlaqvtisxnwbhhdusjrqtvebvgmuaietaotldzzsrqtplqfucfyjpfrohwraeeufvpetorvakablkyvvnwetsrqjlxhmjwgqekapdrvcymvxdzojvbsvcjqrjsdnimathoxcldskndebsfnoqpwxjiicaqdaxhmfnozvwhezimqwnwaoktflkfpdqyhuwtdtgqanymowveuxayebwbjeliulrglhaxwgmgvgiqwqvrkwetmdvkshxwpobakc...

output:


result:


Test #18:

score: 0
Runtime Error

input:

hlheiljjdhhlgihkakdbmjjkjbihblhabaaafedcjickgbmimhldcfdgaeaemhheclgeglffkkiklgalagllffkjkkjbkllkgkkbblficjmklljcfallcicmfdflgebfjeacjejeedmimfdeiadbegfkckiaffagigmckdkihdikgilgehmaglhiddljghmfhgikfkgmfkadekgfalhlemfkdeggcdfkhmjdcdabmeebblbgeflbhkcjgdgadlbfmdebkhhhfajjiflejijamgjekelmjhcmakcglmhafdai...

output:


result:


Test #19:

score: 0
Runtime Error

input:

hcickbjbggigfjddcmijgfbafdebdkcldbibaaegkhmdeibkjdjigbmfelkbdablaccmeblcgikdglmllmdagaaaikfjhdcldhmhmiiiccbhehdhbkjdgkkjhfkflckidfibicfihaagficicjkbiiejddegmcahacchfgmkmmlehbelhlmbkamelfjhkmgfljbaffjjfmfhmhafjhhhdlgfggbilkkcghfaalllcdeffbbjichaiedagaalehkcaglcacgldciahdgehibefmghedciddglfbbmdigdbjij...

output:


result:


Test #20:

score: 0
Runtime Error

input:

cjhkkbhdfmbagemlcmcdclghhcebjlaikgbdlbkedeckmimkeffkjfljmghahfgeihehlfhicjckhjmidafdkhfgehjdgdclckchjddkglaijcfcmigkgmhkmggelagbkbkikaghbadbfeifkemehhcljcfjeljejeehbklflekflaedfeclhidaahikdfaeljbhbaffkdblmecidjglkddkmecifgccmjkjhjecgaklmemfcfemlfmbkljjbakdhchehfhaelhgkicdbhgddcfjeikimklccbdmccjiilhf...

output:


result:


Test #21:

score: 0
Runtime Error

input:

acdalbjachemiccjijekjladlmgcdibegjemfggmcajmkdfaicklclhhjjiifdjkglcdieahidalajicmabkejeggmjdacmljghlicficlaidacjegkhgdmalfbgakblgfbglebhjmkccfgkdkcbgddfgcmkkddlmlikljhmcgfddgkfhddkiekkaefbedjhglclfgebfddlbkkadhlahccmbgjagkkchemmhgbcjkcjdgbmbfhmhgckffedkkllkemkegjhbkijhkjmckkgcccebelfdikbfeigdflebkck...

output:


result:


Test #22:

score: 0
Runtime Error

input:

mddlmgjdadiajebkkjdcfcaemmacbeefbiheblhihlahcilkgcgcgbgbkdddbiedlejkaibalfggglkghmddiiikfabgmggecdmifaegcmkfcmlcfhlecifdiejflclehcbajacmakchcekkiddljfdlejgefbgkgicbdjamafjfgcdmhaejffmdaedaidabihdckhjdkfdclaafcibjfidakllflmejfaeeilaehkicmifjcdiagiihchgefafeaabbihmkddcaembjgjdeljjldagjgghammkfagahdjgb...

output:


result:


Test #23:

score: 0
Runtime Error

input:

llfdgmcekbmbimkccddilecgmlimhkklijdgcfjcdkblbglbaaegedfeihjfgigigfbajgakjmmafechejfihfmdkidmlfdcejkkielgcakckilmlgiklmlalklfdcgkhlmlhkjbkhmdkbhmbfidfmccicgcbejmklcmelcigfjjiaifebbdimekgaglhejaadaglhahfkmkljkfakaifihfihikecehmafbgicelabajgghlmffhgfciclmhmbfhbkbbffmikkeadafebkjkdcidbgadmiaelbhkegimmbf...

output:


result:


Test #24:

score: 0
Runtime Error

input:

dhblhcfekgfmbjkhalldhjckleeffihfallgiafelkkehflcmbikdiijmajkeaghlddammajjdffieiidbgedfekciajfflgbgegmfmaljamaliihmjladahiglmkafmiiflcbhbhceimhmhheeidaejgaecmahcmchclijjdjajmkjgjdgkhmljmjlgadflbdkdkgbggdddicllcfkdmajigmglkfcllijleblcaabkajjghhdgkdbllmjhahjecccfhcgmfemljbkamhgbehjkfffaickeagejjhkgmimb...

output:


result:


Test #25:

score: 0
Runtime Error

input:

iiafeelfecahcjmkadhjkdmmelhmaiafglhiabmlafgmackbbkgfdhdhlageljhmlmehhjgbgkjmbaiffjhcfceiidghmggkhlhkcjdjiehfdcjdlkblgbkcdahgiccjiimggkdlhlkgddbiigbjhbdblbggaealbkldjbfdecmcijdfajlgccfbldbkjmbcmkklfmjfblbhieibecfgjcbchkegbdamflhfjfdgjglkakkgheakegkhlllmhljekmidlhfcmjlgmmajmgjmmlfkhhbklgliejcikjehdijd...

output:


result: