QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#648111#6228. 字符串Jerrywang100 ✓101ms25692kbC++142.3kb2024-10-17 17:05:122024-10-17 17:05:15

Judging History

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

  • [2024-10-17 17:05:15]
  • 评测
  • 测评结果:100
  • 用时:101ms
  • 内存:25692kb
  • [2024-10-17 17:05:12]
  • 提交

answer

// Title:  字符串
// Source: SNOI2020
// Author: Jerrywang
#include <cstdio>
#include <iostream>
#include <vector>
#define ll long long
#define rep(i, s, t) for(int i=s; i<=t; ++i)
#define debug(x) cerr<<#x<<":"<<x<<endl;
const int N=300010;
using namespace std;

char s[N]; int n, m, k, rnk[N+N], last[N+N], sa[N], tmp[N], cnt[N], ht[N];
void init()
{
    rep(i, 1, n) rnk[i]=s[i];
    rep(i, n+1, n+n) last[i]=rnk[i]=0;
    int mx=127; rep(i, 1, n) sa[i]=i;
    for(int len=2; len/2<=n; len<<=1)
    {
        rep(i, 1, n) last[i]=rnk[i];
        rep(i, 0, mx) cnt[i]=0;
        rep(i, 1, n) cnt[last[i+len/2]]++;
        rep(i, 1, mx) cnt[i]+=cnt[i-1];
        rep(i, 1, n) tmp[cnt[last[i+len/2]]--]=i;
        rep(i, 0, mx) cnt[i]=0;
        rep(i, 1, n) cnt[last[i]]++;
        rep(i, 1, mx) cnt[i]+=cnt[i-1];
        for(int i=n; i; i--)
        {
            int x=tmp[i];
            sa[cnt[last[x]]--]=x;
        }
        mx=1; rnk[sa[1]]=1;
        rep(i, 2, n)
        {
            if(!(last[sa[i-1]]==last[sa[i]] && last[sa[i-1]+len/2]==last[sa[i]+len/2]))
                mx++;
            rnk[sa[i]]=mx;
        }
        if(mx==n) break;
    }
    int h=0;
    rep(i, 1, n)
    {
        if(rnk[i]==1) continue;
        if(h) h--;
        int j=sa[rnk[i]-1];
        while(s[i+h]==s[j+h] && i+h<=n && j+h<=n) h++;
        ht[rnk[i]]=h;
    }
}

int fa[N], sz[N], id[N]; vector<int> vec[N];
int root(int u) {return fa[u]==u?u:fa[u]=root(fa[u]);}
ll res;
void merge(int u, int v, int i)
{
    u=root(u), v=root(v);
    if(u==v) return;
    if(id[u]+id[v]==3)
    {
        if(sz[u]<sz[v]) swap(u, v);
        res+=(ll)i*sz[v];
        sz[u]-=sz[v], fa[v]=u;
    }
    else
    {
        sz[u]+=sz[v], fa[v]=u;
        id[u]=max(id[u], id[v]);
    }
}

int main()
{
#ifdef Jerrywang
    freopen("in.txt", "r", stdin);
#endif
    scanf("%d%d", &m, &k); n=m+m;
    scanf("%s", s+1), scanf("%s", s+m+1);
    init();
    rep(i, 1, n)
    {
        fa[i]=i;
        if(sa[i]+k-1<=m) id[i]=1, sz[i]=1;
        else if(sa[i]>m && sa[i]+k-1<=n) id[i]=2, sz[i]=1;
    }
    rep(i, 2, n) vec[ht[i]].push_back(i);
    for(int i=n; i; i--)
    {
        rep(j, 0, (int)vec[i].size()-1)
            merge(vec[i][j], vec[i][j]-1, min(i, k));
    }
    printf("%lld", (ll)k*(m-k+1)-res);

    return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 2ms
memory: 21732kb

input:

11 1
rbbzzmxmbmz
rbzmrbzxxxz

output:

3

result:

ok single line: '3'

Test #2:

score: 10
Accepted
time: 5ms
memory: 21436kb

input:

11 5
iiecieccice
ecccceicicc

output:

27

result:

ok single line: '27'

Test #3:

score: 10
Accepted
time: 0ms
memory: 24152kb

input:

11 2
vfxaikwshqw
vcrstlhgupu

output:

17

result:

ok single line: '17'

Test #4:

score: 10
Accepted
time: 0ms
memory: 22796kb

input:

11 5
abbaaaababb
babbabbabba

output:

24

result:

ok single line: '24'

Subtask #2:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 0ms
memory: 22696kb

input:

189 183
ggzkilwnazromarxgofvbpvoiyxjezsnazromsuadvbqcrbpcgopuaflzxarxsclfzjymwofsoupxgrokklvydfclzkvzosyromseacgopuadvbqcadvbzgrovetzatvbgrgcrdfgwlyokkavyrooibhplfopwyrvkdqtplqjvetarxscoalmscxmjpzt
pceqoxxlwnazromseacqiyzsbmksznaafomibhgsomseaccjgfsoupxgrokkavyromseavzzxarmprlpcgopuadvbqcrxhotzatvgt...

output:

1281

result:

ok single line: '1281'

Test #6:

score: 10
Accepted
time: 0ms
memory: 21324kb

input:

200 57
fepkbvxoerpcvroebkmqhnffauhmrupetettegzclvsuahdpjpbudmlgqoejupzgxwudnyuiyyjgmqhgwsgsgxwpkpqjszlxyoxueypcughhvttnxzskldvfngvvbzxsetkypupmwszsexkplmgspfbzxsetkypcughgwsgstdmjpgxlfzexlxygayahepkbkmqhnkkm
oexzskldvfnudxwudnmxsetkvxoerxonxzjdoejuplcvroerphpzojpqjsjlrmqjueykphydhbkszlxykmdvfyyjgwsf...

output:

7863

result:

ok single line: '7863'

Subtask #3:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 0ms
memory: 23880kb

input:

200 186
bmtexhhnkxtturdmbdwlnojqbrgmfsldftmxfuhwcsfvhqrwtyxahyaeqhdmptdzatiusqlzplnpwwpjtqruzwzfxrkmolppethnfcjahkggzrahuhjxtzzxftapeckzluzbawtqebmkuqvowxjjejyhlwviatpwsgrjlskzdemcjaikeqodtkzjfpuxjvajbecvzbfr
iuaztcsejcanhhcxbceaivostovczsbsrqongikbzzrgrmubfqexqczjgzhdonhidpecjyugbbgsalfmosipjpumrgk...

output:

2783

result:

ok single line: '2783'

Test #8:

score: 10
Accepted
time: 0ms
memory: 24116kb

input:

200 91
babbaabaaabaabbababaaaaabababbaabbabababbabbabbaabbabbbabbaaabbbbbaaaabbbbbabbbbbbabaabbabbbbbbbabbabababbbbbbbaabbbbbabbaababbbaaababaaababbabbaaabbbbbaaaaaabababaaababbbababababbbabbbababbbababaabaa
aabaabbaaaabbaaabbbbbbbbaabbbaaabbaabbabbababbabbbbbbbababbbabbababbbaaaababbbbbbbbbabaaabab...

output:

9267

result:

ok single line: '9267'

Test #9:

score: 10
Accepted
time: 0ms
memory: 22784kb

input:

200 150
nbosezhgtlbulcqhzxmsekhmlwjxdnykhhrppccxytopamjpnmmlwjnvzxmlmzbgonxrfjnbehezhgtlbulgvjewofqnuurfjngckhhreqocuonxrlpthohchzzuatphchzwumrbokiqfbsbehnxsekhcbyoighozeesdxrbgonxrthozeebclvtpptlyjfgicbgbiko
fvzctlpthoqfbssekhcbyoikzeexsezhgtlbulchhrebswwfgjjqxdnmtpotlpwcxytopauafopamjpnmzxmlmzbgon...

output:

7551

result:

ok single line: '7551'

Subtask #4:

score: 10
Accepted

Test #10:

score: 10
Accepted
time: 6ms
memory: 22304kb

input:

1970 76
dbajnykavlpizxpttpyxdtospawwemltpdearvnatpwekllfrwdelahxyilixhccmsukvusqodalaqqrxnyufonqzubxmddmryuysetyxlqrrepcajjhtoriwliaubkocbkyfwvdsuchvtxnhytznlmkzggxmolwkrwqjyhvnipugloyrpnplaokjtlwijwbdzttpeqjqdfqgtnlmkzggxmolwkccgorxwpipugloyrpnplaoubxmdoslibzcwbgqygqjmhpfbiggjanvjamjbwkcpzoucifnkjo...

output:

99038

result:

ok single line: '99038'

Test #11:

score: 10
Accepted
time: 6ms
memory: 23120kb

input:

2000 1800
vagekztgqyfqacujtmjjdggeisvtokooiolvurvumezuhipwklzgpivjrtfscnnsmbaumbnvwfrafjhrsotdfuhkafprhzrtjhjqmgduylebgxjqgmwtqocgthlxcjbxjhhpwaagzdpwmvagekztgqyfqacujtmjjdggeisvtokooiolvurvumezuhipwklzgpivjrtfscnnsmbaubvnmmftofygcvjsnotectmvyyagrpdgtcnwduojcrzwdsvqutkizcedhuqupwlrnlerheesueheorqfrf...

output:

359745

result:

ok single line: '359745'

Subtask #5:

score: 10
Accepted

Test #12:

score: 10
Accepted
time: 0ms
memory: 23020kb

input:

2000 110
cctdrvumnyzeieuzynrhpgdjhtblkwegiqspeqdvlfquembvbgkbxbxqxkzcrejmjybxpaajjbahvnllhsnwqhwbodppwugaglhiccqgwfrqwrrtzvarjphzdvpanlilvvubyzfpinkncmusfpeythsyaqehcpsqeoarrjesmszoxjdwokscxiopdvlrrcatthspslqeteanbgvonavsekcjlxzqkdknewqwkzlrkogaqarlookpwmdbglitjpljgkskomjlpjaxnqneorxlvaacsepppualnwg...

output:

204737

result:

ok single line: '204737'

Test #13:

score: 10
Accepted
time: 0ms
memory: 22660kb

input:

2000 1568
bbaaabbbbbabbbbbbbbabaabbbbaaabbbaaaabbbabbbbbbaabababbaabbabaabbabbabbbbbbbbbaabbaaaaaaaaaaaaababbabbbbababaaaaaaaabbababaaababaaaaaaabbbbaaaababbabbaaabaaaaabbbaabbbbabbabbbaabbbbabbababbababaaabbbaaaabbaaabbabbaaaabbbbabbbbaaabbbababbbaaabbaabaaaaabbaabbabbabaaabbaaaaabbbabaaaaababaabbb...

output:

675034

result:

ok single line: '675034'

Test #14:

score: 10
Accepted
time: 0ms
memory: 21260kb

input:

2000 1344
lolkxicffjoahkfdggddidecuqrfpfooutddnzbcazpcocgubmrigntptbyvztzqgicupxqkjakctdgmbqtfljxesdkumgzypjteiomnavydabegdsueyupxucuopzhucgrbipveldsgvdzxbtskfoficlremrcxzgnhkumgkqhkgrvdabegdsueyutemrcxzgnhkbkqhylgoldsvtgbljrmcbicgqshbetgofdjcxzlysumcfxpcovccfclgjltgmjvwlgghxzvwlgghxzhanmfwhlhxsvrno...

output:

880113

result:

ok single line: '880113'

Subtask #6:

score: 10
Accepted

Test #15:

score: 10
Accepted
time: 23ms
memory: 24672kb

input:

136531 132287
dqkgbnnyzwmbzckupyuuupmenzjfpooutxplglbcqcyeyniuzhgecanatlvlfowlzqjrztednqbhopdrxaaephxnbfaqqfoqovicxazopnkttwzqvlyqrgistvpetfmhhughbqrncmrdbgmyfmivuxbwtuqbrqazuyygcxxgcragzwwxoxqyvpzugywirksslmhsspzountdivthtkvvdqhuoncsdrcewhqkptcwfuysrhqkgrivpckevgbejvwryjtsglmditbbjtxqubwruuqngjugbu...

output:

561550095

result:

ok single line: '561550095'

Test #16:

score: 10
Accepted
time: 23ms
memory: 25080kb

input:

150000 121497
zngvmoixlvkgnadwokornampshpamkzttdsrlrdpljvnyhtumgbjrszxmlbjvuqqilfbwzozrbrofqdiwivrtylbupfvinlggpqojtpqnyjmyisydgzwcpicsacutzkpcttcktknqmvhjvvwkomytrhajtifdqldcfnhhwaavxfqtazukudojiyhxpxqoasmlvfbgavfdamyvdapmlxjvxrzvldbthtagauvczpuofglawxdlhvfughisxfxhskuuybyipbwxauxuytsagjronxoimcbzd...

output:

3463078308

result:

ok single line: '3463078308'

Subtask #7:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 11ms
memory: 24328kb

input:

93376 10006
qvajyijbvmbtcgejthwkwatplbtmscyqqlbjmooteoyzbushasbdruqbwsvdjwzwnfzkawoaqwwibibmsnmnbinktjybibswordjyxipmonbqujxmexlgnchbiqsalrrlnupdhaxvaehcnbjsmcypcakmmengrpogkisfrqghzuakdwdyipuioibvatllelgtqaeqnnmcqcooftbyvjbrfyczwmbiuccckfgdjkdhfdnygsmpspulqwlaorrepzauxbmwpyfqzkkgjyenyfqpulqkhbuegic...

output:

833972344

result:

ok single line: '833972344'

Test #18:

score: 10
Accepted
time: 52ms
memory: 24908kb

input:

100000 3453
klyarstaybbaawhfordfxixwdlbxplhsequnbxtfmeanqfqimnkbcyqqyedrdtpstcddekspidolwgrqelojswgdfnaepcurhsyhvtdwfgufebqjrcyizbinzlntltteasxpwybvkiowzrdfwqybqglvtakkkejwiuvgypdtjycxiqrjfpwitfkrqkifjmxwzfpqgvvhdjfcfufqzxsnslakggtbtbzgrakleovglwbwhayczuygizjvsncrchniozxywswpchtohckqulsvytglehfhgtmk...

output:

246347135

result:

ok single line: '246347135'

Subtask #8:

score: 10
Accepted

Test #19:

score: 10
Accepted
time: 44ms
memory: 24892kb

input:

90081 61832
lqqwzyiwccivztgzvdcjowmgtohjstttigxkkciexmyicxputfgudxdwemcpnnforfltonoeevwxptmbzvelckmgmboebsmfqgvxwhgdlwezreycawmjgnlinxzjsbaqjafsrwhngmorjjubzbwynwgblayrduekrmrenvcuqdmnebsjqvhgcugnwppxtbuuekizxwcpvsusxmzmhzdsmlurhzugnitxtplmsefrsihjdvroaihlluqtttthcyyuekitefhcjcrwrcricypqhehanczcqarp...

output:

1742191016

result:

ok single line: '1742191016'

Test #20:

score: 10
Accepted
time: 53ms
memory: 24172kb

input:

100000 18330
aabbbaaaabbaabbaababababaaabbabaabbaaaabaabbbbbbababbbababaabaabbbaabbbbbbaaabbabbabbabbbbbaaabaaabbbbbabbabbabbabbaaabbaaababbaaabbaaabababbaabaabbbabaababbaabaabbbbabbabaaaabbbabbbaabbbbbaaaaabbaabbbaaaaabbaaaaaabaaabbbbabbaabbaabaaaababaaaabbbabbbaaabbbabaaaabaaababbbabaabaabaabbabbb...

output:

1438031519

result:

ok single line: '1438031519'

Subtask #9:

score: 10
Accepted

Test #21:

score: 10
Accepted
time: 25ms
memory: 25120kb

input:

148067 68475
ndqltwlfnbfgjjrxfzwzlxjwuytfnmgkoozbgxmjhagcxowjeowjshohauryuvbhyijzktzzjnffhccmufbutucqpymbncwdopfziqpdcxqnkgwqekmyfxfftyzmwuyutgddadhmtteqefmbwpuauvsffbcqjhjwukvpleaykjajfdxhcspygwkikuwmtnjhjgxoaktshigoysxhrjjlptordbzoumukatnlzygzcykbnxgvlevngkwygjqrpyaodfutjhyyfygjccqkyjnzebcujwvvokd...

output:

5449905181

result:

ok single line: '5449905181'

Test #22:

score: 10
Accepted
time: 100ms
memory: 25552kb

input:

150000 125148
ccpbdfncvudrbqqhkphhmpqgzdnpfztoddoznzptiocplmqasljuuplejyjyczoencfvaxxkwwdradqpgrxhcenakmttyisfuzksmtuhfryqrzqjbmfgoiaxnpgvkiaidndioksdtfhojgfxxnceywvkkbtdresxebwpiqqxqcwgemgjblwugmolkozcqvueobmapsrdxwllpesqiberzefaktdnxxydxorremnsjsesvvgnwugwmzkgdeathtnvqxqzkzmhnihtopfmbvaaeunnzzuiix...

output:

3100212388

result:

ok single line: '3100212388'

Subtask #10:

score: 10
Accepted

Test #23:

score: 10
Accepted
time: 100ms
memory: 25296kb

input:

142928 139024
jdgusjdfvxvfdtvgwwumkrnhgpckfgeoagwnspjyiexkkgudqtkxbeprmpvzfsdtoexmccgqmgewithttrtoceddynvnvhurikgwhvdibmyaokzysmyrjxbwymdyskhsdhnhhbhoeyzsepiyvebfyojfxzlhrxozvsvzdmlggrtbyemqcxixqnmzscepaoogdxfdrvbwxxscokuucdycppvssnckvazqoutebossriaxuhnesksxzycabccoafbluystrytufwxhhdrcfumanheulnbgph...

output:

542881204

result:

ok single line: '542881204'

Test #24:

score: 10
Accepted
time: 101ms
memory: 25692kb

input:

150000 101453
bbbaaabbbabbbaababaabaaaababbbbbaabaaabbababbababbaaaababbbbbaababbbabbbabaaaabaabaaaabbbbabbababbabbbaababbababaabbaababbbbbbaaaaaaabbbbaaabbababbbbbbbbbbbbabbbaaaaabaaaaabbaaabaabbbbbaabbbaabbabbaaaababaabbbaaaabbbaababaabbbaaaabaabbbabbabbaaababababbaaabaabbbabbbbbababbbbbbbbbbbaabb...

output:

4870040636

result:

ok single line: '4870040636'