当前位置:网站首页>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;
}
边栏推荐
- 2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination
- Basic use of continuous integration server Jenkins
- Php+mysql registration landing page development complete code
- How to retrieve the password for opening word files
- Sdl2 + OpenGL glsl practice (Continued)
- 论文阅读_中文医疗模型_ eHealth
- [USACO 2009 Dec S]Music Notes
- How to choose cross-border e-commerce multi merchant system
- JS multidimensional array to one-dimensional array
- [free completion] development of course guidance platform (source code +lunwen)
猜你喜欢

Golang -- realize file transfer

Triangular rasterization

Review the old and know the new: Notes on Data Science

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

论文阅读_中文NLP_ELECTRA

并发操作-内存交互操作

Web - Information Collection

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

After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me
![[USACO 2009 Dec S]Music Notes](/img/e6/282a8820becdd24d63dcff1b81fcaf.jpg)
[USACO 2009 Dec S]Music Notes
随机推荐
String matching: find a substring in a string
Learning practice: comprehensive application of cycle and branch structure (I)
Leetcode simple question: check whether two string arrays are equal
MC Layer Target
FFMpeg filter
stm32逆向入门
Symbol of array element product of leetcode simple problem
Market status and development prospect prediction of global neutral silicone sealant industry in 2022
Market status and development prospect forecast of global heat curing adhesive industry in 2022
Youdao cloud notes
[luatos sensor] 1 light sensing bh1750
论文阅读_ICD编码_MSMN
C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement
Matplotlib -- save graph
STM32 reverse entry
[BMZCTF-pwn] 20-secret_ file
Introduction to message queuing (MQ)
【SQL注入点】注入点出现位置、判断
Internationalization and localization, dark mode and dark mode in compose
2022 P cylinder filling test content and P cylinder filling simulation test questions