当前位置:网站首页>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;
}
边栏推荐
- Leetcode simple question: check whether two string arrays are equal
- When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
- 2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
- Market status and development prospects of the global IOT active infrared sensor industry in 2022
- The reason why the entity class in the database is changed into hump naming
- Sdl2 + OpenGL glsl practice (Continued)
- [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)
- Triangular rasterization
- Writing skills of multi plate rotation strategy -- strategy writing learning materials
- Employee attendance management system based on SSM
猜你喜欢
Prefix and (continuously updated)
STM32 reverse entry
Design and implementation of JSP logistics center storage information management system
Php+mysql registration landing page development complete code
关于开学的准备与专业认知
Arthas watch grabs a field / attribute of the input parameter
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
[XSS bypass - protection strategy] understand the protection strategy and better bypass
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
Web security - CSRF (token)
随机推荐
【工具跑SQL盲注】
Why should programmers learn microservice architecture if they want to enter a large factory?
The reason why the entity class in the database is changed into hump naming
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
Joint search set: the number of points in connected blocks (the number of points in a set)
GFS distributed file system (it's nice to meet it alone)
联发科技2023届提前批IC笔试(题目)
Human resource management system based on JSP
Dive into deep learning - 2.1 data operation & Exercise
RSRS index timing and large and small disc rotation
Kingbasees plug-in KDB of Jincang database_ exists_ expand
Reptile exercise 03
How to use kotlin to improve productivity: kotlin tips
[luatos sensor] 1 light sensing bh1750
Kubernetes source code analysis (I)
Network security textual research recommendation
How to retrieve the password for opening word files
2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
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
逆袭大学生的职业规划