当前位置:网站首页>字典树(随学)
字典树(随学)
2022-06-29 17:47: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;
}
边栏推荐
- Function independent watchdog (iwdg) experiment based on stm32f103zet6 Library
- R language uses user-defined functions to write deep learning leaky relu activation functions and visualize leaky relu activation functions
- Face recognition 4- research on Baidu commercial solutions
- Repair of JSON parsing errors in a collection
- OpenFeign使用步骤 轮询策略与权重 log4j使用 openFeign拦截器的配置
- Industry application of smart city based on GIS 3D visualization
- /usr/bin/ld: warning: **libmysqlclient.so.20**, needed by //usr/
- 面试中问最常问的海量数据处理你拿捏了没?
- SRM系统可以为企业带来什么价值?
- Selenium file upload method
猜你喜欢

Bloom filter:
![[webdriver] upload files using AutoIT](/img/69/8c27626d515976b47f1df4831d09c8.png)
[webdriver] upload files using AutoIT

最受欢迎的30款开源软件

人脸识别4-百度商用方案调研

Leetcode daily question - 535 Encryption and decryption of tinyurl

Basic operations such as MySQL startup under Windows platform

Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly

Bottom level internal skill cultivation

Top 30 open source software

Opencv+YOLO-V3实现目标跟踪
随机推荐
育润多维发力慈善领域,勇抗企业公益大旗
mac安装php7.2
MaxCompute字符串替换函数-replace
上班可以做副业
Opencv+yolo-v3 for target tracking
自定义HandlerInterceptor拦截器实现用户鉴权
Serial port experiment based on stm32f103zet6 library function
YoloV6+TensorRT+ONNX:基于WIN10+TensorRT8+YoloV6+ONNX的部署
国外LEAD赚钱,做个网站真的很简单
What technology is an applet container? Can it help Internet of things enterprises break through the red sea?
3h精通OpenCV(六)-图像堆叠
填充每个节点的下一个右侧节点指针[利用好每个点->尽可能降低时空复杂度]
布隆过滤器:
Bottom level internal skill cultivation
PWM output experiment based on stm32f103zet6 library function
selenium上传文件
Custom handlerinterceptor interceptor for user authentication
底层内功修养
[try to hack] cookies and sessions
使用autoIt 上传文件