QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#461186 | #7748. Karshilov's Matching Problem II | Ether13 | WA | 53ms | 20628kb | C++14 | 1.8kb | 2024-07-02 16:50:01 | 2024-07-02 16:50:01 |
Judging History
answer
#include<bits/stdc++.h>
#define il inline
#define ll long long
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Per(i,a,b) for(int i=(a);i>(b);i--)
#define tep(i,u) for(int i=head[u];i;i=e[i].nex)
#define pb push_back
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define mp make_pair
using namespace std;
il int read(){
int x=0,f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
return x*f;
}
const int N=150010;
char s[N<<1],t[N];
int w[N],n,m,z[N<<1],s1[N],s2[N],nex[N],st[N][22];
void z_function(){
int l=0,r=0;
rep(i,2,n*2+1){
if(i<=r) z[i]=min(r-i+1,z[i-l+1]);
while(z[i]<n&&s[z[i]+1]==s[i+z[i]]) z[i]++;
if(i+z[i]-1>r) l=i,r=i+z[i]-1;
}
}
void kmp(){
s1[1]=w[1];
int j=0;
rep(i,2,n){
while(j&&s[j+1]!=s[i]) j=nex[j];
if(s[j+1]==s[i]) j++;
nex[i]=j;
s1[i]=s1[nex[i]]+w[i];
}
}
int getst(int l,int r){
int x=__lg(r-l+1);
return max(st[l][x],st[r-(1<<x)+1][x]);
}
int main(){
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout);
n=read(),m=read();
scanf("%s%s",s+1,t+1);s[n+1]='#';
rep(i,1,n) w[i]=read(),s[i+n+1]=t[i];
z_function();kmp();
rep(i,1,n) s1[i]+=s1[i-1],w[i]+=w[i-1];
rep(i,1,n) s2[i]=s2[i-1]+w[z[n+1+i]];
rep(i,1,n) st[i][0]=i+z[n+1+i]-1;
rep(i,1,20) rep(j,1,n-(1<<i)+1)
st[j][i]=max(st[j][i-1],st[j+(1<<(i-1))][i-1]);
rep(i,1,m){
int l=read(),r=read();
int le=l,ri=r,p=r+1;
while(le<=ri){
int mid=(le+ri)/2;
if(getst(l,mid)>r) ri=mid-1,p=mid;
else le=mid+1;
}
printf("%d\n",s2[p-1]-s2[l-1]+s1[r-p+1]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3896kb
input:
8 5 abbabaab aababbab 1 2 4 8 16 32 64 128 1 1 2 3 3 5 4 7 1 8
output:
1 3 3 16 38
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 7980kb
input:
15 4 heheheheehhejie heheheheheheheh 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 2 3 4 8 2 6 1 15
output:
3 13 13 174
result:
ok 4 lines
Test #3:
score: -100
Wrong Answer
time: 53ms
memory: 20628kb
input:
150000 150000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
-238689766 574735614 259907610 510975269 -494263619 -119776439 -1202625941 712131205 -233956491 295786658 854069821 -1389700931 -1959196086 -1471492067 1796429659 227026746 -1291964243 -833662909 -28332933 1521598991 -210103850 888469404 604921440 813327493 -853316457 1964711175 -669853735 -13877485...
result:
wrong answer 1st lines differ - expected: '108147037823514', found: '-238689766'