社区讨论

样例过但是 RE 求调

P3879[TJOI2010] 阅读理解参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mk5h6g5q
此快照首次捕获于
2026/01/08 21:20
上个月
此快照最后确认于
2026/01/11 11:25
上个月
查看原帖
CPP

#include<iostream>
#include<vector>
using namespace std;
const int N=50001,S=28;
int n,l,m,tot,trie[N][S];
vector<int>cnt[N];
string str;
int get(char x)
{
  return x-'a'+1;
}
void insert(string str,int idx)
{
  int now=0;
  for(char x:str)
  {
    if(!trie[now][get(x)])trie[now][get(x)]=++tot;
    now=trie[now][get(x)];
  }
  cnt[now].push_back(idx);
  return;
}
void query(string str)
{
  int now=0;
  for(char x:str)
  {
    if(!trie[now][get(x)])
    {
      cout<<'\n';
      break;
    }
    now=trie[now][get(x)];
  }
  for(int x:cnt[now])cout<<x<<' ';
  cout<<'\n';
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin>>n;
  for(int i=1; i<=n; ++i)
  {
    cin>>l;
    for(int j=1; j<=l; ++j)
    {
      cin>>str;
      insert(str,i);
    }
  }
  cin>>m;
  for(int i=1; i<=m; ++i)
  {
    cin>>str;
    query(str);
  }
  return 0;
}

回复

4 条回复,欢迎继续交流。

正在加载回复...