题意

给你一个长度为\(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. sort algorithms

    //todo #include<iostream> void swap(int *a, int *b){int temp = *a; *a = *b; *b = temp;} ; i &l ...

  2. 【原创】大数据基础之Mesos+Marathon+Docker部署nginx

    一 安装 安装docker:https://www.cnblogs.com/barneywill/p/10343091.html安装mesos:https://www.cnblogs.com/barn ...

  3. php 常用的自定义函数

    1. 发送 SMS 在开发 Web 或者移动应用的时候,经常会遇到需要发送 SMS 给用户,或者因为登录原因,或者是为了发送信息.下面的 PHP 代码就实现了发送 SMS 的功能. 为了使用任何的语言 ...

  4. Hibernate Envers

    一.目的Hibernate Envers的目的是提供应用程序实体数据的历史版本,记录执行数据变更历史. 二.用途Hibernate Envers记录的审计数据,主要用于意外丢失数据找回.审查数据合法性 ...

  5. BeanPostProcessors (for example: not eligible for auto-proxying),报错解决

    最近遇到个问题,springmvc项目debug启动失败 debug启动会卡住不动,run模式启动正常 debug启动输出到下面这行之后,就不会继续输出了 -- :: [INFO]- Bean 'da ...

  6. 使用 Sonar 检测代码质量

    经历了一段时间的加班赶项目进度之后,今天终于闲下来了.忽然不知道干啥.于是,想着做点什么吧.突然想起了码云上面有个代码分析的功能,用的是 Sonar 于是想来玩玩这个. 一.下载Sonar,和初始化, ...

  7. node20180927

    1. fs读文件.写文件 // 1 fs读文件 var fs = require('fs') fs.readFile('./20180926 demo/a.text', function (err, ...

  8. php获取两个时间戳之间相隔多少天多少小时多少分多少秒

    /** * 返回两个时间的相距时间,*年*月*日*时*分*秒 * @param int $one_time 时间一 * @param int $two_time 时间二 * @param int $r ...

  9. js分析 汽_车_之_家 js生成css伪元素 hs_kw44_configUS::before

    0.参考 https://developer.mozilla.org/zh-CN/docs/Web/CSS/Pseudo-elements https://developer.mozilla.org/ ...

  10. Maven安装配置(Windows10)

    想要安装 Apache Maven 在Windows 系统上, 需要下载 Maven 的 zip 文件,并将其解压到你想安装的目录,并配置 Windows 环境变量. 所需工具 : JDK 1.8 M ...