QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276695#7814. 消消乐SoyTony100 ✓29ms31008kbC++141.5kb2023-12-06 09:35:432023-12-06 09:35:44

Judging History

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

  • [2023-12-06 09:35:44]
  • 评测
  • 测评结果:100
  • 用时:29ms
  • 内存:31008kb
  • [2023-12-06 09:35:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn=2e6+10;
const int base=13331;
const int mod1=1e9+3579;
const int mod2=998244353;
const int inv1=804968750;
const int inv2=814485322;

inline int read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}

int n;
char s[maxn];
ll ans;
struct HashTable{
    const static int MOD=5000011;
    int head[MOD],tot;
    int nxt[maxn],siz[maxn];
    ll val[maxn];
    inline void insert(ll k){
        int p=k%MOD;
        for(int i=head[p];i;i=nxt[i]){
            if(val[i]==k) return ++siz[i],void();
        }
        ++tot;
        nxt[tot]=head[p],val[tot]=k,siz[tot]=1;
        head[p]=tot;
    }
    inline void calc(){
        for(int i=1;i<=tot;++i){
            ans+=1ll*siz[i]*(siz[i]-1)/2;
        }
    }
}mp;

int st[maxn],top;
int h1,h2;

int main(){
    n=read();
    scanf("%s",s+1);
    mp.insert(0);
    for(int i=1;i<=n;++i){
        if(top&&s[st[top]]==s[i]){
            h1=1ll*(h1-s[st[top]]+mod1)*inv1%mod1;
            h2=1ll*(h2-s[st[top]]+mod2)*inv2%mod2;
            --top;
        }
        else{
            st[++top]=i;
            h1=(1ll*h1*base+s[i])%mod1;
            h2=(1ll*h2*base+s[i])%mod2;
        }
        mp.insert(1ll*h1*mod2+h2);
    }
    mp.calc();
    printf("%lld\n",ans);
    return 0;
}

详细

Test #1:

score: 5
Accepted
time: 2ms
memory: 5696kb

input:

10
aaaaaaaaaa

output:

25

result:

ok single line: '25'

Test #2:

score: 5
Accepted
time: 1ms
memory: 7932kb

input:

10
ooooppuuhh

output:

16

result:

ok single line: '16'

Test #3:

score: 5
Accepted
time: 1ms
memory: 5708kb

input:

10
nnppkkppjj

output:

16

result:

ok single line: '16'

Test #4:

score: 5
Accepted
time: 0ms
memory: 7760kb

input:

10
vvcckkhhqq

output:

15

result:

ok single line: '15'

Test #5:

score: 5
Accepted
time: 0ms
memory: 5792kb

input:

10
llmmxxoopp

output:

15

result:

ok single line: '15'

Test #6:

score: 5
Accepted
time: 2ms
memory: 6812kb

input:

800
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjddzziiyyyyjjooppiivvppmmooppttnnbbmmaaqqvvkkllyyvvmmjjsswwxxccwweeeekkhhaakkvvffaaiieessmmiibbff...

output:

38306

result:

ok single line: '38306'

Test #7:

score: 5
Accepted
time: 0ms
memory: 6752kb

input:

800
pffpgppguqqugllgwhhwxjjxpkkpxnnxlkklunnuxiixallayqqyccccjnnjnyynqccqqjjqtuutboobwddwfwwfgvvgwuuwpqqppttpyggysrrsgwwgeddexbbxbssbvbbvbeebweewwkkwwddwnoontddtcddcajjapffptcctkeekboobfjjfvaavpjjpriirlfflnazdsevmozgezlngnhktrllcgorjoollwtqylmmzxfeibnifcebsnnugzluzlizievzxfnlokzodymigextlmyltzbmptyjf...

output:

27479

result:

ok single line: '27479'

Test #8:

score: 5
Accepted
time: 0ms
memory: 13272kb

input:

8000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

3820477

result:

ok single line: '3820477'

Test #9:

score: 5
Accepted
time: 0ms
memory: 15096kb

input:

8000
neenbnnbvjjvddddommolrrlzttzqwwqlfflijjiaqqayaayihhiqmmqduudlzzlyzzyannatyytfiifbqqbroorcffcgjjgwhhwoqqopuupdjjdeqqewnnwvwwvpiiprqqrukkuhbbhsiisrqqrxvvxfmmfzkkzjlljimmiazzariirdvvdcuucpaapbaabbaabccccxqqxivvipttpqffqmggmzhhzdaadyxxyhccheddeaiianggnxjjxqssqfaafqllqskksfuufviivozzocwwcznnzfxxfnss...

output:

2713693

result:

ok single line: '2713693'

Test #10:

score: 5
Accepted
time: 0ms
memory: 13224kb

input:

8000
ivviurrukrrkaccafoofaxxaleelcyycsiisimmifvvfoeeodppdneenqjjqsccsguugonnoyiiymttmcjjcmkkmjwwjieeikeekdbbdolloyvvyolloxiixmaamfnnfzrrzqbbqweewvttvboobbeebcmmcsqqsiyyifddfyvvyvttvvddvejjeeeeeleellzzlzbbzcrrcobbowsswquuqozzoyqqyulluwvvwyxxyxllxwrrwgmmgeppecvvcsiisyvvyukkuyppyryyrhjjhthhtvssvvnnvnee...

output:

2721590

result:

ok single line: '2721590'

Test #11:

score: 5
Accepted
time: 0ms
memory: 29880kb

input:

200000
tdaatgfvypbdkxdlvttiuksoooxszoqnqvmtznizlqfstlenqrnmdpkmvhmzftporwzvlbpyplrvrkgrpvqxyjcwwpcinilarbaudodadcglszflkzvmmdahgqphqoueltddqlymwpvweslymviccsmhuezesmlwsswgznaofullpxciuezrbkxfnodiglhpyrfcjajyuqzfoxsysgeqrqmvtqysypgaivfetwhmgxngzdvavbkipanoopqftdmntwpxgaljiqrkppywfuspzfgljheckapftjqar...

output:

8356

result:

ok single line: '8356'

Test #12:

score: 5
Accepted
time: 11ms
memory: 31008kb

input:

200000
nleqrvpkpopfbstnolidsxrfhivbwbbqbwxmvymzmnwozrbklbuwliccquzhpfjsbxlnkzewvjpjarqmwcpsvovxeynjrgdjxrauincbnjvokawliinjqqulwxxeztpbrotihuiyjjqsxxosragocxbpjmhquczgwfakfaojxslteazikjqkebpcrrggswjiyetkpyvjubhtoounhveftykvetuwqgpddicnarbsigpjytmhcymvapbmkforkaeccsuhmwiuljmvajlztzjghnohlmxnmdehfxnra...

output:

8340

result:

ok single line: '8340'

Test #13:

score: 5
Accepted
time: 0ms
memory: 8404kb

input:

200000
abbabbbbbbaababaaabaaaababaaaaaabbababababbabbaaababbbbaabaabbbbbbababaabababbababaabbaabaaaabbbbbaabbbbaababbbabaaababbbbbbbbbbabbbabaabaabaababbbbbbabaabbbbbbbbbbaaabbbbabaabbaababaaabbabbaaabbbbbaaabababaababbaaabbbbababbbbbbaaaabaaaaaaabbbaabbaaaabbabbbbbaabbbbbbbabbaaaabaaabaabbaaaababbb...

output:

52315097

result:

ok single line: '52315097'

Test #14:

score: 5
Accepted
time: 4ms
memory: 9396kb

input:

200000
aaaababaaaaabbabababbbbabbbbababbabbaabaaabbabbaabaaaaaabaaaabbbbbbbabaabbabaabababbbaabbbbabbbbbaabaaaabaaaababaaaabbaaaaabbbabbbabbbbbbbaabbbabbaaabbbabaabaaaaaaaaababbaaabbbbaabaabbaaababbabbaabbbbaaababbbbbbbbbbbaabaaabbaaabaabbaaabbabaabbabbaabbbababbaaabaaaaaabbbbbbbabaabbabbaabaabaabaa...

output:

72221142

result:

ok single line: '72221142'

Test #15:

score: 5
Accepted
time: 0ms
memory: 25580kb

input:

200000
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy...

output:

2395581278

result:

ok single line: '2395581278'

Test #16:

score: 5
Accepted
time: 0ms
memory: 27388kb

input:

200000
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

2396621459

result:

ok single line: '2396621459'

Test #17:

score: 5
Accepted
time: 0ms
memory: 25548kb

input:

200000
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo...

output:

2395864064

result:

ok single line: '2395864064'

Test #18:

score: 5
Accepted
time: 22ms
memory: 30460kb

input:

2000000
iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii...

output:

239586659381

result:

ok single line: '239586659381'

Test #19:

score: 5
Accepted
time: 22ms
memory: 29200kb

input:

2000000
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

239687303822

result:

ok single line: '239687303822'

Test #20:

score: 5
Accepted
time: 29ms
memory: 30500kb

input:

2000000
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

239608981171

result:

ok single line: '239608981171'