当前位置:网站首页>The 19th Zhejiang I. barbecue
The 19th Zhejiang I. barbecue
2022-07-03 04:44:00 【Snow_ raw】
The 19th Zhejiang I. Barbecue
The question : Two classmates Putata and Budada Playing a game , Give a fixed length string at the beginning , There will be m m m Time to ask , Give a range each time you ask [ l , r ] [l,r] [l,r], That is, intercept from the original string [ l , r ] [l,r] [l,r] Part of . From the first classmate Putata Start the operation , Each operation must remove a character from the beginning or end of the string , If the string before and after the operation becomes a palindrome string, the classmate of the operation will be judged negative , Ask every time you ask which student will win ?
Tip:
- If the first student gets the palindrome string at the beginning , Then you must lose the game .
- Otherwise, the first student will get a non palindrome string , Because if the substring becomes a palindrome string after the operation, it is also counted as the operation of the students to lose , Then the best plan for students in operation is Non palindrome * \implies * Non palindrome
- This means that if the game is not over, that is, after the last operation, the string becomes Non palindrome , Then it means that if the game continues all the time The first operation , The students who operated got it Always a non palindrome string . Then through continuous operation , The final length is 2 2 2 Classmate You will lose , Because no matter how you operate , The rest 1 1 1 Characters must be Palindrome .
- So obviously, if the student who operated for the first time got Non palindrome And the length is even, then the student who operates for the first time will lose . If it is Non palindrome And the length is odd , Then the first operation of the students will win . Of course, there is a special case of non palindrome even digit strings a b a b a b a b abababab abababab, Whether the first character or the last character is removed, the operator will input , So it is also classified into the first case .
- The next step is if the decision interval [ l , r ] [l,r] [l,r] The string in is palindrome string , The queries given by the title are 1 0 6 10^6 106, So the complexity of support is O ( 1 ) O(1) O(1) Inquire about . Then we can use string h a s h hash hash and M a n a c h a r Manachar Manachar Algorithm . The string is given here h a s h hash hash practice ( Study address ).
Code :
#include<bits/stdc++.h>
using namespace std;
int n,q;
const int P = 131;
const int N = 1e6+10;
unsigned long long p[N],t[N],t1[N];
unsigned long long query1(int l,int r){
return t[r]-t[l-1]*p[r-l+1];
}
unsigned long long query2(int l,int r){
return t1[l]-t1[r+1]*p[r-l+1];
}
char s[N];
int main(){
scanf("%d%d",&n,&q);
scanf("%s",s+1);
p[0]=1;
t[0]=0;
t1[n+1]=0;
for(int i=1;i<=n;i++){
p[i]=p[i-1]*P;
t[i]=t[i-1]*P+s[i];
}
for(int i=n;i>=1;i--){
t1[i]=t1[i+1]*P+s[i];
}
while(q--){
int l,r;
scanf("%d%d",&l,&r);
if(query1(l,r)==query2(l,r)){
printf("Budada\n");
}
else{
if((r-l+1)%2==0)printf("Budada\n");
else printf("Putata\n");
}
}
return 0;
}
边栏推荐
- Introduction to JVM principle
- Php+mysql registration landing page development complete code
- Review the old and know the new: Notes on Data Science
- MC Layer Target
- C primre plus Chapter 10 question 6 inverted array
- Introduction to message queuing (MQ)
- 7. Integrated learning
- Human resource management system based on JSP
- 《牛客刷verilog》Part II Verilog进阶挑战
- data2vec! New milestone of unified mode
猜你喜欢

Two drawing interfaces - 1 Matlab style interface

The programmer went to bed at 12 o'clock in the middle of the night, and the leader angrily scolded: go to bed so early, you are very good at keeping fit

MPM model and ab pressure test
![[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)](/img/36/53886b9d3b98f744be2b6aa6b5d3eb.jpg)
[PCL self study: filtering] introduction and use of various filters in PCL (continuously updated)

Pyqt control part (II)

Sdl2 + OpenGL glsl practice (Continued)

2022 P cylinder filling test content and P cylinder filling simulation test questions

FuncS sh file not found when using the benchmarksql tool to test kingbases

"Niuke brush Verilog" part II Verilog advanced challenge

Preparation for school and professional cognition
随机推荐
Integration of Android high-frequency interview questions (including reference answers)
Php+mysql registration landing page development complete code
Leetcode simple question: the key with the longest key duration
【工具跑SQL盲注】
普通本科大学生活避坑指南
When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully
Day 51 - tree problem
Handling record of electric skateboard detained by traffic police
MySQL winter vacation self-study 2022 12 (3)
Factor stock selection scoring model
UiPath实战(08) - 选取器(Selector)
Contents of welder (primary) examination and welder (primary) examination in 2022
[set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
Library management system based on SSM
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
Games101 Lesson 9 shading 3 Notes
The reason why the entity class in the database is changed into hump naming
Market status and development prospect prediction of global SoC Test Platform Industry in 2022
Priv-app permission异常
Kingbasees plug-in KDB of Jincang database_ exists_ expand