Codeforces 1045B Space Isaac
我们定义第一个集合为a, 第二个集合为b
先把a数组排序, 然后我们会以线段的形式得到b集合。
我们先用a[ 1 ]去和 b 中的元素结合, 只有size(a) 个数字未被覆盖, 我们从这些数组中选答案。
枚举这些数字, 什么情况下才它是答案呢, 就是移到a[ 2 ], a[ 3 ], a[ 4 ], 它都是未被覆盖的数组,
这个东西可以用hash值维护一下就能O(1)check啦。
#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define ull unsigned long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end() using namespace std; const int N = 4e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;} int n, m, a[N];
vector<PII> seg;
vector<int> vc;
vector<int> ans; ull HashVal; ull hs[N], Pow[N]; ull getHash(int L, int R) {
return hs[R] - hs[L - ] * Pow[R - L + ];
} int main() {
for(int i = Pow[] = ; i < N; i++) Pow[i] = Pow[i - ] * ;
scanf("%d%d", &n, &m);
if(n == || n == m) return puts(""), ;
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
sort(a + , a + + n);
a[n + ] = m;
a[] = -;
for(int i = ; i <= n; i++)
if(a[i] + < a[i + ])
seg.push_back(mk(a[i] + , a[i + ] - ));
seg.push_back(mk(-, -));
seg.push_back(mk(m, m));
sort(ALL(seg));
for(int i = ; i < SZ(seg) - ; i++)
for(int j = seg[i].se + ; j < seg[i + ].fi; j++)
vc.push_back((j + a[]) % m), vc.push_back((j + a[]) % m - m);
sort(ALL(vc));
for(int i = n - ; i >= ; i--) HashVal *= , HashVal += a[i + ] - a[i];
n--;
for(int i = ; i < SZ(vc); i++) hs[i] = hs[i - ] * + vc[i] - vc[i - ];
for(int i = SZ(vc) / ; i < SZ(vc); i++)
if(getHash(i - n + , i) == HashVal) ans.push_back(vc[i]);
printf("%d\n", SZ(ans));
for(auto& t : ans) printf("%d ", t);
if(SZ(ans))puts("");
return ;
} /*
*/
Codeforces 1045B Space Isaac的更多相关文章
- Codeforces 1045B Space Isaac - 数论 - Hash
题目传送门 传送门I 传送门II 传送门III 题目大意 给定将$\left \{ 0, 1, \dots, m - 1\right \}$分成了不相交的两个非空集合$A$和$B$,给定$A$,问存在 ...
- codeforces1045B Space Isaac 【manacher】【差分】
题目大意: 题目是将$[0,m)$的数划成了两个集合,其中一个集合的元素个数不超过$n$.问在第一个集合中选出的数加上第二个集合中选出的数的和中没有出现的数有哪些. 题目分析: 很有意思的一道题.方便 ...
- CF1045B Space Isaac(乱搞)
翻译 有0~m-1的数被分成了两个集合每次你可以从两个集合中任取一个数做加法并对m取模问最后0~m-1中不能被组合出来的数有多少个会给出你A集合 大小不超过200000m<=1e9 完了题解都看 ...
- CF1045B Space Isaac
原题链接 DOWNLOAD AS PDF 题目大意 \(0\sim m-1\)的数被分成两个集合,你可以分别从两个集合中取一个数相加并对\(m\)取模,求一不能构造出的数. 题解 感觉如果\(\col ...
- Noip前的大抱佛脚----赛前任务
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...
- 【做题】CF1045(ABH)
原文链接https://www.cnblogs.com/cly-none/p/9697662.html 题目当然不会做完了,这里只讲有做&会做的. A. Last chance 题意:有\(n ...
- codeforce1046 Bubble Cup 11 - Finals 题解
比赛的时候开G开了3h结果rose说一句那唯一一个AC的是羊的心态就崩了.. 这套题感觉质量挺好然后就back了下 A: AI robots 有三个限制条件:相互能够看见和智商的差.使用主席树,可以维 ...
- Bubble Cup 11 - Finals [Online Mirror, Div. 1]题解 【待补】
Bubble Cup 11 - Finals [Online Mirror, Div. 1] 一场很好玩的题啊! I. Palindrome Pairs 枚举哪种字符出现奇数次. G. AI robo ...
- Codeforces Gym 100803D Space Golf 物理题
Space Golf 题目连接: http://codeforces.com/gym/100803/attachments Description You surely have never hear ...
随机推荐
- ES--04
第三十一讲! 分布式文档系统 写一致性原理以及相关参数 课程大纲 (1)consistency,one(primary shard),all(all shard),quorum(default) 我们 ...
- OpenSIPS 1.11.1安装记录
说明:操作系统Centos 6.5 64位 安装步骤: 1.安装依赖包 : yum -y install gcc make gdb wget yum -y install flex bison nc ...
- 10)django-ORM(创建,字段类型,字段参数)
一:ORM关系对象映射(Object Relational Mapping,简称ORM) ORM分两种: DB first 先在数据库中创建数据库表等 Code first 先创建类,然后根据类创建数 ...
- liunx contos 7.4 安装redis集群
前前后后安装了几次redis集群,基本上每次安装都会采坑,耗时伤神. 安装redis依赖gcc环境,安装前先检查liunx上面有没有安装GCC 命令:gcc -v 上传redis-4.0.1.tar. ...
- swift 学习- 27 -- 访问控制
// 访问控制 可以限定其源文件 或模块中的代码对你的代码的访问级别, 这个特性可以让我们隐藏代码的一些实现细节, 并且可以为其他人可以访问和使用的代码提供接口 // 你可以明确地给某个类型 (类, ...
- Confluence 6 MySQL 输入你的数据库细节
Confluence 的安装向导将会指导你一步一步的在 Confluence 中配置安装 MySQL 数据库. 使用 JDBC 连接(默认) JDBC 是推荐的连接你的 Confluence 到数据库 ...
- AFN 请求报 415错误解决方案
使用 AFHTTPSessionManager 发起请求时 设置下面两句代码 manager.requestSerializer = [AFJSONRequestSerializer seriali ...
- OSError: cannot identify image file
OSError: cannot identify image file <_io.BytesIO object at 0x00000236DD598BF8> 说一下为什么会出现OSErro ...
- excel生成数据
Sub function1()Dim i As LongFor i = 1 To 1000000Cells(i, 1) = "A" & iCells(i, 2) = &qu ...
- 微信小程序 如何获取用户code
1.首先需要获取code 使用 wx.login({ success: function(res) { console.log(res);//这里的返回值里面便包含code }, fail: func ...