题目

多组询问查询某个串是否为模式串的子序列


分析

考虑用子序列自动机做,匹配的时候显然选择靠前的,用个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的更多相关文章

  1. 洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速$dp\&Floyd$)

    洛谷P3502 [POI2010]CHO-Hamsters感想及题解(图论+字符串+矩阵加速\(dp\&Floyd\)) 标签:题解 阅读体验:https://zybuluo.com/Junl ...

  2. [洛谷P3501] [POI2010]ANT-Antisymmetry

    洛谷题目链接:[POI2010]ANT-Antisymmetry 题目描述 Byteasar studies certain strings of zeroes and ones. Let be su ...

  3. 【AC自动机】洛谷三道模板题

    [题目链接] https://www.luogu.org/problem/P3808 [题意] 给定n个模式串和1个文本串,求有多少个模式串在文本串里出现过. [题解] 不再介绍基础知识了,就是裸的模 ...

  4. 【后缀自动机】洛谷P3804模板题

    题目描述 给定一个只包含小写字母的字符串SSS, 请你求出 SSS 的所有出现次数不为 111 的子串的出现次数乘上该子串长度的最大值. 输入输出格式 输入格式: 一行一个仅包含小写字母的字符串SSS ...

  5. 【字符串】【hash】【倍增】洛谷 P3502 [POI2010]CHO-Hamsters 题解

        这是一道字符串建模+图论的问题. 题目描述 Byteasar breeds hamsters. Each hamster has a unique name, consisting of lo ...

  6. [洛谷P3512 [POI2010]PIL-Pilots]

    题目链接: 传送门走这里 题目分析: 感觉不是很难啊--不像是蓝题(AC量也不像)恶意评分? 少打了一个+1调了半天,就这样居然还能过60pts?我思路和题解第一篇高度重合是什么鬼啊,太过分了吧本来还 ...

  7. 洛谷 P3496 [POI2010]GIL-Guilds

    P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...

  8. 洛谷 P3507 [POI2010]GRA-The Minima Game

    P3507 [POI2010]GRA-The Minima Game 题目描述 Alice and Bob learned the minima game, which they like very ...

  9. 洛谷 P3505 [POI2010]TEL-Teleportation

    P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...

  10. 洛谷P3507 [POI2010]GRA-The Minima Game

    题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the ga ...

随机推荐

  1. VS Code实现SSH远程开发

    最近收获一台新台式机,但是个人主要还是使用自己的笔记本,用了几天远程控制,感觉各种不方便,最终决定配置一下VS Code实现SSH远程开发,特此记录. 首先介绍一下环境,控制端是Windows 11, ...

  2. 在写dockerfile时替换国内源

    众所周知,Debian是linux发行版中官方源最难用的一个,这个傻逼源让我再构建docker镜像时卡了很久. ​ 那么能不能替换构建dockerfile时使用的源呢?显然是可以的 ​ 在与Docke ...

  3. 我的第一个项目(八):(解决问题)图片资源无法加载(Error: Cannot find module "../../xxx" )

    好家伙,问题一堆   先开一个测试页模拟游戏模块的运行 原先的图片初始化方法失效了,(vue里面自然是用不了这种方法的) function createImage(src) { let img; if ...

  4. 【Azure 应用服务】Azure Durable Function(持久函数)在执行Activity Function时候,因为调用函数名称错误而导致长时间无响应问题

    问题描述 在使用Azure Durable Function函数,调用函数链模式来调用多个Activity Function. 函数链:https://docs.azure.cn/zh-cn/azur ...

  5. 用 nebula_dart_gdbc 在移动设备玩图数据库,泰酷辣!

    nebula_dart_gdbc,是访问 NebulaGraph 的 Dart 语言客户端,在 dart_gdbc 的规范下进行开发. dart_gdbc 是一套使用 Dart 语言定义的图数据库标准 ...

  6. BeanShell Sampler 前置处理器

    一概念: 前置处理器主要作用: 用于修改即将发送的http的请求数据 BeanShell预处理器可以在取样器发送请求之前被执行,可以通过它完成发送请求所需的数据 其中的ctx.vars.props.p ...

  7. Java运行时生成类元数据,初始化注解信息的方式

    问题前因 在一次技术升级中, 把分布式配置中心组件由百度的Disconf 改成 Nacos , 在对项目进行改造时, 首先将所有Disconf客户端依赖全部移除后, 依赖的封装的jar包中, 所有依赖 ...

  8. RocketMQ(6) offset管理

    这里的offset指的是Consumer的消费进度offset. 消费进度offset是用来记录每个Queue的不同消费组的消费进度的.根据消费进度记录器的不同,可以分为两种模式:本地模式和远程模式. ...

  9. Java 多线程------解决 实现继承 Thread类 方式线程的线程安全问题 方式二:同步方法

    1 package bytezero.threadsynchronization; 2 3 4 5 /** 6 * 使用同步方法解决实现 继承 Thread类 的线程安全问题 7 * 8 * 9 * ...

  10. Vue实现图片瀑布流

    在线演示地址:点击前往 一,创建一个Waterfall组件 代码如下: <template> <div class="waterfall"> <!-- ...