QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#260267#7748. Karshilov's Matching Problem IIucup-team1525WA 57ms11280kbC++171.5kb2023-11-21 23:14:062023-11-21 23:14:07

Judging History

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

  • [2024-08-25 20:42:18]
  • hack成功,自动添加数据
  • (/hack/789)
  • [2023-11-21 23:14:07]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:11280kb
  • [2023-11-21 23:14:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1.5e5;
int n,m;
char s[N+5],t[N+5];
ll w[N+5];
int zs[N+5],zt[N+5];
ll sw[N+5],wt[N+5];
void prep(){
	sw[1]=w[1];
	for(int i=2,j=1,r=1;i<=n;i++){
		int &k=zs[i]=r>i?zs[i-j+1]:0;
		sw[i]=(r>i?sw[i-j+1]:0)+w[i]-w[i-1];
		while(i+k<=n&&s[i+k]==s[k+1]) k++;
		sw[i]+=w[(k>0)&&(r<=i)];
		if(i+k>r){
			j=i; r=i+k;
		}
	}
	for(int i=1;i<=n;i++) sw[i]+=sw[i-1];
	for(int i=1,j=0,r=0;i<=n;i++){
		int &k=zt[i]=r>i?zs[i-j+1]:0;
		while(i+k<=n&&t[i+k]==s[k+1]) k++;
		if(i+k>r){
			j=i; r=i+k;
		}
		wt[i]=w[k];
	}
	for(int i=1;i<=n;i++) wt[i]+=wt[i-1];
}
namespace Segtr{
	int tr[N*4+5];
	#define lc id<<1
	#define rc id<<1|1
	void build(int l,int r,int id){
		if(l==r){
			tr[id]=l+zt[l]-1;
			return;
		}
		int mid=l+r>>1;
		build(l,mid,lc);
		build(mid+1,r,rc);
		tr[id]=max(tr[lc],tr[rc]);
	}
	int query(int l,int r,int st,int en,int id){
		if(tr[id]<=en) return -1;
		if(l==r) return l;
		int mid=l+r>>1,ans=-1;
		if(st<=mid) ans=query(l,mid,st,en,lc);
		if(ans==-1&&en>mid) ans=query(mid+1,r,st,en,rc);
		return ans;
	}
}
using namespace Segtr;
int main(){
	scanf("%d %d",&n,&m);
	scanf("%s",s+1);
	scanf("%s",t+1);
	for(int i=1;i<=n;i++){
		scanf("%lld",&w[i]);
		w[i]+=w[i-1];
	}
	prep();
	build(1,n,1);
	while(m--){
		int l,r;
		scanf("%d %d",&l,&r);
		int p=query(1,n,l,r,1);
		if(p==-1) printf("%lld\n",wt[r]-wt[l-1]);
		else printf("%lld\n",wt[p-1]-wt[l-1]+sw[r-p+1]);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 10068kb

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: 1ms
memory: 8072kb

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: 57ms
memory: 11280kb

input:

150000 150000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

194786751068092
389626387603952
821430473284481
789203782193053
267099797055190
152448256344436
636389261223224
105566622014179
120822864648103
478164185216776
347026407258032
534645168660908
429180998763800
52792025687056
738846762284006
486364137173702
57809071595420
193177097329816
86688394022784...

result:

wrong answer 1st lines differ - expected: '108147037823514', found: '194786751068092'