Queries on a String

output

standard output

A string s is given. Also there is a string p, and initially it is empty. You need to perform q operations of kind «add a letter to the end of the string p» and «remove a letter from the end of the string p», and after performing each operation you must say whether or not s contains pas a subsequence.

Input

The first line contains the string s of length from 1 to 200000, consisting of lowercase Latin letters.

The second line contains a single integer q (1 ≤ q ≤ 200000) — the number of operations.

Each of the next q lines describes an operation in the format «push c», which means «add letter c to the end of the string p» (c is lowercase Latin letter), or «pop», which means «remove letter from the end of the string p». The «pop» operations is guaranteed never to be applied to the empty string p.

Output

Output q lines, each of which equals «YES» or «NO», depending on whether or not the string p is contained in the string s as a subsequence after performing the corresponding operation.

Example

input

Copy

abcabc
30
push a
pop
push a
push a
push a
pop
push c
push b
pop
pop
push b
push c
push c
pop
pop
pop
pop
push b
push c
push c
pop
push b
push c
pop
pop
push a
push b
push c
push a
pop

output

YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES

先将原字符串的每一个字符用一个二位数组记录下来,记录的原则是nxt[i][j]记录s[i+1]的出现的字符,这样就能不断往下走,判断接下来是否存在所需要的字符,然后用一个一位整形数组代表之后变化的字符串,t[0]=0;(为二维数组遍历的起点),然后就判断是否存在,如果存在t[cnt]就存字符出现的第一个位置x,此时nxt[x]存的是接下来位置的字符情况,如果不存在,那本身也不存在了,所以就t[cnt]=-1;然后cnt++;

最后查是否t[cnt-1]是否不为-1即可

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;


const int N = 200005;


int n,Q,nxt[N][26],t[N];
char s[N],ope[10],c;


int main()
{
    scanf("%s %d",s+1,&Q);
    n=strlen(s+1);
    memset(nxt[n],-1,sizeof(nxt[n]));
    for(int i=n-1;i>=0;i--)
    {
        for(int j=0;j<26;j++)
        {
            if(s[i+1]-'a'==j)nxt[i][j]=i+1;
            else nxt[i][j] = nxt[i+1][j];
        }
    }
    int len=1;
    t[0]=0;
    while(Q--)
    {
        scanf(" %s",ope);
        if(ope[2]=='s')
        {
            scanf(" %c",&c);
            if(t[len-1]==-1)t[len]=-1;
            else t[len]=nxt[t[len-1]][c-'a'];
            len++;
        }
        else len--;
        if(t[len-1]!=-1)puts("YES");
        else puts("NO");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
To optimize queries in Hive, you can follow these best practices: 1. Use partitioning: Partitioning is a technique of dividing a large table into smaller, more manageable parts based on specific criteria such as date, region, or category. It can significantly improve query performance by reducing the amount of data that needs to be scanned. 2. Use bucketing: Bucketing is another technique of dividing a large table into smaller, more manageable parts based on the hash value of a column. It can improve query performance by reducing the number of files that need to be read. 3. Use appropriate file formats: Choose the appropriate file format based on the type of data and the query patterns. For example, ORC and Parquet formats are optimized for analytical queries, while Text and SequenceFile formats are suitable for batch processing. 4. Optimize data storage: Optimize the way data is stored on HDFS to improve query performance. For example, use compression to reduce the amount of data that needs to be transferred across the network. To create a partition table with Hive, you can follow these steps: 1. Create a database (if it doesn't exist) using the CREATE DATABASE statement. 2. Create a table using the CREATE TABLE statement, specifying the partition columns using the PARTITIONED BY clause. 3. Load data into the table using the LOAD DATA statement, specifying the partition values using the PARTITION clause. Here's an example: ``` CREATE DATABASE my_db; USE my_db; CREATE TABLE my_table ( id INT, name STRING ) PARTITIONED BY (date STRING); LOAD DATA LOCAL INPATH '/path/to/data' OVERWRITE INTO TABLE my_table PARTITION (date='2022-01-01'); ``` This creates a table called `my_table` with two columns `id` and `name`, and one partition column `date`. The data is loaded into the table with the partition value `2022-01-01`.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值