#子序列自动机,vector#洛谷 3500 [POI2010]TES-Intelligence Test
题目
多组询问查询某个串是否为模式串的子序列
分析
考虑用子序列自动机做,匹配的时候显然选择靠前的,用个vector查询最近的就行了
代码
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#define rr register
using namespace std;
const int N=1000011;
vector<int>::iterator it;
int n,Q; vector<int>K[N];
inline signed iut(){
rr int ans=0; rr char c=getchar();
while (!isdigit(c)) c=getchar();
while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
return ans;
}
signed main(){
n=iut();
for (rr int i=1;i<=n;++i)
K[iut()].push_back(i);
Q=iut();
for (rr int i=1;i<=Q;++i){
rr int len=iut(),now=0,flag=1;
for (rr int j=1;j<=len;++j){
rr int x=iut(); if (!flag) continue;
it=upper_bound(K[x].begin(),K[x].end(),now);
if (it==K[x].end()) flag=0;
else now=*it;
}
puts(flag?"TAK":"NIE");
}
return 0;
}
#子序列自动机,vector#洛谷 3500 [POI2010]TES-Intelligence Test的更多相关文章
- 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)
洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...
- [洛谷P3501] [POI2010]ANT-Antisymmetry
洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...
- 【AC自动机】洛谷三道模板题
[题目链接] https://www.luogu.org/problem/P3808 [题意] 给定n个模式串和1个文本串,求有多少个模式串在文本串里出现过. [题解] 不再介绍基础知识了,就是裸的模 ...
- 【后缀自动机】洛谷P3804模板题
题目描述 给定一个只包含小写字母的字符串SSS, 请你求出 SSS 的所有出现次数不为 111 的子串的出现次数乘上该子串长度的最大值. 输入输出格式 输入格式: 一行一个仅包含小写字母的字符串SSS ...
- 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解
这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...
- [洛谷P3512 [POI2010]PIL-Pilots]
题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...
- 洛谷 P3496 [POI2010]GIL-Guilds
P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...
- 洛谷 P3507 [POI2010]GRA-The Minima Game
P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...
- 洛谷 P3505 [POI2010]TEL-Teleportation
P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...
- 洛谷P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...
随机推荐
- Kafka本地单实例安装
下载安装 从国内镜像站点下载并安装Kafka安装包,以下载并安装v3.2.3版本为例. $ tar -xzf kafka_2.12-3.2.3.tgz $ cd kafka_2.12-3.2.3 启动 ...
- del,str,repr,call,bool,add,len等魔术方法以及与类相关的魔术属性---day23
1.__del__ # ### __del__魔术方法(析构方法) ''' 触发时机:当对象被内存回收的时候自动触发(1.页面执行完毕回收所有变量2.所有对象被del的时候) 功能:对象使用完毕后资源 ...
- 【Azure Redis 缓存】如何使得Azure Redis可以仅从内网访问? Config 及 Timeout参数配置
问题描述 问题一:Redis服务,如何可以做到仅允许特定的子网内的服务器进行访问? 问题二:Redis服务,timeout和keepalive的设置是怎样的?是否可以配置成timeout 0? 问题三 ...
- expect tcl 摘录
目录 部分参考来源说明 例子 expect命令 核心命令有三个 spawn.expect.send 其他expect命令 expect命令的选项 变量 tcl摘录 数据类型 符号 命令 其他说明 部分 ...
- 从0开始入门智能知识库和星火大模型,打造AI客服。
介绍FastWiki FastWiki是一个高性能.基于最新技术栈的知识库系统,旨在为大规模信息检索和智能搜索提供解决方案.它采用微软Semantic Kernel进行深度学习和自然语言处理,在后端使 ...
- RocketMQ(2) 消息的生产和存储
## 一 : 消息的生产 1. 消息的生产过程 Producer在发送消息时可以将消息写入到指定topic的某Broker中的某Queue中,其经历了如下过程: Producer发送消息之前,会先向N ...
- C++//常用排序算法 sort //打乱 random_shuffle //merge 两个容器元素合并,并储存到另一容器中(相同的有序序列) //reverse 将容器内的元素进行反转
1 //常用排序算法 sort //打乱 random_shuffle 2 //merge 两个容器元素合并,并储存到另一容器中(相同的有序序列) 3 //reverse 将容器内的元素进行反转 4 ...
- 开源:基于mybatis和jpa的数据库安全加密脱敏插件,围观交流
开源:基于mybatis和jpa的数据库安全加密脱敏插件,围观交流
- ACS 构词法 + 44个后缀 记忆方法
抖音号:九词君-不用语法学好英语
- history = his + story 男性史 = 历史 学单词
history = his + story 男性史 = 历史 早先还有 herstory 由于女性地位底下,就由 history 代表历史了. 然后 history 由拉丁文过来 story 从法语过 ...