QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#484417 | #2018. 字符串匹配 | winner_yc | 100 ✓ | 127ms | 13516kb | C++14 | 1.7kb | 2024-07-19 18:33:13 | 2024-07-19 18:33:13 |
Judging History
answer
#include<bits/stdc++.h>
#define int ll
#define up(i,l,r) for(int i=l,END##i=r;i<=END##i;i++)
#define dn(i,l,r) for(int i=l,END##i=r;i>=END##i;i--)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int INF=0x3f3f3f3f,N=1<<20;
ll n,all,lst,now,tot[30],cnt[30],z[N];
string s;
struct node {
int c[30|1];
void add(int x,int y) {
while(x<=26) c[x]+=y,x|=x+1;
}
int sum(int x) {
ll ans=0;
while(x>=0) ans+=c[x],x&=x+1,x--;
return ans;
}
} T;
namespace sol {
ll read() {
ll f=0,x=0;
char c=getchar();
while(c<'0'||c>'9') f|=c=='-',c=getchar();
while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f?-x:x;
}
void write(ll x) {
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
void get(string s) {
ll l=0;
up(i,0,n-1) z[i]=0;
up(i,0,(ll)s.length()-1) {
if(!i) continue;
if(l+z[l]>i) z[i]=min(z[i-l],l+z[l]-i);
while(i+z[i]<n&&s[z[i]]==s[i+z[i]]) z[i]++;
if(i+z[i]>l+z[l]) l=i;
}
}
void fnnqaq() {
cin>>s;
n=s.length();
get(s);
up(i,0,n-1) if(i+z[i]==n) z[i]--;
ll ans=all=lst=now=0;
up(i,0,25) tot[i]=cnt[i]=T.c[i]=0;
up(i,0,n-1) tot[s[i]-'a']++;
up(i,0,25) all+=(tot[i]&1);
lst=all;
up(i,0,n-1) {
tot[s[i]-'a']&1?lst--:lst++;
cnt[s[i]-'a']&1?now--:now++;
tot[s[i]-'a']--,cnt[s[i]-'a']++;
if(i&&i<n-1) {
ll fnn=z[i+1]/(i+1)+1;
ans+=(fnn>>1)*T.sum(all)+(fnn-(fnn>>1))*T.sum(lst);
}
// cout<<"now="<<now<<" last="<<lst<<" all="<<all<<'\n';
T.add(now,1);
}
write(ans);
}
}
using namespace sol;
signed main() {
ll t=read();
while(t--)
fnnqaq(),puts("");
return 0;
}
詳細信息
Test #1:
score: 4
Accepted
time: 0ms
memory: 3604kb
input:
5 jjjjjjjjjj lllllllcyg mgmgmgmgmg nycqtnycqt tdutduwyga
output:
30 39 30 20 33
result:
ok 5 tokens
Test #2:
score: 4
Accepted
time: 0ms
memory: 3680kb
input:
5 hhhhhhhhhh iiiiiiibkw dgdgdgdgdg ffffffffyf ffzffzwsnw
output:
30 39 30 44 36
result:
ok 5 tokens
Test #3:
score: 4
Accepted
time: 0ms
memory: 3584kb
input:
5 rrrrrrrrrr iiiiiiiwzr dididididi wwwwzqcjvv mbymbyhgpc
output:
30 39 30 28 33
result:
ok 5 tokens
Test #4:
score: 4
Accepted
time: 0ms
memory: 3604kb
input:
5 cccccccccc lllllllket tututututu ccbuxccbux pnppnpnlwl
output:
30 39 30 26 32
result:
ok 5 tokens
Test #5:
score: 4
Accepted
time: 0ms
memory: 3668kb
input:
5 uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuubgmwdgmgwvqvkbcvihsk qdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaaqdaa csqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxfuuojcsqblzrdlnifzdoijirxf...
output:
6590 3585 2313 4359 4486
result:
ok 5 tokens
Test #6:
score: 4
Accepted
time: 0ms
memory: 3660kb
input:
5 llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllsuqtxhunfvotmxfqebwj rpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpiarpia yyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaztszfyyexplkvmxjuqzgrsmdaz...
output:
6564 3560 2607 4517 4554
result:
ok 5 tokens
Test #7:
score: 4
Accepted
time: 0ms
memory: 3648kb
input:
5 nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnkvpnzxdkdhjucliujhhl quegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegquegqueg aicsiooegbozaohagssdehvjzaicsiooegbozaohagssdehvjzaicsiooegbozaohagssdehvjzaicsiooegbozaohagssde...
output:
6517 3560 2888 4965 4105
result:
ok 5 tokens
Test #8:
score: 4
Accepted
time: 0ms
memory: 3732kb
input:
5 ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppphytnmeyelaxegcuzqkv joksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoksjoks yqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqptuhwyqmqquzipayftwvwjnbqp...
output:
6604 3560 2738 4804 4832
result:
ok 5 tokens
Test #9:
score: 4
Accepted
time: 0ms
memory: 3672kb
input:
5 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
690923 325466 274377 538726 519032
result:
ok 5 tokens
Test #10:
score: 4
Accepted
time: 0ms
memory: 3656kb
input:
5 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
688611 325466 278014 483768 516890
result:
ok 5 tokens
Test #11:
score: 4
Accepted
time: 0ms
memory: 3640kb
input:
5 rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...
output:
690572 325466 282653 400319 517082
result:
ok 5 tokens
Test #12:
score: 4
Accepted
time: 0ms
memory: 3752kb
input:
5 jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
output:
689440 325466 278624 464740 501911
result:
ok 5 tokens
Test #13:
score: 4
Accepted
time: 4ms
memory: 4000kb
input:
5 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...
output:
714173984 606072908 715934994 603558188 714547382
result:
ok 5 tokens
Test #14:
score: 4
Accepted
time: 4ms
memory: 6052kb
input:
5 vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...
output:
713410981 603184777 713761452 714012718 603184777
result:
ok 5 tokens
Test #15:
score: 4
Accepted
time: 8ms
memory: 4300kb
input:
5 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee...
output:
3502305645 3504362490 3495279874 3496151003 2412446034
result:
ok 5 tokens
Test #16:
score: 4
Accepted
time: 8ms
memory: 4296kb
input:
5 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
2419023179 3481792643 2416893029 3498851133 2414888013
result:
ok 5 tokens
Test #17:
score: 4
Accepted
time: 8ms
memory: 6408kb
input:
5 dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd...
output:
2414715183 2414053265 3498760311 2415418741 2412193453
result:
ok 5 tokens
Test #18:
score: 4
Accepted
time: 16ms
memory: 5864kb
input:
5 uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu...
output:
14044909130 13758605640 8021703699 4927122703 9489413350
result:
ok 5 tokens
Test #19:
score: 4
Accepted
time: 16ms
memory: 4744kb
input:
5 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
14044820948 13781146461 7453935828 4673360128 9488558416
result:
ok 5 tokens
Test #20:
score: 4
Accepted
time: 16ms
memory: 4816kb
input:
5 rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr...
output:
14044830602 13805450160 7984918891 4873659736 9491430029
result:
ok 5 tokens
Test #21:
score: 4
Accepted
time: 13ms
memory: 6360kb
input:
5 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
14044823925 13789617860 7597752918 4978465106 9490927685
result:
ok 5 tokens
Test #22:
score: 4
Accepted
time: 120ms
memory: 13484kb
input:
5 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
903628883069 902178522904 467114641327 305284235317 620652587747
result:
ok 5 tokens
Test #23:
score: 4
Accepted
time: 122ms
memory: 13516kb
input:
5 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...
output:
903629704237 901055755987 504315438243 304698187610 620653531389
result:
ok 5 tokens
Test #24:
score: 4
Accepted
time: 123ms
memory: 13460kb
input:
5 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc...
output:
904243010503 904253960505 904235088477 667900329073 904248230739
result:
ok 5 tokens
Test #25:
score: 4
Accepted
time: 127ms
memory: 13480kb
input:
5 hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh...
output:
904261912252 904260123920 904263261760 667900331468 904241569561
result:
ok 5 tokens
Extra Test:
score: 0
Extra Test Passed