大意: 给定01串, 两人轮流操作, Tokitsukaze先手. 每次操作可以选择长为$k$的区间, 全部替换为$0$或$1$, 若替换后同色则赢. 求最后结果.

先判断第一步是否能直接赢, 不能的话若所有后继都是必败则必败, 否则平局.

正确性很显然, 因为一次操作不能直接赢的话, 只要模仿对手操作一定能平局.

那么问题就转化为判断一步操作后是否能赢.

假设$0$的最大范围为$[L[0],R[0]]$,$1$的最大范围为$[L[1],R[1]]$, 那么只要操作前$R[0]-L[0]+1\le k$或$R[1]-L[1]+1\le k$那么一定必胜.

然后用带撤销的线段树枚举所有后继模拟即可.

#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
using namespace std; const int N = 1e6+10;
int n,k,clk,tim[N<<2];
char s[N];
struct _ {
int L[2],R[2];
void upd(int v, int l, int r) {
L[v]=l,R[v]=r;
L[!v]=1e9,R[!v]=-1e9;
}
_ operator + (const _ & rhs) const {
_ ret;
REP(i,0,1) {
ret.L[i]=min(L[i],rhs.L[i]);
ret.R[i]=max(R[i],rhs.R[i]);
}
return ret;
}
} tr[N<<2],tmp[N<<2]; void build(int o, int l, int r) {
if (l==r) return tmp[o].upd(s[l]=='1',l,r);
build(ls),build(rs);
tmp[o]=tmp[lc]+tmp[rc];
}
void upd(int o) {
if (tim[o]!=clk) tr[o]=tmp[o],tim[o]=clk;
}
void update(int o, int l, int r, int ql, int qr, int v) {
upd(o);
if (ql<=l&&r<=qr) return tr[o].upd(v,l,r);
else {
upd(lc),upd(rc);
if (mid>=ql) update(ls,ql,qr,v);
if (mid<qr) update(rs,ql,qr,v);
tr[o]=tr[lc]+tr[rc];
}
}
int chk() {
REP(i,0,1) if (tr[1].R[i]-tr[1].L[i]+1<=k) return 1;
return 0;
} int work() {
scanf("%d%d%s", &n, &k, s+1);
build(1,1,n);
++clk,upd(1);
if (chk()) return 1;
int cnt = 0;
REP(i,1,n-k+1) {
int f = 0;
++clk, update(1,1,n,i,i+k-1,1), f += chk();
++clk, update(1,1,n,i,i+k-1,0), f += chk();
if (f==2) ++cnt;
}
return cnt==n-k+1?0:-1;
} int main() {
int t = work();
if (t==1) puts("tokitsukaze");
else if (t==-1) puts("once again");
else puts("quailty");
}

Tokitsukaze and Duel CodeForces - 1191E (博弈论)的更多相关文章

  1. E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)

    "Duel!" Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty ha ...

  2. [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)

    [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...

  3. Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取

    https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...

  4. Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. Codeforces 1190C. Tokitsukaze and Duel

    传送门 注意到后手可以模仿先手的操作,那么如果一回合之内没法决定胜负则一定 $\text{once again!}$ 考虑如何判断一回合内能否决定胜负 首先如果最左边和最右的 $0$ 或 $1$ 距离 ...

  6. Codeforces 1190C Tokitsukaze and Duel game

    题意:有一个长为n的01串,两个人轮流操作,每个人可以把某个长度为m的区间变成相同颜色,谁在操作后整个串颜色相同就赢了.问最后是谁赢?(有可能平局) 思路:容易发现,如果第一个人不能一击必胜,那么他就 ...

  7. C. Tokitsukaze and Duel 前缀维护

    枚举每一个连续的K的第一个位置,如果是先手胜利,那么前[1 , i-1 ]和[ i+k , n ]区间要么全是0,要么全是1 如果能够平局,那么肯定是[1,i-1],以及[ i+k , n]中有两种情 ...

  8. Financiers Game CodeForces - 737D (博弈论)

    直接暴力区间DP的话是$O(n^3)$, 关键注意到每步走的距离差不超过1, 所以差最大是$O(\sqrt{n})$的, 所以实际上有用的状态是$O(n^2)$的, 可以通过.

  9. Future Failure CodeForces - 838C (博弈论,子集卷积)

    大意: 两人轮流操作一个长$n$, 只含前$k$种小写字母的串, 每次操作删除一个字符或者将整个串重排, 每次操作后得到的串不能和之前出现过的串相同, 求多少种串能使先手必胜. 找下规律发现$n$为奇 ...

随机推荐

  1. 学号 20175313 《Android程序设计》实验报告

    目录 一.实验内容 (1)Android Stuidio的安装测试 (2)Activity测试 (3)UI测试 (4)布局测试 (5)事件处理测试 二.实验步骤 (1)Android Stuidio的 ...

  2. error storage size of my_addr isn't known

  3. matlab中x.^2与x^2有什么区别?

    .^2是矩阵中的每个元素都求平方,^2是求矩阵的平方或两个相同的矩阵相乘,因此要求矩阵为方阵,且看下面的例子x=1:4x = 1 2 3 4 x.^2 ans = 1 4 9 16 x^2 Error ...

  4. 一个读取C#特性Description方法(zhuan)

    class Program { static void Main(string[] args) { string str= DB.write.ToDescription(); Console.Writ ...

  5. python __new__

    1.__new__的作用是什么? 依照Python官方文档的说法,__new__方法主要是当你继承一些不可变的class时(比如int, str, tuple), 提供给你一个自定义这些类的实例化过程 ...

  6. springBoot注解搜集

    一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...

  7. connections java.net.BindException: Address already in use_解决方案

    一.问题描述 在Linux服务器(CentOS7系统)中配置并启动JMeter远程监控服务器资源所需的ServerAgent目录下的 startAgent.sh 文件时,系统出现异常提示,如 [roo ...

  8. 一百四十六:CMS系统之帖子按照发布时间和评论数量排序

    按照不同选项进行排序 视图 @bp.route('/')def index(): board_id = request.args.get('board_id', type=int, default=N ...

  9. 123457123456#1#-----com.threeapp.qianShuiTingYX01-----潜水艇跑酷游戏01

    com.threeapp.qianShuiTingYX01-----潜水艇跑酷游戏01

  10. $().attr() 和 $().css的区别

    使用jquery的.attr( )方法去给div隐藏,这样写的 $("#div_id").attr("display","none"),发现 ...