CodeForces 670E Correct Bracket Sequence Editor

i茅台APP加密参数逆向分析:MT-Device-ID与mt-v生成算法 在移动应用安全领域,参数加密是防止API滥用的重要手段。通过对通信协议的逆向分析,可以揭示加密参数的生成原理,这对理解移动应用安全机制具有重要意义。以i茅台APP为例,其关键接口使用了MT-Device-ID和mt-v两个加密参数,前者基于设备硬件信息生成,后者则通过动态签名机制确保请求时效性。这类技术广泛应用于电商、金融等需要高安全性的场景。通过抓包工具和逆向工程手段,可以还原出从设备指纹生成到动态签名的完整技术链条,其中涉及MD5、SHA256等常见哈希算法的应用。掌握这些加密参数的生成逻辑,不仅有助于 阅读详情

题目

E. Correct Bracket Sequence Editor
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS).

Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and "1"-s to it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not. Each bracket in CBS has a pair. For example, in "(()(()))":

1st bracket is paired with 8th,
2d bracket is paired with 3d,
3d bracket is paired with 2d,
4th bracket is paired with 7th,
5th bracket is paired with 6th,
6th bracket is paired with 5th,
7th bracket is paired with 4th,
8th bracket is paired with 1st.
Polycarp's editor currently supports only three operations during the use of CBS. The cursor in the editor takes the whole position of one of the brackets (not the position between the brackets!). There are three operations being supported:

«L» — move the cursor one position to the left,
«R» — move the cursor one position to the right,
«D» — delete the bracket in which the cursor is located, delete the bracket it's paired to and all brackets between them (that is, delete a substring between the bracket in which the cursor is located and the one it's paired to).
After the operation "D" the cursor moves to the nearest bracket to the right (of course, among the non-deleted). If there is no such bracket (that is, the suffix of the CBS was deleted), then the cursor moves to the nearest bracket to the left (of course, among the non-deleted).

There are pictures illustrated several usages of operation "D" below.


All incorrect operations (shift cursor over the end of CBS, delete the whole CBS, etc.) are not supported by Polycarp's editor.

Polycarp is very proud of his development, can you implement the functionality of his editor?

Input
The first line contains three positive integers n, m and p (2 ≤ n ≤ 500 000, 1 ≤ m ≤ 500 000, 1 ≤ p ≤ n) — the number of brackets in the correct bracket sequence, the number of operations and the initial position of cursor. Positions in the sequence are numbered from left to right, starting from one. It is guaranteed that n is even.

It is followed by the string of n characters "(" and ")" forming the correct bracket sequence.

Then follow a string of m characters "L", "R" and "D" — a sequence of the operations. Operations are carried out one by one from the first to the last. It is guaranteed that the given operations never move the cursor outside the bracket sequence, as well as the fact that after all operations a bracket sequence will be non-empty.

Output
Print the correct bracket sequence, obtained as a result of applying all operations to the initial sequence.

Examples
input
8 4 5
(())()()
RDLD
output
()
input
12 5 3
((()())(()))
RRDLD
output
(()(()))
input
8 8 8
(())()()
LLLLLLDD
output
()()
Note
In the first sample the cursor is initially at position 5. Consider actions of the editor:

command "R" — the cursor moves to the position 6 on the right;
command "D" — the deletion of brackets from the position 5 to the position 6. After that CBS takes the form (())(), the cursor is at the position 5;
command "L" — the cursor moves to the position 4 on the left;
command "D" — the deletion of brackets from the position 1 to the position 4. After that CBS takes the form (), the cursor is at the position 1.
Thus, the answer is equal to ().

大意

给出一个合法的括号序列,一个光标的初始位置在p,有3个操作,‘L’是把光标向左移一格,‘R’是把光标向右移一格,‘D’是把当前光标位置到与这个位置匹配的括号位置的一段删去,问最后剩下的括号序列。

思路

先求出每个位置与其匹配的括号位置,再建一个双向链表维护删除和移动操作。

代码

#include<cstdio>
#include<stack>
#include<cstdlib>
using namespace std;
struct node
{
	int id,nextid;
	node *link1,*link2;//link1是前驱节点的指针,link2是后继结点的指针
};
struct NODE
{
	int id;
	char ty;
};
char op[500005],str[500005];
int match[500005];//match记录每个位置和他匹配的位置
stack <NODE> s;
int main()
{
	int n,m,p,i;
	NODE tmp;
	scanf("%d%d%d",&n,&m,&p);
	scanf("%s",str+1);
	scanf("%s",op);
	for(i=1;i<=n;i++)
	{
		if(!s.empty())
		{
			tmp=s.top();
			if(str[i]==')'&&tmp.ty=='(')
			{
				s.pop();
				match[i]=tmp.id;
				match[tmp.id]=i;
				continue;
			}
		}
		tmp.id=i;
		tmp.ty=str[i];
		s.push(tmp);
	}
	node *head,*temp,*pre=0;
	for(i=1;i<=n;i++)
	{
		temp=(node*)malloc(sizeof(node));
		if(i==1)
			head=temp;
		temp->id=i;
		temp->nextid=match[i];
		temp->link1=pre;
		if(pre!=NULL)
			pre->link2=temp;
		pre=temp;
	}
	head->link1=NULL;
	temp->link2=NULL;
	for(temp=head;temp->link2;temp=temp->link2);
	node *nowpos=head;
	for(i=1;i<p;i++)
		nowpos=nowpos->link2;
	for(i=0;i<m;i++)
	{
		if(op[i]=='L')
			nowpos=nowpos->link1;
		else if(op[i]=='R')
			nowpos=nowpos->link2;
		else
		{
			int del=nowpos->nextid;
			node *del_id=nowpos,*left,*right;
			if(del>nowpos->id)
			{
				while(1)
				{
					if(del_id->id==del)
						break;
					del_id=del_id->link2;
				}
				left=nowpos;
				right=del_id;
			}
			else
			{
				while(1)
				{
					if(del_id->id==del)
						break;
					del_id=del_id->link1;
				}
				left=del_id;
				right=nowpos;
			}
			if(left==head)
			{
				head=right->link2;
				nowpos=right->link2;
			}
			else if(right->link2==NULL)
			{
				left->link1->link2=NULL;
				nowpos=left->link1;
			}
			else
			{
				left->link1->link2=right->link2;
				right->link2->link1=left->link1;
				nowpos=right->link2;
			}
		}
	}
	for(temp=head;temp;temp=temp->link2)
		printf("%c",str[temp->id]);
	puts("");
	return 0;
}


Intel MKL库常用模块的C语言实现 文章目录1. 随机数生成1.1 等概率的01分布 viRngUniform1.2 (复)高斯分布 vsRngGaussian2. 向量-向量运算2.1 向量数乘与加法 cblas_caxpby2.2 向量内积 cblas_cdotu_sub2.3 向量范数 cblas_scnrm23. 矩阵-向量运算3.1 矩阵存储方案3.2 矩阵-向量乘法 cblas_cgemv4. 矩阵-矩阵运算4.1 矩阵... 阅读详情

相关推荐

从实习生到独立上手:我是如何用海思PQTool搞定IPC图像调试的

本文分享了从实习生到独立使用海思PQTool进行IPC图像调试的成长历程。通过工具搭建、核心参数调整和实战案例,详细介绍了如何高效解决图像质量问题,特别强调了ISP调试中的关键参数和实用技巧,适合刚入门的图像调试工程师参考。

weixin_33756596的博客 311

Codeforces Round #177 (Div. 2) 题解

【前言】咦?现在怎么流行打CF了?于是当一帮大爷

阿蒋的专栏 1768

2. Netty使用JSerialComm进行串口读取(二)

现在开始处理这些问题 第一个问题:串口读取超时异常一路传播到最后也没有处理。 ​ 第二个问题:即使处理了该异常,程序仍然退出,这不能满足一些实际使用要求需求。该问题与设置很长的读取超时时间没关系,无论多长到时间后总会退出。

s3c2410的博客 2461

codeforces 670E. Correct Bracket Sequence Editor

E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Polycarp started to devel

哇咔咔 1618

Go语言AI智能体开发实战:基于LangGraphGo构建下一代工作流引擎

在AI应用开发领域,工作流编排是构建复杂智能系统的核心技术。其核心原理是将任务执行过程建模为状态图,通过节点和边的组合定义数据流转路径,实现多步骤推理与工具调用的自动化。这种基于状态图的编程模型,为智能体提供了清晰的“思考-行动-观察”循环抽象,显著提升了复杂业务逻辑的可维护性和可观测性。从技术价值看,它解决了传统代码中状态分散、流程僵化的问题,支持条件分支、并行执行等高级模式,是实现生产级AI应用的关键基础设施。在应用场景上,该技术广泛适用于客服机器人、自动化审批、数据ETL等需要多步骤协调的领域。本文以

weixin_30457551的博客 360

单片机技术入门与实战:从零基础到项目开发

单片机(MCU)作为嵌入式系统的核心组件,集成了CPU、内存和各种接口电路,广泛应用于智能家居、工业控制和汽车电子等领域。其工作原理基于实时控制和低功耗设计,通过定时器、中断系统和通信接口等功能模块实现各种控制任务。在物联网和智能硬件快速发展的背景下,掌握单片机开发技术成为电子工程师的重要技能。本文以STM32和PIC系列为例,详细解析单片机的基本概念、功能模块和选型指南,并分享从入门到项目实战的系统学习方法,帮助开发者在3-6个月内快速掌握这一关键技术。

weixin_35753291的博客 651

Codeforces670E. Correct Bracket Sequence Editor

E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Polycarp started to develop a text ed

KeyboardPianist的博客 502

微信小程序PC端兼容性实战:如何绕过限制在电脑上运行手机端小程序

本文详细解析了微信小程序在PC端的兼容性问题及解决方案,重点介绍了如何利用`wx.getSystemInfo`API检测运行环境,并通过修改User-Agent、动态环境检测与适配等技术手段实现手机端小程序在PC端的顺畅运行。文章还提供了常见兼容性问题的解决方法和调试工具推荐,帮助开发者高效应对多端适配挑战。

weixin_28366053的博客 863

Codeforces 670E - Correct Bracket Sequence Editor 链表

E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Polycarp s...

200

【StarRocks】-- DATETIME 与 TIMESTAMP 区别详解

本文详细解析了StarRocks中DATETIME/DATETIMEV2与TIMESTAMP的区别及使用场景。DATETIME系列存储人类可读时间,不携带时区;TIMESTAMP实际指Unix时间戳,建议用BIGINT存储。关键差异包括:精度选择(DATETIMEV2支持微秒级)、时区处理(仅函数计算时影响)、存储方式等。针对不同场景提供选型建议:单时区展示用DATETIMEV2,跨时区计算用BIGINT存储Epoch。特别强调与MySQL迁移时的注意事项,并给出常见问题解决方案和最佳实践清单,包括统一入口

欢迎来到我的博客,一起探索代码里的世界! 496

Harness Engineering:让Coding Agent真正落地生产

本文将带你系统性地了解如何让Coding Agent真正落地生产,核心是依托(全球领先的持续交付、云成本管理、 feature flagging、安全治理一体化平台),结合企业级AIDD(AI-Driven Development)的工程化实践,构建一套可信赖、可观测、可扩展、可治理的Coding Agent落地体系。核心概念与理论基础:什么是Coding Agent?它和普通的AI代码补全工具(比如GitHub Copilot)有什么区别?什么是Harness Engineering?

移动开发前沿的博客 454

codeforces 670E Correct Bracket Sequence Editor

Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct math

qiuxueming_csdn 537

openbmc mctp i3c适配步骤

本文介绍了在Intel OKS平台下,BMC作为I3C从设备如何适配MCTP over I3C的实现方法。主要内容包括:1)关键术语解释,如MDB(Mandatory Data Byte)值为0xAE,DCR(Device Characteristics Register)和BCR(Bus Characteristics Register)的设置;2)适配流程说明,包括BMC作为控制器主节点分配地址后成为MCTP端点,CPU作为总线所有者的角色转换;3)测试验证步骤,展示通过mctp-client工具发送指

wit_yuan的专栏 131

Codeforces 670E Correct Bracket Sequence Editor (list模拟)

题意给出一个合法的小括号序列,然后有三种操作: L 光标左移 R 光标右移 D 删除当前位置括号并他的对应括号,两括号中间的也一起删除。 输出操作后的序列。思路list直接模拟就好了,这题主要考察的也就是list的操作吧。 list的删除也确实是个坑,注意光标移动出界之后别忘了向左移动一下。代码#include <stdio.h> #include <string.h> #include

Winterfell30' Blog 3856

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【31.93%】【codeforces 670E】Correct Bracket Sequence Editor

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Polycarp started to develop a text editor that works only with corr...

AWCXV 130

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

CodeForces 670E Correct Bracket Sequence Editor (模拟双向链表)

题意:一串括号序列,有一个移动光标,给出三种操作,‘L’:将光标左移,‘R’:将光标右移,‘D’删除光标所在括号及其对应括号之间的序列,并将括号移动到删除序列的右端,若右端不存在,则移动到左端。输出最后序列。 题解:模拟双向链表 用le[]le[]le[]记录当前括号的左端是哪一个,ri[]ri[]ri[]记录右端,pa[]pa[]pa[]记录与之匹配的括号下标,用stack模拟一下。 因为最后要输出最终序列,用ststst记录一下起始下标。 #define _CRT_SECURE_NO_WARNINGS

gongyuandaye的博客 245

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Codeforces 670E Correct Bracket Sequence Editor【模拟双相链表】

E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output  Recently Polycarp started to deve

mengxiang000000 499

群晖DS925+企业级NAS实战:数据备份、快照与SHR配置指南

在数字化转型中,企业数据存储与保护成为刚需。NAS作为本地化存储方案,在数据备份、文件共享和灾难恢复中扮演关键角色。与传统服务器相比,NAS更侧重存储管理,通过磁盘阵列(如SHR)平衡容量与冗余,结合快照技术实现秒级数据回滚。群晖DS925+作为5盘位企业级NAS,其Active Backup for Business套件可集中备份员工PC、服务器和虚拟机,配合防篡改快照抵御勒索病毒。实际部署中,需合理规划SHR阵列、热备盘与权限隔离,实现高效可靠的企业数据管理。本文从实践角度分享群晖DS925+的选型思考

weixin_34021089的博客 360

CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)

E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Polycarp starte

Frozen_Forest 890

CodeForces 670 E.Correct Bracket Sequence Editor(链表)

Description 给出一个合法的括号序列,给出一个指针的初始位置,m次操作,操作分三种: L: 指针左移 R: 指针右移 D: 删除当前指针指的括号以及与该括号匹配的括号,然后指针右移,如果右边没有括号则左移 求m次操作后的括号序列 Input 第一行三个整数n,m,pos分别表示初始状态括号序列长度,操作数以及初始状态指针位置,之后一个长度为n的字符串表示该括号序列,最后输入一

ZSQ 486

Data Structure Note WEEK 3

WEEK3-2020/9/29 Problem A - Broken Keyboard-UVa 11988 Difficuty: 2 | tag: deque/list You’re typing a long text with a broken keyboard. Well it’s not so badly broken. The only problem with the keyboard is that sometimes the “home” key or the “end” key get

RiKler的博客 345

Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快。 代码: #include<iostream> #include<cstdio> #include<cstring> #include<map> #include&l...

weixin_30904593的博客 135

Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)

题目链接:http://codeforces.com/contest/670/problem/E 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以内的所有字符(比如'(()())'),'R'操作表示右移光标,'L'操作表示左移光标。删除操作后光标向右移,要是再向右移没有字符的话,那就停在最后的字符上了。问你最后的括号字符是怎么样的。 这题用...

weixin_30940783的博客 195

Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description Recently Polycarp started to develop a text editor that works only with correct bracket sequences (...

weixin_30354675的博客 113
上一篇: 大视野1079: [SCOI2008]着色方案
下一篇: UVA 10891 Game of Sum
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值