QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#461186#7748. Karshilov's Matching Problem IIEther13WA 53ms20628kbC++141.8kb2024-07-02 16:50:012024-07-02 16:50:01

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2024-07-02 16:50:01]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:20628kb
  • [2024-07-02 16:50:01]
  • 提交

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'