当前位置:网站首页>Dictionary tree (optional)
Dictionary tree (optional)
2022-06-29 17:56:00 【eva_ can(not)survive】
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#define lowbit(x) ((x)&(-x))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using pll=pair<ll,ll>;
const int MAXN=1e6+5;
const int INF=0x3f3f3f3f;
const ll NNF=0x3f3f3f3f3f3f3f3f;
int n;
int tri[MAXN][26],cnt;
bool exist[MAXN],vis[MAXN];
void init(){
memset(tri,0,sizeof(tri));
cnt=1;
}
void insert(const string &s){
int cur=1;
for(auto c:s){
if(!tri[cur][c-'a']) tri[cur][c-'a']=++cnt;
cur=tri[cur][c-'a'];
}
exist[cur]=1;
}
void find_prefix(const string &s){
int cur=1;
for(auto c:s){
if(!tri[cur][c-'a']) return void(printf("WRONG\n"));
cur=tri[cur][c-'a'];
}
if(!exist[cur]) printf("WRONG\n");
else if(!vis[cur]){
printf("OK\n");
vis[cur]=1;
}
else printf("REPEAT\n");
}
void solve(){
init();
scanf("%d",&n);
string s;
for(int i=1;i<=n;i++){
cin>>s;
insert(s);
}
scanf("%d",&n);
for(int i=1;i<=n;i++){
// scanf("%d",&n);
cin>>s;
find_prefix(s);
}
}
int main(){
solve();
return 0;
}
边栏推荐
- [try to hack] cookies and sessions
- mac安装php7.2
- Face recognition 4- research on Baidu commercial solutions
- Prevent form resubmission based on annotations and interceptors
- Matlab farthest point sampling (FPS)
- What is the SRM system? How do I apply the SRM system?
- Visio annotation, annotation location
- /usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/
- Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]
- 3h精通OpenCV(五)-透视变换
猜你喜欢

从一个被应用商店坑了的BUG说起

SRM supplier collaborative management system function introduction

YoloV6+TensorRT+ONNX:基于WIN10+TensorRT8+YoloV6+ONNX的部署

Force deduction daily question 06.29 add two numbers

Visio标注、批注位置

Yurun multidimensional makes efforts in the charity field and bravely resists the corporate public welfare banner

Kubekey2.2.1 kubernetes1.23.7 offline package production +harbor Department summer and upload image

Wechat applet development reserve knowledge

最受欢迎的30款开源软件
![分割回文串[dp + dfs组合]](/img/7b/221b000984977508f849e19802c2c2.png)
分割回文串[dp + dfs组合]
随机推荐
Spingmvc requests and responses
设置双击运行 jar 文件
SRM supplier collaborative management system function introduction
Maidong Internet won the bid of Dajia Insurance Group
VB.Net读写NFC Ntag标签源码
位图的详细介绍及模拟实现
It's really easy to make money in foreign lead and build a website
How to solve the 2003 error of MySQL in Linux
Xiaomai technology x hologres: high availability of real-time data warehouse construction of ten billion level advertising
两种Controller层接口鉴权方式
Web Scraping with Beautiful Soup for Data Scientist
selenium 文件上传方法
MaxCompute Studio
Partial mock of static class of phpunit operation
Have you grasped the most frequently asked question in the interview about massive data processing?
Younger sister Juan takes you to learn JDBC - 2-day dash Day1
How MySQL queries character set codes of tables
育润多维发力慈善领域,勇抗企业公益大旗
MaxCompute Studio
【目标跟踪】|stark配置 win otb