Codeforces Round #452 (Div. 2) - F. Letters Removing(树状数组+set)

CTFshow-CRYPTO(持续更新) 密码学签到 }wohs.ftc{galf 将字符串逆序即可 letters = '}wohs.ftc{galf' a = list(letters) a.reverse() for letters in a: print(letters,end='') crypto2 打开浏览器的控制台,复制粘贴回车即可得到flag crypto3 这一题同上 crypto4 如图填写即可,一开始e填写的是17,一直回答错误,后来经过群内大佬提醒软件的e是十六进制的,17转十六进制就是0x11 cr 阅读详情

 

F. Letters Removing

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya has a string of length n consisting of small and large English letters and digits.

He performs m operations. Each operation is described with two integers l and r and a character c: Petya removes from the string all characters c on positions between l and r, inclusive. It's obvious that the length of the string remains the same or decreases after each operation.

Find how the string will look like after Petya performs all m operations.

Input

The first string contains two integers n and m (1 ≤ n, m ≤ 2·105) — the length of the string and the number of operations.

The second line contains the string of length n, consisting of small and large English letters and digits. Positions in the string are enumerated from 1.

Each of the next m lines contains two integers l and r (1 ≤ l ≤ r), followed by a character c, which is a small or large English letter or a digit. This line describes one operation. It is guaranteed that r doesn't exceed the length of the string s before current operation.

Output

Print the string Petya will obtain after performing all m operations. If the strings becomes empty after all operations, print an empty line.

Examples

input

4 2
abac
1 3 a
2 2 c

output

b

input

3 2
A0z
1 3 0
1 1 z

output

Az

input

10 4
agtFrgF4aF
2 5 g
4 9 F
1 5 4
1 7 a

output

tFrg4

input

9 5
aAAaBBccD
1 4 a
5 6 c
2 3 B
4 4 D
2 3 A

output

AB

Note

In the first example during the first operation both letters 'a' are removed, so the string becomes "bc". During the second operation the letter 'c' (on the second position) is removed, and the string becomes "b".

In the second example during the first operation Petya removes '0' from the second position. After that the string becomes "Az". During the second operations the string doesn't change.

 

 

 

 

 

题意:

一个字符串,给你m个操作,每个操作删除l到r的字符c。

注意l和r是根据当前的字符串来给的。是变化的。

 

POINT:

因为是变化的l,r,所以我们要把他们还原为原始位置。

用树状数组实现,先给树状数组全为1。然后删一个字符,那个字符对应的位置就是1。

那么每次给你的l和r,那就从树状数组里找到前缀和恰好是l的位置。就实现了。二分查找+树状数组查询为(logn)^2.

先用set存下每一个字符的位置。因为set是有序的,用二分查找第l个,然后遍历下去到r。全删掉。

 

 

#include <set>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>

using namespace std;
const int maxn  = 4e5+5555;
#define lowbit(x) (x&-x)
int sum[maxn];
int n,m;
int flag[maxn];
set<int>S[70];
set<int>::iterator it;
int name(char x)
{
	if(x>='a'&&x<='z'){
		return x-'a'+1;
	}else if(x>='0'&&x<='9'){
		return x-'0'+1+26;
	}else{
		return x-'A'+1+36;
	}
}
void subtract(int x)
{
	for(int i=x;i<=n;i+=lowbit(i))
		sum[i]--;
}
int query(int x)
{
	int ans=0;
	for(int i=x;i>=1;i-=lowbit(i)) ans+=sum[i];
	return ans;
}
int lb(int x)
{
	int l=1,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(query(mid)>=x){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	return r;
}
char s[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	for(int i=1;i<=n;i++){
		sum[i+lowbit(i)]+=++sum[i];
	}
	int l=strlen(s);
	for(int i=0;i<l;i++){
		int x=name(s[i]);
		S[x].insert(i+1);
	}
	for(int i=1;i<=m;i++){
		int l,r;char ss[22];
		scanf("%d%d%s",&l,&r,ss);
		int x=name(ss[0]);
		l=lb(l);
		r=lb(r);
		it=S[x].lower_bound(l);
		while(it!=S[x].end()&&*it<=r){
			flag[*it]=1;
			subtract(*it);
			S[x].erase(it++);
		}
	}
	for(int i=1;i<=l;i++){
		if(!flag[i]){
			printf("%c",s[i-1]);
		}
	}
	printf("\n");


}

 

 

 

 

 

 

 

面经-2023-联发科MTK-数字芯片设计 阅读详情

相关推荐

word 2013 长篇文档排版案例教程

office 2013 制作长文格式模板

1万+

问题 A: Small and Large Integers(C++)

时间限制: 1.000 Sec 内存限制: 128 MB题目描述1≤A≤B≤1091≤K≤100输入A B K输出样例输入3 8 2样例输出3478提示。

m0_73795998的博客 177

从零构建AI辅助逆向分析环境:JADX-MCP与LLM的实战集成指南

本文详细介绍了如何从零构建AI辅助逆向分析环境,通过集成JADX-MCP与LLM技术,提升Android应用逆向工程效率。文章涵盖环境搭建、插件安装、MCP服务器配置及实战案例分析,帮助开发者快速掌握AI在代码理解、漏洞挖掘和自动化文档生成中的应用。

weixin_27875131的博客 836

Atcoder Beginner Contest093小结

AtCoder Beginner Contest 093 2018/04/07 20:00:00 ~ 2018/04/07 21:40:00呼呼(。-_-。)最初了前三题,第四题突然变成700分,吓死我了A - abc of ABCTime limit : 2sec / Memory limit : 256MBScore : 100 pointsProblem StatementYou are g...

fu_xuantong的博客 412

使用buildroot系统的qmake编译QT出现Unknown module(s) in QT: xxxx 的错误解决方法

可以看到,我这里使用的是 qt5base-5.15.2 目录下的qmake,这个qmake只包含了基础的qt模块,而额外添加的qt模块没有包含进去,需要使用。可以看到我这里是有的,如果你跟我一样,模块存在,但是还是报找不到对应模块的错误的话,大概率是跟我一样,用错qmake了,看第二点。在包含 qt5base 目录下查看,是否有对应模块的目录,如果没有的话,需要通过make menuconfig 添加一下。目录下的qmake才可以。

T541132的博客 2489

射频功率放大器设计实战:从理论到Layout的全流程解析

本文以一款40W、960MHz LDMOS功率放大器为例,系统解析了从理论分析、仿真设计到版图实现的射频功率放大器设计全流程。内容涵盖AB类放大器选型、核心指标定义、稳定性分析、Load-Pull/源牵引仿真、史密斯圆图匹配、偏置网络设计,以及最终的谐波平衡仿真与版图电磁验证,为工程师提供了一套从理论到实践的完整设计方法论。

weixin_29266007的博客 248

【CF899F】 Letters Removing

题目 题目描述 Petya has a string of length nn consisting of small and large English letters and digits. He performs mm operations. Each operation is described with two integers ll and rr and a character cc ...

Brute♂force 384

第17篇:深入解析OpenEuler 24.03系统中的逻辑卷管理(LVM)

OpenEuler 24.03系统中的逻辑卷管理(LVM)提供了灵活的存储管理方案,通过在物理存储与文件系统间构建抽象层实现动态资源分配。

专注于系统运维、数据库、DevOps、虚拟化技术、docker、kubernetes、等云原生技术。 1689

899F - Letters Removing

Codeforces 899F - Letters Removing 思路:考虑一下怎么找到输入的l和r在原来串中的位置,我们想到用前缀和来找,一开始所有位置都为1,删掉后为0,那么前缀和为l的位置就是l的位置,前缀和为r的位置就是r的位置。 那么用树状数组来维护一下前缀和,再用二分查找来找到位置就可以了。然后找到的区间可能很大,然而我们要删的只有一种字符,把每种字符的位置分开来保存来操作,...

weixin_33682719的博客 202

分布式数据采集框架openclaw-worker:模块化设计与实战指南

数据采集是获取网络信息、实现自动化处理的基础技术,其核心原理是通过模拟HTTP请求从目标源提取结构化数据。在工程实践中,传统单体脚本面临维护困难、扩展性差等挑战。分布式采集架构通过解耦任务定义与执行,结合消息队列实现水平扩展,显著提升了系统的弹性与可靠性。openclaw-worker作为模块化的工作节点,将采集流程配置化,支持CSS选择器、XPath等多种提取规则,并集成请求速率控制、代理IP池等反爬策略,适用于竞品监控、内容聚合等需要高效、稳定获取数据的应用场景。

weixin_28706423的博客 298

SpringBoot整合LangChain4j实现RAG检索实战详解

本文介绍了使用LangChain4j框架在Java生态中构建RAG(检索增强生成)应用的最佳实践。作为最接近Python LangChain的Java实现,LangChain4j提供了文档解析、向量化存储到检索增强的全套组件,并与SpringBoot深度集成。文章通过电商智能客服场景,详细演示了从零搭建RAG系统的完整流程:包括使用PostgreSQL+pgvector作为生产级向量数据库、文档加载与向量化处理、声明式AI服务实现以及查询压缩、结果重排等进阶优化技巧。同时对比了内存模式与生产级向量库的差异,

分享AI、区块链技术及应用,未来已来 432

codeforces 899 F - Letters Removing (线段树)

题意:给你一个长度为n的字符串,只包括大小写字母与数字,还有q个操作,对于每个操作 将[l,r]区间内删除字符ch题解:对于这个操作l,r,是之间操作完的串的l,r,也就是你还需要找到原始串中的l,r 方法是开62个线段树,每一个维护区间和,那么对于如何寻找原来的l,r,进行前缀和的二分查找,前缀和等于l的地方就是原始串中l的地方这题把我折磨死了= =。 62个线段树刚好卡在内存附近,打的lazy

yxmGo 376

手把手教你学Simulink--巴特沃斯滤波器设计与实现仿真

巴特沃斯滤波器的设计目标是拥有尽可能平滑的通带响应,这意味着在通带内信号衰减最小且没有波动。这种类型的滤波器非常适合用于音频处理、生物医学信号处理以及其他需要高保真度的应用场景。根据应用需求的不同,可以选择低通、高通、带通或带阻滤波器。明确你的系统需求,如输入信号类型(正弦波、方波等)、滤波器类型(低通、高通、带通或带阻)、截止频率、滤波器阶数等。假设我们需要设计一个4阶低通巴特沃斯滤波器,其截止频率为1kHz,用来过滤掉高于1kHz的所有频率成分。

MHD0815的博客 449

Codeforces Round #452 (Div. 2)-F-Letters Removing(树状数组+set+二分)

F. Letters Removingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya has a string of length n consisting of small and large English letters an...

信仰.的博客 398

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Codeforces Round #452 (Div. 2) F. Letters Removing 线段树

F. Letters Removing time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Petya has a string of length n consisting of small and large English l

zstu_zy的博客 465

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Codeforces Round #452 F. Letters Removing

Description Petya has a string of length n consisting of small and large English letters and digits. He performs m operations. Each operation is described with two integers l and r and a character c: ...

weixin_30249203的博客 97

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Codeforces 899F Letters Removin-线段树

传送门题意: 给一个字符串和m个操作,每次给出l,r,c,把字符串中l-r这段区间的字符为c的字符删掉,求最后的字符串。(n,m<=2e5)Solution: 此题显然不能离线搞,那么有什么动态的优秀的数据结构呢?我们一定会先想到线段树,我们可以维护每个区间剩余字符的个数siz和区间中每个字符的个数num,通过siz来求出每个l,r对应的在线段树上的l,r。 PS:因为字符串一定是不断减少的,

Fizzmy的博客 744

Codeforces 899F Letters Removing [线段树]

Codeforces 899F Letters Removing [线段树]

ACTerminate的博客 559

CF899F. Letters Removing

给一个字符串支持以下操作:区间删除某个特定字符。最后输出字符串。n,m<=200000。 这题我居然不会可以回家了。。 首先,单点删除,选个平衡树比如set。 然后,他给的下标是会随删除操作变化的,需要查“存在于字符串中的第K个是谁”来找左右端点,一个树状数组搞定。 树状数组找出题目给的x,y在初始串中的下标L,R,对每个字符开一个set存它的所有出现位置,把这个set里在...

a2850363633的博客 191

Codeforces 899 F. Letters Removing (二分、树状数组)

题目链接:Letters Removing 题意:   给你一个长度为n的字符串,给出m次操作。每次操作给出一个l,r和一个字符c,要求删除字符串l到r之间所有的c。 题解:   看样例可以看出,这题最大的难点在于每次在字符串中删除了前面的字符会对后面的字符产生影响。如何确定当前l和r所指的字符?这里由于对字符的位置查询相当于单点操作区间查询,可以用树状数组维护字符串的前缀和,这...

201

1212 -- Large or small

Large or small Time Limit:1000MS  Memory Limit:65536K Total Submit:93 Accepted:63 Description Only Input and Output Input Several cases. A letter indicating the operation('L' means to output th

jtahstu_akoj的博客 3105

【CodeForces】899 F. Letters Removing

【题目】F. Letters Removing 【题意】给定只含小写字母、大写字母和数字的字符串,每次给定一个范围要求删除[l,r]内的字符c(l和r具体位置随删除变动),求m次操作后的字符串。n<=2*10^5。 【算法】树状数组+平衡树(set) 【题解】因为坐标是序列变动后的,动态坐标可以转化为找到第l个存在的数字到第r个存在的数字之间的范围。 将序列中存在记为1,删除记为0,...

weixin_34403693的博客 179

codeforces831B

B. Keyboard Layouts time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are two popular keyboard layouts i

时光、疏离了记忆づ童话的博客 756

aoj.339.Large or small

Large or small Description Only Input and Output Input Several cases. A letter indicating the operation('L' means to output the lager one while 'S' the smaller). Followed by two integers

aniSHadow的专栏 456

Codeforces - Letters Removing

题目链接:Codeforces - Letters Removing 每次我们需要从删除之后的序列,找到原来对应的区间。 其实就是一个第k大的问题。平衡树或者权值树维护即可。 然后因为只有删除操作,我们直接从set当中删除即可。 AC代码: #pragma GCC optimize("-Ofast","-funroll-all-loops") #include<bits/stdc++.h...

青烟绕指柔的博客 355

Remove Duplicate Letters

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order a

Yuwen's Hero 1784
上一篇: 二叉树的非递归遍历实现
下一篇: TCP/IP 第1章 理解网络编程和套接字
Mr_Treeeee
博客等级 码龄10年 38粉丝 551原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值