当前位置:网站首页>第十九届浙江省 I. Barbecue
第十九届浙江省 I. Barbecue
2022-07-03 04:37:00 【Snow_raw】
第十九届浙江省 I. Barbecue
题意: 两个同学Putata和Budada在玩一个游戏,一开始给定一个固定长度的字符串,接下去有 m m m次询问,每次询问给定一个范围 [ l , r ] [l,r] [l,r],即从原字符串中截取 [ l , r ] [l,r] [l,r]的部分。从第一个同学Putata开始操作,每次操作必须从字串开头或末尾移除一个字符,如果操作前后字串变成回文串那么操作的同学判负,问每次询问哪个同学会赢?
Tip:
- 如果一开始第一个同学拿到的就是回文串,那么必定输掉比赛。
- 否则第一个同学拿到的就是非回文串,由于如果操作后子串变成回文串那么也算操作的同学输,那么在操作的同学最好的方案就是 非回文 * \implies *非回文
- 这就说明如果游戏没结束即上一次操作的同学结束操作后字串变成 非回文,那么意味着游戏如果始终持续进行除去 第一次操作 ,操作的同学拿到的 始终是非回文串 。那么通过不断操作,最终拿到长度为 2 2 2 的同学 必败 ,因为无论怎么操作,剩下的 1 1 1 个字符必定是 回文 。
- 那么显然有如果第一次操作的同学拿到的是 非回文 并且长度为偶数那么第一次操作的同学必败。如果是 非回文 并且长度为奇数,那么第一次操作的同学必胜。 当然非回文偶数字串有一种特殊情况为 a b a b a b a b abababab abababab,不管拿掉首个字符还是末尾字符都是操作者输,所以同样归类至第一种情况。
- 接下去就是如果判定区间 [ l , r ] [l,r] [l,r]内的字串为回文串,由于题目给到的查询有 1 0 6 10^6 106,所以支持的复杂度即为 O ( 1 ) O(1) O(1)查询。那么我们可以通过字符串 h a s h hash hash和 M a n a c h a r Manachar Manachar算法来进行处理。此处给出字符串 h a s h hash hash做法(学习地址)。
代码:
#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;
}
边栏推荐
- Joint search set: the number of points in connected blocks (the number of points in a set)
- Smart contract security audit company selection analysis and audit report resources download - domestic article
- [set theory] Cartesian product (concept of Cartesian product | examples of Cartesian product | properties of Cartesian product | non commutativity | non associativity | distribution law | ordered pair
- [free completion] development of course guidance platform (source code +lunwen)
- Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
- What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
- RSRS指标择时及大小盘轮动
- 2022 new examination questions for the main principals of hazardous chemical business units and examination skills for the main principals of hazardous chemical business units
- FFMpeg example
- Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended
猜你喜欢
![[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)

Golang -- realize file transfer

Introduction to JVM principle

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

FISCO bcos zero knowledge proof Fiat Shamir instance source code

MC Layer Target

A outsourcing boy's mid-2022 summary

Some information about the developer environment in Chengdu

使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭

Asp access teaching management system design finished product
随机推荐
解决bp中文乱码
Leetcode simple question: the key with the longest key duration
2022 registration examination for safety production management personnel of hazardous chemical production units and examination skills for safety production management personnel of hazardous chemical
Asp access teaching management system design finished product
2022 new examination questions for the main principals of hazardous chemical business units and examination skills for the main principals of hazardous chemical business units
A outsourcing boy's mid-2022 summary
[set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
Solve BP Chinese garbled code
Triangular rasterization
Two drawing interfaces - 1 Matlab style interface
[dynamic programming] subsequence problem
X-ray normal based contour rendering
vulnhub HA: Natraj
data2vec! New milestone of unified mode
Internationalization and localization, dark mode and dark mode in compose
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
Number of uniform strings of leetcode simple problem
2022-02-14 (394. String decoding)
Leetcode simple question: check whether the array is sorted and rotated