当前位置:网站首页>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;
}
边栏推荐
- 2.14 summary
- Basic use of continuous integration server Jenkins
- data2vec! New milestone of unified mode
- [set theory] binary relationship (definition field | value field | inverse operation | inverse synthesis operation | restriction | image | single root | single value | nature of synthesis operation)
- Shell script Basics - basic grammar knowledge
- Learning practice: comprehensive application of cycle and branch structure (I)
- Youdao cloud notes
- X-ray normal based contour rendering
- How to choose cross-border e-commerce multi merchant system
- Prefix and (continuously updated)
猜你喜欢

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

MPM model and ab pressure test

Leetcode simple problem delete an element to strictly increment the array

C language self-made Games: Sanzi (tic tac toe chess) intelligent chess supplement

2022 chemical automation control instrument examination summary and chemical automation control instrument certificate examination

Introduction to message queuing (MQ)

Introduction to JVM principle
![[USACO 2009 Dec S]Music Notes](/img/e6/282a8820becdd24d63dcff1b81fcaf.jpg)
[USACO 2009 Dec S]Music Notes

JVM原理简介

FISCO bcos zero knowledge proof Fiat Shamir instance source code
随机推荐
【SQL注入点】注入点出现位置、判断
Two drawing interfaces - 1 Matlab style interface
2022 P cylinder filling test content and P cylinder filling simulation test questions
Leetcode simple question: check whether two string arrays are equal
带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...
stm32逆向入门
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
MC Layer Target
Truncated sentences of leetcode simple questions
普通本科大学生活避坑指南
[luatos sensor] 1 light sensing bh1750
Asp access teaching management system design finished product
General undergraduate college life pit avoidance Guide
FFMpeg filter
Writing skills of multi plate rotation strategy -- strategy writing learning materials
Introduction to message queuing (MQ)
论文阅读_中文NLP_ELECTRA
C Primer Plus Chapter 10, question 14 3 × 5 array
Matplotlib -- save graph
Web security - CSRF (token)