大意: 给定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. 【译】Solr in Action 第二章

    2.1 2.2 2.3 基本废话 2.4 基本废话

  2. MySQL格式化时间date_format

    select date_format(deal_date, '%Y年%m月%d日 %H时%i分%s秒'), date_format(deal_date, '%Y-%m-%d %H:%i:%s') fr ...

  3. C#-片段-插入片段:测试

    ylbtech-C#-片段-插入片段:测试 using Microsoft.VisualStudio.TestTools.UnitTesting; 1.返回顶部 ·测试方法 [Microsoft.Vi ...

  4. python小白之np功能快速查

    np一些用法 np.a np.array([1,2,3],dtype=int)  #建立一个一维数组, np.array([[1,2,3],[2,3,4]])  #建立一个二维数组. np.arang ...

  5. osg 线程模型

    void ViewerBase::frame(double simulationTime) { if (_done) return; // OSG_NOTICE<<std::endl< ...

  6. CentOS设置交换分区swap

    环境查看 查看未设置交换分区之前 free -h 新加一块磁盘用于交换分区/dev/sdc 格式化 mkswap /dev/sdc 设置为交换分区 swapon /dev/sdc 再次查看 设置为重启 ...

  7. 讲不明白自杀系列:KMP算法

    算法:KMP排序 算法分析 KMP算法是一种快速的模式匹配算法.KMP是三位大师:D.E.Knuth.J.H.Morris和V.R.Pratt同时发现的,所以取首字母组成KMP. 少部分图片来自孤~影 ...

  8. iOS-代理设计模式delegate和protocol

    充当代理的步骤: 首先要明确谁请别人代理,谁当别人的代理 1> 请代理三部曲: 1 写一个协议protoc,把自己不方便做的事列出来(@protocol  studentDelegate < ...

  9. Docker Machine(十五)

    目录 一.Docker Machine 总览 1.Docker Engine VS Docker Machine 2.环境准备 二.安装 Docker Machine 1.Install Machin ...

  10. 【Kail 学习笔记】Dmitry信息收集工具

    DMitry(Deepmagic Information Gathering Tool)是一个一体化的信息收集工具.它可以用来收集以下信息: 根据IP(或域名)来查询目标主机的Whois信息 在Net ...