当前位置:网站首页>Dictionary tree simple introductory question (actually blue question?)
Dictionary tree simple introductory question (actually blue question?)
2022-07-05 21:00:00 【Soup key TJ】
[TJOI2010] reading comprehension
Title Description
The English teacher left N N N A reading comprehension assignment , But every English essay has many new words to look up in the dictionary , To save time , Now let's do a statistic , Let's count some new words that have appeared in some essays .
Input format
The first line is an integer N N N , Indicates the number of short articles , Each essay contains only spaces and lowercase letters .
Pressed down N N N That's ok , Each line describes a short passage . The beginning of each line is an integer L L L , This passage is written by L L L One word makes up .
Next is L L L Word , Separate words with a space .
Then it is an integer M M M , It means to ask several times . In the back M M M That's ok , Each line represents a new word to be counted .
Output format
Output one line for each new word , Count the number of essays in which it has appeared , And output the serial number of the passage from small to large , The serial number should not be repeated , The serial numbers are separated by a space ( Note that there should be no spaces in front of the first sequence number and after the last sequence number ). If the word has never appeared , Then output a blank line .
Examples #1
The sample input #1
3
9 you are a good boy ha ha o yeah
13 o my god you like bleach naruto one piece and so do i
11 but i do not think you will get all the points
5
you
i
o
all
naruto
Sample output #1
1 2 3
2 3
1 2
3
2
Tips
about 30 % 30\% 30% The data of , 1 ≤ M ≤ 1 0 3 1\le M\le 10^3 1≤M≤103 .
about 100 % 100\% 100% The data of , 1 ≤ M ≤ 1 0 4 1\le M\le 10^4 1≤M≤104, 1 ≤ N ≤ 1 0 3 1\le N\le 10^3 1≤N≤103 .
The length of each essay ( Contain spaces between adjacent words ) ≤ 5 × 1 0 3 \le 5\times 10^3 ≤5×103 character , The length of each word ≤ 20 \le 20 ≤20 character .
Time limit of each test point 2 2 2 second .
All processes are in the notes
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
typedef long long ll;
int son[N][30],idx,n,l,m;
char a[N];
bitset<1010> sign[N];
// use bool Explosive space
// use bool One value accounts for 1 byte ,1 Bytes are 8 The bit
// use bitset Then each bool Value takes only one bit , Greatly save space
void insert(char str[],int k){
// Insert string , At the same time, tell me which line it is
int p=0; // Traverse the insert from the root node
int l=strlen(str);
for(int i=0;i<l;i++){
int u=str[i]-'a'; // Convenience as a subscript
if(!son[p][u]) son[p][u]=++idx;
// View the current node p Child nodes of u Whether the number has been given , If there is no mark, it will be numbered
p=son[p][u];// Move to the next node conversion position
}
sign[p][k]=1;// Mark that the string exists in k That's ok
}
void find(char str[]){
// Find the string
int p=0,signsign=1;// initialization , Go back to the root node and continue to check
int l=strlen(str);
for(int i=0;i<l;i++){
// Traverse the nodes to query
int u=str[i]-'a';
if(!son[p][u]){
// Once found unmarked , Then the string... Does not exist , Exit traversal query
signsign=0;// At the same time, the tag does not exist
break;
}
p=son[p][u];// Move to the next node conversion position
}
if(signsign){
// Judge whether the query is successful by marking
for(int i=1;i<=n;i++){
if(sign[p][i]){
// Check whether this string exists in this line through the tag
printf("%d ",i);
}
}printf("\n");
}
else{
puts("");
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>l;
for(int j=1;j<=l;j++){
scanf("%s",a);
insert(a,i);
}
}
cin>>m;
for(int i=1;i<=m;i++){
scanf("%s",a);
find(a);
}
return 0;
}
边栏推荐
- shell编程100例
- LeetCode: Distinct Subsequences [115]
- Deep merge object deep copy of vant source code parsing
- Enclosed please find. Net Maui's latest learning resources
- Sequence alignment
- ViewRootImpl和WindowManagerService笔记
- 树莓派4B上ncnn转换出来的模型调用时总是崩溃(Segment Fault)的原因
- 产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
- Monorepo管理方法论和依赖安全
- 从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题
猜你喜欢

培养机器人教育创造力的前沿科技

示波器探头对测量带宽的影响

从架构上详解技术(SLB,Redis,Mysql,Kafka,Clickhouse)的各类热点问题

如何让化工企业的ERP库存账目更准确

The transformation based on vertx web sstore redis to realize the distributed session of vertx HTTP application

Abbkine trakine F-actin Staining Kit (green fluorescence) scheme

Duchefa MS medium contains vitamin instructions

2.<tag-哈希表, 字符串>补充: 剑指 Offer 50. 第一个只出现一次的字符 dbc

Duchefa d5124 md5a medium Chinese and English instructions

使用WebAssembly在浏览器端操作Excel
随机推荐
Enclosed please find. Net Maui's latest learning resources
Maker education infiltrating the transformation of maker spirit and culture
模式-“里氏替换原则”
10000+ 代码库、3000+ 研发人员大型保险集团的研发效能提升实践
SYSTEMd resolved enable debug log
Cutting edge technology for cultivating robot education creativity
vant 源码解析 event.ts 事件处理 全局函数 addEventListener详解
Determine the best implementation of horizontal and vertical screens
Utils/index TS tool function
培养机器人教育创造力的前沿科技
How to renew NPDP? Here comes the operation guide!
Learning notes of SAS programming and data mining business case 19
Abnova total RNA Purification Kit for cultured cells Chinese and English instructions
Using webassembly to operate excel on the browser side
vant 源码解析之 utils/index.ts 工具函数
Abnova CRISPR spcas9 polyclonal antibody protocol
PHP deserialization +md5 collision
Abnova blood total nucleic acid purification kit pre installed relevant instructions
【案例】元素的显示与隐藏的运用--元素遮罩
Duchefa p1001 plant agar Chinese and English instructions