Non-Substring Subsequence CodeForces - 1451B(字符串处理问题)

LTE/NR中的相应cause场景【原创】 目录1.背景2.LTE EMM cause2.0 写在最前2.1 特殊处理的cause第一梯队第二梯队2.2 非特殊处理的cause3.NR cause 实网分析终端被拒等问题,经常遇到各类cause,其会对应不同的终端限制行为。查找已有资料后理解没有很深,自行总结本文用于梳理现象,如有错误敬请指正,转载请注明出处。 本文用于记录协议Ts 24.301及Ts 24.501中的cause及其对应行为。 已总结的cause值: 24.301中的cause分 阅读详情

Hr0d1y has q queries on a binary string s of length n. A binary string is a string containing only characters ‘0’ and ‘1’.

A query is described by a pair of integers li, ri (1≤li<ri≤n).

For each query, he has to determine whether there exists a good subsequence in s that is equal to the substring s[li…ri].

A substring s[i…j] of a string s is the string formed by characters sisi+1…sj.

String ais said to be a subsequence of string b if a can be obtained from b by deleting some characters without changing the order of the remaining characters.

A subsequence is said to be good if it is not contiguous and has length ≥2. For example, if s is “1100110”, then the subsequences s1s2s4 (“1100110”) and s1s5s7 (“1100110”) are good, while s1s2s3 (“1100110”) is not good.

Can you help Hr0d1y answer each query?

Input

The first line of the input contains a single integer t (1≤t≤100 ) — the number of test cases. The description of each test case is as follows.

The first line contains two integers n(2≤n≤100) and q (1≤q≤100) — the length of the string and the number of queries.

The second line contains the string s.

The i-th of the next q lines contains two integers li and ri (1≤li<ri≤n ).

Output

For each test case, output q lines. The i-th line of the output of each test case should contain “YES” if there exists a good subsequence equal to the substring s[li…ri] , and “NO” otherwise.

You may print each letter in any case (upper or lower).

Example

Input

2
6 3
001000
2 4
1 3
3 5
4 2
1111
1 4
2 3

Output

YES
NO
YES
NO
YES

Note

In the first test case, s[2…4]=“010”. In this case s1s3s5 (“001000”) and s2s3s6 (“001000”) are good suitable subsequences, while s2s3s4
(“001000”) is not good.
s[1…3]=“001”. No suitable good subsequence exists.
s[3…5]=“100”. Here s3s5s6 (“001000”) is a suitable good
subsequence.

题意:

先给出一个区间,在区间内的字符串组成一个新的字符串,求原来的字符串除给出的区间外还有没有与新的字符串相同的字符串(下标不可以连续)有输出Yes,否则No

思路:

中间不动,对比两边
判断是否还有相同的字符串,可以先判断区间外前面的范围是否有和区间内第一个字符相同的,如果有,就可以实现下标不连续(意思就是将区间的第一个字符的下标换为前面与其相同的字符的下标,同理,对比区间后面的也是如此)
一句话思路:如果区间前面或后面能找到与新字符串的第一个字符或最后一个字符相同的,就输出Yes

代码:

#include<stdio.h>
char a[120];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,q,l,r;
        scanf("%d %d",&n,&q);
        scanf("%s",a+1);
        while(q--)
        {
            int j=0;
            scanf("%d %d",&l,&r);
            int f=0,f1=0;
            for(int i=1; i<l; i++)
            {
                if(a[i]==a[l])
                    f=1;
            }
            for(int i=r+1; i<=n; i++)
            {
                if(a[i]==a[r])
                    f1=1;
            }
            if(f==1||f1==1)
                printf("YES\n");
            else
                printf("NO\n");
        }
    }
    return 0;
}
音乐生成 - 使用LSTM或Transformer模型进行音乐生成,如MIDI音乐生成。 在本篇博客中,我们将介绍如何使用LSTM和Transformer模型生成MIDI音乐。我们将首先概述音乐生成的一般流程,然后深入了解LSTM和Transformer模型的特点和实现。最后,我们将通过Python代码演示如何使用这两种模型生成MIDI音乐。 阅读详情

相关推荐

Excel药品说明书数据库:从零开始搭建医药数据查询系统(附完整模板)

本文详细介绍了如何从零开始搭建Excel药品说明书数据库,提供完整的医药数据查询系统模板。涵盖数据库架构设计、数据清洗标准化、智能查询系统搭建及维护优化,帮助医药从业者高效管理药品信息,提升查询速度和准确性。

weixin_28327051的博客 234

Codeforces Round #685 (Div. 2)

A. Subtract or Divide time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Ridbit starts with an integer n. In one move, he can perform one of the following operations: divide n by one of its proper divis

zxzxzxxzx的博客 446

1020空心杯电机驱动设计与ESP32实战

空心杯电机是一种高动态响应的直流微特电机,其驱动本质是解决电感负载下的大di/dt启动、反电动势耦合与电流纹波抑制问题。核心原理在于建立包含内阻、电感和反电动势的等效电路模型,并据此匹配开关器件、PWM参数与采样闭环。技术价值体现在小体积下实现毫秒级响应、低噪声(>30kHz)、高精度电流保护(±50mA)及热鲁棒性。典型应用于微型航模、手持云台与精密执行器等对功率密度和动态性能敏感的嵌入式系统。本文以1020规格空心杯电机为对象,基于ESP32平台完成从MOSFET选型、32kHz硬件PWM生成到INA2

weixin_42298164的博客 584

Codeforces Round #685 (Div. 2) B. Non-Substring Subsequence 模拟

Hr0d1y has q queries on a binary string s of length n. A binary string is a string containing only characters ‘0’ and ‘1’. A query is described by a pair of integers li, ri (1≤li<ri≤n). For each query, he has to determine whether there exists a good sub

qq_45891413的博客 377

SAP PP后台配置实战:从BOM到工艺路线的全流程解析

本文详细解析了SAP PP模块后台配置的全流程,从BOM到工艺路线的关键步骤与实战技巧。通过分享生产计划、工作中心能力计划等核心配置经验,帮助企业优化生产管理流程,提升SAP系统实施效率。特别针对BOM配置、工艺路线设置等常见问题提供解决方案。

weixin_29300931的博客 1010

VIVADO中的IP核在MATLAB中仿真

VIVADO中的IP核在MATLAB中仿真项目简述VIVADO建立FFT IP核MATLAB调用FFT IP核 项目简述 我们都会用MATLAB进行算法验证,但是经常会发现如果VIVADO中调用了IP核,那么最终会发现VIVADO与MATLAB之间的数据不可以统一的对应起来。那么,MATLAB验证的效果就会大大下降,那么可不可以想办法将VIVADO中的IP核封装成一个函数在MATLAB中调用呢?答案是可以的。这篇博客主要以FFT的IP核为例讲解封装成一个函数并且成功在MATLAB中调用。 本次实验所使用的软

zhangningning1996的博客 6992

Codeforces 1451B. Non-Substring Subsequence

Hr0d1y has ???? queries on a binary string ???? of length ????. A binary string is a string containing only characters ‘0’ and ‘1’. A query is described by a pair of integers ????????, ???????? (1≤????????<????????≤????). For each query, he has to deter

tomjobs的博客 456

Loupe Browser实战指南:解锁10xGenomics单细胞数据的可视化奥秘

本文提供了Loupe Browser的实战指南,帮助用户无需编程即可探索和可视化10xGenomics单细胞数据。文章详细介绍了从数据导入、界面导航到细胞亚群鉴定、差异基因分析的核心操作流程,并分享了高级技巧与避坑指南,是快速上手这一强大可视化工具的必备参考。

weixin_29313423的博客 206

cf Queries on a String

#include<iostream> #include<cstring> #include<cstdio> using namespace std; #define maxn 200005 char s[maxn]; int nxt[maxn][27],ans[maxn],t[maxn]; int main(){ int q; ...

weixin_30443731的博客 189

【100分- 求最多可以派出多少支团队】(题目+思路+Java&C++&Python解析+在线测试)

用数组代表每个人的能力,一个比赛活动要求参赛团队的最低能力值为N,每个团队可以由1人或者2人组成,且1个人只能参加1个团队,计算出最多可以派出多少只符合要求的团队。

m0_73659489的博客 313

R语言中的summarise函数和mutate函数用于计算分组占比。下面是关于这两个函数的详细介绍以及相应的源代码示例:

R语言中的summarise函数和mutate函数用于计算分组占比。

CodeByte的博客 1183

Codeforces 1451B. Non-Substring Subsequence(思维+前缀和)

Description Example input 2 6 3 001000 2 4 1 3 3 5 4 2 1111 1 4 2 3 output YES NO YES NO YES Solution 如果能找到,必然可以是当前子串丢掉某一段点的子串+另一个点,我们用前缀和判断即可 Code #include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 10; int bit[maxn]; int pre[maxn]

chr1stopher 267

Python爬虫:招聘网站岗位要求、薪资与求职者数据爬取与分析

通过本文的教程,我们学习了如何通过 Python 编写招聘数据爬虫,爬取招聘网站上的岗位要求、薪资和求职者数据,并通过数据存储、清洗、分析和可视化,获取有价值的信息。网站如智联招聘、猎云网、前程无忧等,都提供了大量的招聘信息,包括岗位要求、薪资范围、工作经验、学位要求、招聘公司等。本文将介绍如何通过 Python 编写爬虫,爬取招聘网站上的岗位要求、薪资、求职者数据,并通过数据存储、分析和可视化等手段,为求职者或招聘者提供实用的信息和决策支持。通过循环抓取多个页面的数据,可以获取不同岗位的信息。

2201_76125261的博客 723

Codeforces 1451B Non-Substring Subsequence(贪心)

Description: 题目大意:给定一个长度为 n 的字符串,q 次询问,每次询问在字符串中是否存在着s[l,…r]相同的子串,要求字串不连续且在原串的出现次序未发生改变。 解题思路: 算法标签:贪心 假设如果在 s[l] 之前未出现与 s[l] 相同的字符,同时在 s[r] 之后也未出现与它相同的字符,那么只有它自己与它相等(废话),与题意矛盾。所以只有在 l 之前便出现与 s[l] 相同的字符,或者在 r 之后出现与 s[r] 相同的字符才会出现 good 字串。 代码: // TSWorld #i

TSWorld 236

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

codeforse1451总结

codeforse1451总结

周世正的博客 392

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

B. Non-Substring Subsequence

思路:在带检测子串的左右两段遍历查询是否存在s[ L ]和s[ R ]即可。即遍历母串的[ 1 , L-1 ]中是否存在待检测串的首元素。或者[ R+1 , n ]中是否存在待检测串的尾元素。 #include<bits/stdc++.h> using namespace std; int T,n,q; int main(){ cin>>T; while(T--) { string s; int l,r; cin >> n >>

cosx_的博客 212

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

1310. XOR Queries of a Subarray

Given the arrayarrof positive integers and the arrayquerieswherequeries[i] = [Li,Ri],for each queryicompute theXORof elements fromLitoRi(that is,arr[Li]xorarr[Li+1]xor...xorarr[R...

Do not mess it up 273

【CF1451B】Non-Substring Subsequence

链接 传送门 分析 要保持子串的有序性,那我们可以想象向子串左右边找,判断是否找到相同的字符就可以了。数据很小,直接遍历。 代码 #include <iostream> #include <string> #include <cstdio> int t, n, q, l, r; using namespace std; int main() { cin >> t; while (t--){ cin >> n &g

weixin_50070650的博客 216

Chapter 3. Strings, Vectors and Arrays -C++ Primer 5 notes

Chapter 3. Strings, Vectors and Arrays What does built-in types include? chapter 2 array maybe more? What is the characteristic of built-in types? These types represent facilities present in most computer hardware, such as numbers or characters. What i

Nekoraa的博客 1977

CF1451B - Non-Substring Subsequence

1451B - Non-Substring Subsequence 题意 给定一个字符串 sss,再给定一个字符串的子串 xxx,求这个字符串 sss 中是否存在一个不连续的子序列满足 xxx 题解 Key 满足这一情况当且仅当在 xxx 的首元素或者最后一个元素不是 sss 中的第一个出现或是最后一个出现 证明 假定有一个不连续的子序列在上述条件不成立时存在,那么这个子序列 kkk 必须以字符串中的第一个出现开头,最后一个出现结尾,那么唯一存在的字符串就是长度等于给定原串 xxx 的字符串,xxx

QiuHong 的博客 265

本周题解

@本周题解 A Do you own an ID card?You must have a identity card number in your family's Household Register. From the ID card you can get specific personal information of everyone. The number has 18 bits,the first 17 bits contain special specially meanings:th

weixin_51671731的博客 979

String的substring和subSequence的区别

 今天截取字符串的时候,无意中发现了subSequence,并且不小心用上了,呵呵,发现同样能和substring一样截取,效果一模一样。我就好奇地翻看了一下源码: public CharSequence subSequence(int beginIndex, int endIndex) { return this.substring(beginIndex, endI

italywj222的博客 5732

Codeforces Round #616 (Div. 2)(题解)

写在前面: 疫情严重,希望武汉与中国一起加油。 这次就做出两题,第三题没读完,实在是比较慢。 A. Even But Not Even time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Let’s define a number ebne...

Sqssq的博客 4466

Subarray Substring vs Subsequence

Subarray/Substring vs Subsequence and Programs to Generate them Subarray/Substring A subbarray is a contiguous part of array. An array that is inside another array. For example, consider the

screaming的博客 789

Codeforce_828C_String Reconstruction_字符串处理

String ReconstructionIvan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the

NITjianbagengmu的博客 472

Y - Nearly Lucky Number CodeForces - 110A

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5...

weixin_44003830的博客 214
上一篇: 牛客竞赛(字符串+思维)
下一篇: Circle Game CodeForces - 1451D( 博弈 +思维 )
Piink
博客等级 码龄7年 119粉丝 195原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值