当前位置:网站首页>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;
}
边栏推荐
- 论文阅读_中文医疗模型_ eHealth
- Truncated sentences of leetcode simple questions
- "Niuke brush Verilog" part II Verilog advanced challenge
- Matplotlib -- save graph
- [BMZCTF-pwn] 20-secret_ file
- Market status and development prospects of the global IOT active infrared sensor industry in 2022
- 2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
- Mount NFS in kubesphere
- 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
- AWS VPC
猜你喜欢

Auman Galaxy new year of the tiger appreciation meeting was held in Beijing - won the double certification of "intelligent safety" and "efficient performance" of China Automotive Research Institute

The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping

The reason why the entity class in the database is changed into hump naming

MC Layer Target

Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)

X-ray normal based contour rendering

2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank

The least operation of leetcode simple problem makes the array increment

Introduction to message queuing (MQ)

Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
随机推荐
2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination
Joint set search: merge intervals and ask whether two numbers are in the same set
移动端——uniapp开发记录(公共请求request封装)
Library management system based on SSM
Arthas watch grabs a field / attribute of the input parameter
stm32逆向入门
How to retrieve the password for opening word files
Hj35 serpentine matrix
Employee attendance management system based on SSM
Joint search set: the number of points in connected blocks (the number of points in a set)
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
MPM model and ab pressure test
Symbol of array element product of leetcode simple problem
FFMpeg filter
C primre plus Chapter 10 question 6 inverted array
Youdao cloud notes
Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
Introduction to JVM principle
[BMZCTF-pwn] 20-secret_ file
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022