QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#839277 | #9952. JUMPin' JUMP UP!!! | N_z_ | WA | 410ms | 16044kb | C++23 | 2.0kb | 2025-01-01 16:14:12 | 2025-01-01 16:14:12 |
Judging History
answer
//just test
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
char s[N],t[N];
const int mod1=1e9+7;
const int mod2=1e9+9;
const int base=131;
map<ll,int> m1;
int n,m,q;
int nxt[N];
ll p1[N],p2[N];
struct node{
ll l,r;
}h[N];
int pos[N];
void Hash(){
p1[0]=1,p2[0]=1;
for(int i=1;i<=n;i++){
p1[i]=p1[i-1]*base%mod1;
p2[i]=p2[i-1]*base%mod2;
h[i].l=(h[i-1].l*base%mod1+(s[i]-'0'))%mod1;
h[i].r=(h[i-1].r*base%mod2+(s[i]-'0'))%mod2;
}
}
ll get(int l,int r){
ll h1=(h[r].l-(h[l-1].l*p1[r-l+1]%mod1)+mod1)%mod1;
ll h2=(h[r].r-(h[l-1].r*p2[r-l+1]%mod2)+mod2)%mod2;
return h1+h2;
}
int main(){
int T;
cin>>T;
while(T--){
int i;
scanf("%d%d%d",&n,&m,&q);
scanf("%s",s+1);
scanf("%s",t+1);
m1.clear();
nxt[0]=-1;
int cnt=0;
for(int i=1;i<=m;i++){
int p=nxt[i-1];
while(p>=0&&t[p+1]!=t[i]) p=nxt[p];
nxt[i]=p+1;
}
int len=m-nxt[m];
if(nxt[m]*2<m) len=m;
Hash();
node x={0,0};
for(i=1;i<=m;i++){
ll h1=(x.l*base%mod1+(t[i]-'0')+mod1)%mod1;
ll h2=(x.r*base%mod2+(t[i]-'0')+mod2)%mod2;
x={h1,h2};
}
for(i=1;i<=m;i++){
ll h1=(x.l*base%mod1+(t[i]-'0')-(ll)(t[i]-'0')*p1[m]%mod1+mod1)%mod1;
ll h2=(x.r*base%mod2+(t[i]-'0')-(ll)(t[i]-'0')*p2[m]%mod2+mod2)%mod2;
x={h1,h2};
if(!m1[h1+h2]){
m1[h1+h2]=++cnt;
pos[cnt]=i;
}
}
while(q--){
ll x,y;
scanf("%lld%lld",&x,&y);
auto tmp=get(x,x+m-1);
if(!m1[tmp]){
printf("0\n");
}
else{
int d=m1[tmp];
printf("%lld\n",(ll)(y-pos[d])/len+1);
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7820kb
input:
1 4 2 3 abcd ba 1 2 2 2 3 2
output:
1 0 0
result:
ok 3 tokens
Test #2:
score: -100
Wrong Answer
time: 410ms
memory: 16044kb
input:
1126 100 19 100 bzbzbzbzbzbzbzbyydzbzbzbzbzbzbzbzbyydzbzbzbzbzbzbzbzbyydzbzbzbzbzbzbzbzbyydzbzbzbzbzbzbzbzbyydzbzbzb bzbzbzbzbzbzbzbyydz 56 76480443552173389 38 692816130192550219 33 703112329902236202 74 338839552028748732 5 231782307290688600 11 676202903706926230 23 327149191556259670 46 89836370...
output:
4025286502745967 36464006852239485 37005912100117695 17833660633092038 12199068804773085 35589626510890854 17218378502961036 47282300283677508 49424514696701914 718335379405514 21864557806215529 34660711060158649 10954133132284723 4309231433797528 51886468906311730 8242825662888107 52502379720138545...
result:
wrong answer 32201st words differ - expected: '25223307291231491', found: '107199055987733837'