当前位置:网站首页>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();
}
}边栏推荐
- Static routing default routing VLAN experiment
- [explain C language in detail] takes you to play with loop structure (for_while_do while)
- Test and open basic daily question brushing (continuous updating...)
- Golang - sync包的使用 (WaitGroup, Once, Mutex, RWMutex, Cond, Pool, Map)
- Esp8266wi fi data communication
- Self introduction and planning about programming
- 第五讲—按键控制LED
- Vitgan: training Gans with vision transformers
- TIM输出比较——PWM
- npm报错, Error: EPERM: operation not permitted, mkdir
猜你喜欢

初识C语言(1)

Timer interrupt experiment

Solution: various error reporting and pit stepping and pit avoiding records encountered in the alchemist cultivation plan pytoch+deeplearning (III)
![[explain C language in detail] this article takes you to know C language and makes you impressed](/img/37/205c1c6eb2ba704941e48ff89c6268.png)
[explain C language in detail] this article takes you to know C language and makes you impressed

Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis

C语言——while语句、dowhile语句、for循环和循环结构、break语句和continue语句

Brief introduction of VLAN principle and specific experimental configuration

【volatile原理】volatile原理

HCIA基础知识(1)

Lora通信应用开发
随机推荐
7.13 Weilai approved the written examination in advance
C语言——赋值运算符、复合的赋值运算符、自增自减运算符、逗号运算符、条件运算符、goto语句、注释
第四讲—讲解GPIO_Write函数以及相关例程
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
Codeforces Round #807 (Div. 2), problem: (C) Mark and His Unfinished Essay
Experiment of total connection and star topology of mGRE
The latest C language introduction and advanced - the most complete and detailed C language tutorial in history!! Section 1 - overview of C language
(前缀和/思维)Codeforces Round #806 (Div. 4)F. Yet Another Problem About Pairs Satisfying an Inequality
Esp8266wi fi data communication
静态路由基础配置(IP地址的规划、静态路由的配置),实现全网可达。
[explain C language in detail] takes you to play with the choice (Branch) structure
NAT (network address translation protocol)
Influence of pre frequency division value and automatic reload value on interrupt frequency
JS logical operator
About unsafe problems such as fopen and strError encountered in vs2022 or advanced version running environment
微信小程序:用户微信登录流程(附:流程图+源码)
TIM输出比较——PWM
Nat网络地址转换实验
关于在VS2022或者高级版本运行环境下遇到fopen,strerror等不安全的问题
WAN technology experiment