题意

给你一个长度为\(n\)的序列和一个数\(m\)。

小A和小B分别在\([1,m]\)选出一个数\(a\)和\(b\),然后开始游戏。

轮到小A时,他选择一个元素减\(a\);小B则选择一个元素减\(b\)。

不能将元素变成负数。

问对于所有\(m \times m\)对\((a,b)\),分别有多少对是小A/B必胜,先/后手必胜。

$ n \leq 100,m \leq 100000 $,序列元素 $ \leq 10^{18} $

思路

首先易知,原序列与原序列\(mod \space a+b\)后得到的结果是一样的,且A必胜与B必胜的情况种类是一样的,所以不妨假设\(a \leq b\)

先取模,然后对后来的序列进行讨论

判断条件1 \(d\)个数\(\geq 2a\) \(c\)个数\(\geq b\) 判断条件4 情况
$ \exists i$ 使\(a \leq x_i <b\) A
\(d \geq2\) A
\(c=0\)
\(c \text{ mod } 2=1\)
\(d=1\) A
\(d=0\)

一个大的分类讨论

枚举\(a+b\),每次\(O(n \space log n)\)计数,总复杂度\(O(2nm \space log n)\)

#include <bits/stdc++.h>
using std::sort;
using std::min;
using std::max;
int n,m,b[105];
long long a[105],cnt1,cnt2;
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
for (int i=2;i<=2*m;i++){
for (int j=1;j<=n;j++) b[j]=a[j]%i;
sort(b+1,b+n+1);
b[n+1]=m;
if (~i&1){
int t1=0;
for (int j=1;j<=n;j++) if (b[j]>=i/2) t1=t1^1;
if (t1) cnt2++;
}
for (int j=1;j<=n+1;j++){
int l=max(b[j-1]+1,i/2+1),r=min(min(i-1,m),b[j]);
if (r<l) continue;
int al=max(b[j-1],b[n-1]/2),bl=max(l,i-al);
if (bl<=r) cnt1+=r-bl+1,r=bl-1;
if (r<l) continue;
if ((n-j+1)&1) cnt2+=(r-l+1)*2;
else{
al=b[n-1]/2+1;int ar=b[n]/2;
bl=max(l,i-ar);int br=min(r,i-al);
if (br>=bl) cnt1+=br-bl+1;
}
}
}
printf("%lld %lld %lld %lld",cnt1,cnt1,cnt2,1ll*m*m-cnt1-cnt1-cnt2);
}

后记

ZJOI2019 kcz讲解了此题,但是写起来还是有点晕,ZJOI开心地爆了

CF1033G Chip Game的更多相关文章

  1. p_b_p_b 杂题选讲

    [ARC119F] AtCoder Express 3 [ARC117F] Gateau 考虑二分答案,对前缀和建差分约束 \(\text{check}\) ,但是用 \(\text{spfa}\) ...

  2. a chip multiprocessor

    COMPUTER OR GANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION A multicore computer ...

  3. hdu5269 Chip Factory

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=5536 题目: Chip Factory Time Limit: 18000/9000 MS ( ...

  4. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  5. codeforces 590B B. Chip 'n Dale Rescue Rangers(二分+计算几何)

    题目链接: B. Chip 'n Dale Rescue Rangers time limit per test 1 second memory limit per test 256 megabyte ...

  6. Codeforces Round #327 (Div. 1) B. Chip 'n Dale Rescue Rangers 二分

    题目链接: 题目 B. Chip 'n Dale Rescue Rangers time limit per test:1 second memory limit per test:256 megab ...

  7. HDU 5536 Chip Factory 字典树

    Chip Factory Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  8. Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理

    D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

  9. Cheap CK100 1024 tokens NXP FIX Chip on Eobd2

    CK100 is a well-known and cost-effective key programmer for many cars. Some said it is a must for bo ...

随机推荐

  1. java基础学习总结——面向对象1

    目录 一.面向过程的思想和面向对象的思想 二.简单理解面向对象 三.面向对象的设计思想 四.对象和类的概念 五.如何抽象出一个类? 六.类(对象)之间的关系 七.Java与面向对象 八.为什么使用面向 ...

  2. github密钥

    官网英文资料:https://help.github.com/articles/connecting-to-github-with-ssh/ 1.生成SSH keys文件id_rsa.pub ssh- ...

  3. Spring 源码分析-1-启动

    Spring 源码分析-1-启动 在web项目中使用spring的时候,我们会在web.xml中加入如下配置: <listener> <listener-class>org.s ...

  4. angular 2+ 变化检测系列二(检测策略)

    我们将创建一个简单的MovieApp来显示有关一部电影的信息.这个应用程序将只包含两个组件:显示有关电影的信息的MovieComponent和包含执行某些操作按钮的电影引用的AppComponent. ...

  5. android setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds区别

    手工设置文本与图片相对位置时,常用到如下方法: setCompoundDrawables(left, top, right, bottom) setCompoundDrawablesWithIntri ...

  6. iOS之UIApplicatio、AppDelegate

    UIApplication,代表的是整个应用做的事,因此每个程序只能有一个,系统使用的是单例模式,就是[UIApplication sharedApplication]来得到一个实例. 这个单例实例是 ...

  7. C. Queen Codeforces Round #549 (Div. 2) (搜索)

    ---恢复内容开始--- You are given a rooted tree with vertices numerated from 11 to nn . A tree is a connect ...

  8. 什么是 B 树?

    本文提到的「B-树」,就是「B树」,都是 B-tree 的翻译,里面不是减号-,是连接符-.因为有人把 B-tree 翻成 「B-树」,让人以为「B树」和「B-树」是两种树,实际上两者就是同一种树. ...

  9. windows下安装 mysql 8.0 以上版本以及遇到的问题

    Windows 上安装 MySQL Windows 上安装 MySQL 相对来说会较为简单,地那就链接 https://cdn.mysql.com//Downloads/MySQL-8.0/mysql ...

  10. __x__(29)0908第五天__高度塌陷 问题

    高度塌陷 在文档流中,父元素的高度默认是被子元素撑开的. 但是当为 子元素 设置 float 时,子元素会完全脱离文档流,无法再撑开父元素,导致父元素高度塌陷...以致于布局混乱 变成 BFC块级格式 ...