本地过,洛谷RE??
查看原帖
本地过,洛谷RE??
223392
Belarus楼主2020/12/2 15:02

rt,不知道为什么:

#include<bits/stdc++.h>
using namespace std;
const int sze=5e5+9;
int n,m,tot=1;
int trie[sze][28];
set<int> _end[sze];
inline void insert(char* str,int id){
	int p=1,len=strlen(str);
	for(int k=0;k<len;++k){
		int ch=str[k]-'a';
		if(!trie[p][ch]) trie[p][ch]=++tot;
		p=trie[p][ch];
	}
	_end[p].insert(id);
}
inline void find(char* str){
	int p=1,len=strlen(str);
	for(int k=0;k<len;++k){
		int ch=str[k]-'a';
		p=trie[p][ch];
		if(!p) return;
	}
	
	for(set<int>::iterator it=_end[p].begin();it!=_end[p].end();++it) cout<<(*it)<<' ';
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		int l;
		cin>>l;
		for(int j=1;j<=l;++j){
			char tmp[30];
			cin>>tmp;
			insert(tmp,i);
		}
	}
	cin>>m;
	while(m--){
		char tmp[30];
		cin>>tmp;
		find(tmp);
		cout<<'\n';
	}
	return 0;
}
2020/12/2 15:02
加载中...