关于LSOT Round 1 D
  • 板块灌水区
  • 楼主dk_qwq
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/7/25 19:08
  • 上次更新2023/10/27 18:27:25
查看原帖
关于LSOT Round 1 D
311306
dk_qwq楼主2022/7/25 19:08

测评记录

提供一种做法,感觉能卡到O(n2)O(n^2)(?我乱说的),是不是数据太水的原因

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
const int N=5e5+5;
struct node{
	int last;
	string s;
}f[N];
int check(int st,string str){
	int now=st,ans=0;
	while(now!=-1){
		int s=str.find(f[now].s,0);
		while(f[now].s!=""&&s!=string::npos){
			s=str.find(f[now].s,s+1);
			ans++;
		}
		now=f[now].last;
	}
	return ans;
}
int q;
int main()
{
	scanf("%d",&q);
	f[0].last=-1;
	for(int i=1;i<=q;i++){
		int op,hoc;
		string str;
		scanf("%d%d",&op,&hoc);
		cin>>str;
		if(op==1){
			f[i].last=hoc;
			f[i].s=str;
		}
		if(op==2){
			f[i].last=hoc;
			printf("%d\n",check(i,str));
		}
	}
}
2022/7/25 19:08
加载中...