社区讨论
本地过,洛谷RE??
P3879[TJOI2010] 阅读理解参与者 3已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @locvdx19
- 此快照首次捕获于
- 2023/10/30 20:22 2 年前
- 此快照最后确认于
- 2023/11/05 06:53 2 年前
rt,不知道为什么:
CPP#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;
}
回复
共 7 条回复,欢迎继续交流。
正在加载回复...