当前位置:网站首页>Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
2022-07-27 02:20:00 【ZaneBobo】

One . The question
tina Have a string of initial strings s, He can do it “ Copy an existing string l-r Segment to the end of the current string ” Operate multiple times , For example, the initial string is work He chose l=1 r=3 So now the string becomes workwor, When he repeatedly executes c After changing this string in this way , Here you are q A query , Each query gives you a number k, Let you output the current string number k What is a character .
Input :
T(T Group test data )
n( Initial string length ) c( Paste times ) q(q Queries , Question no k What is a character )
Output :
(q That's ok )
The first k What is a character
Example :
Input
1
4 3 3
mark
1 4
5 7
3 8
1
10
12
initial mark
- The first transformation ( take l=1,r=4 Paste the paragraph to the end )->markmark
- The second transformation ( take l=5,r=7 Paste the paragraph to the end )->markmarkmar
- The third transformation ( take l=3,r=8 Paste the paragraph to the end )->markmarkmarrkmark
So the output is
m
a
r
Two . Ideas
utilize to flash back thought , Record the left and right endpoints of the source segment corresponding to the left and right endpoints of each added segment , In code map<LL,LL>p Do this , Then every time we check k Go back to this position , Keep finding out where he is in the initial stage , Because its position is pasted layer by layer , So it must initially have a position in the initial string . And then because I have to be right k Query the interval , So record the left boundary of all the added character segments , In code map<LL,LL>st Do this , Then every time you query, you can find out which additional segment exists , And then go back , Find out which paragraph of this paragraph is pasted , And then update k The location of , Then use the present k The location of , Again, binary search the left boundary for backtracking , The left boundary of this position until the current search is 1( That is, the current position is less than the length of the initial string ) until .
Then output the character of the current position .
In fact, this question doesn't need two points Just 40 Intervals ! Hahaha, I didn't master the time complexity There is an extra dichotomy when enumerating , Just enumerate normally ~ The idea is right .
3、 ... and . Code
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N = 55;
typedef long long LL;
map<LL,LL> p,st;
void solve()
{
int n,c,q;
cin>>n>>c>>q;
string s;
cin>>s;
LL len=s.size();
int cnt=1;// This is a position pointer to the left boundary
st[1]=1;// The left boundary of the initial string is 1
for(int i=1;i<=c;i++)
{
LL a,b;
cin>>a>>b;
p[len+1]=a,p[len+1+b-a]=b;// This is the correspondence between the pasted segment and the left and right boundaries of the original string segment
st[++cnt]=len+1;// Save the left border of each paste
len+=b-a+1;// Length of string , String is lengthening
}
while(q--)
{
LL k;
cin>>k;
while(k>s.size())// Until we trace back to the location of the current query At the position corresponding to the initial string
{
LL l=1,r=cnt;
while(l<r)// Dichotomy k Currently in that range
{
LL mid=(l+r+1)>>1;
if(st[mid]<=k) l=mid;
else r=mid-1;
}
k=p[st[r]]+k-st[r];
}
cout<<s[k-1]<<endl;
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
solve();
}
}边栏推荐
- 通过对射式红外传感器计次实验讲解EXTI中断
- HCIA动态路由RIP基础实验
- JS -- first understand the naming rules and data types of JS and variables
- 全网显示 IP 归属地,是怎么实现的?
- JS 99 multiplication table
- Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)
- Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
- Lora通信应用开发
- Lora光照传感器节点数据采集
- FID index reproduction step on the pit to avoid the pit text generation image FID quantitative experiment whole process reproduction (FR é Chet inception distance) quantitative evaluation experiment s
猜你喜欢

Mechanical hard disk Selection Guide -- from the selection experience

Vitgan: training Gans with vision transformers

JUC并发编程

C语言——字符和字符串、算术运算符、类型转换

About unsafe problems such as fopen and strError encountered in vs2022 or advanced version running environment

Solution: various error reporting and pit stepping and pit avoiding records encountered in the alchemist cultivation plan pytoch+deeplearning (III)

Republishing and routing strategy of OSPF

lvs+keepalived项目实战

Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay

(前缀和/思维)Codeforces Round #806 (Div. 4)F. Yet Another Problem About Pairs Satisfying an Inequality
随机推荐
ospf协议概述以及基础概念
2022 latest live broadcast monitoring 24-hour monitoring (III) analysis of barrage in live broadcast room
定时器中断实验
Static routing default routing VLAN experiment
Lecture 4 - explain GPIO_ Write function and related routines
OSPF protocol overview and basic concepts
Pseudo class of a element
2022zui new Tiktok 24-hour round robin live broadcast monitoring (I) live broadcast room start-up monitoring
Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
The basic configuration of static routing (planning of IP address and configuration of static routing) realizes the accessibility of the whole network.
CAN总线通信应用
【volatile原理】volatile原理
HCIA静态路由基础模拟实验
数字芯片的面积优化:第三届“华为杯”研究生创芯大赛数字方向上机题1详解
NB-IOT联网通信
【mysql】mysql启动关闭命令以及一些报错解决问题
识时务者常用网址大全
HCIA基础知识(1)
Solution to high collapse
【数据库课程设计】SQLServer数据库课程设计(学生宿舍管理),课设报告+源码+数据库关系图