题目传送门

  传送门I

  传送门II

  传送门III

题目大意

  给定将$\left \{ 0, 1, \dots, m - 1\right \}$分成了不相交的两个非空集合$A$和$B$,给定$A$,问存在多少个整数$x$满足$0\leqslant x < m$且对于任意$a\in A, b \in B$满足$a + b\not \equiv x \pmod{m}$

  容易发现满足后一个条件的充分必要条件是对于任意$a \in A$,存在$a' \in A$使得$a + a' \equiv x \pmod{m}$。

  如果$a \leqslant x$,则易证$a' \leqslant x$。

  同样,如果$a > x$,则易证$a' > x$。

  所以这个数$x$将序列分成两部分,每一部分首尾配对后,每一对的和都等于$x$。

  那么怎么判断呢?我们发现$a + d = c + b$等价于$a - b = c - d$。

  所以我们只用差分一下判断是否是回文,再判断首尾的和是否等于$x$就行了。

Code

 /**
* Codeforces
* Problem#1045B
* Accepted
* Time: 77ms
* Memory: 7300k
*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
using namespace std;
typedef bool boolean; #define ull unsigned long long const int N = 2e5 + ;
const ull base = 1e9 + ; int n, M;
int ar[N];
int cr[N];
ull ph[N], sh[N], pb[N]; int add(int a, int b) {
return ((a += b) >= M) ? (a - M) : (a);
} inline void init() {
scanf("%d%d", &n, &M);
for (int i = ; i <= n; i++)
scanf("%d", ar + i);
} ull fquery(int l, int r) { // forward
if (l > r)
return ;
return ph[r] - ph[l - ] * pb[r - l + ];
} ull rquery(int l, int r) { // backward
if (l > r)
return ;
return sh[l] - sh[r + ] * pb[r - l + ];
} boolean ispar(int l, int r) {
return fquery(l, r) == rquery(l, r);
} vector<int> vec; inline void solve() {
ph[] = , sh[n] = , pb[] = ;
for (int i = ; i < n; i++)
ph[i] = ph[i - ] * base + (cr[i] = ar[i + ] - ar[i]);
for (int i = n - ; i; i--)
sh[i] = sh[i + ] * base + cr[i];
for (int i = ; i < n; i++)
pb[i] = pb[i - ] * base; for (int i = , x; i < n; i++) {
x = ar[] + ar[i];
// if (x >= M)
// break;
if (add(ar[i + ], ar[n]) == x && ispar(, i - ) && ispar(i + , n - ))
vec.push_back(x);
}
int x = add(ar[], ar[n]);
if ((x <= ar[] || x >= ar[n]) && ispar(, n - ))
vec.push_back(x);
printf("%d\n", (signed) vec.size());
sort(vec.begin(), vec.end());
for (int i = ; i < (signed) vec.size(); i++)
printf("%d ", vec[i]);
putchar('\n');
} int main() {
init();
solve();
return ;
}

Codeforces 1045B Space Isaac - 数论 - Hash的更多相关文章

  1. Codeforces 1045B Space Isaac

    Space Isaac 我们定义第一个集合为a, 第二个集合为b 先把a数组排序, 然后我们会以线段的形式得到b集合. 我们先用a[ 1 ]去和 b 中的元素结合, 只有size(a) 个数字未被覆盖 ...

  2. luogu2312 解方程 (数论,hash)

    luogu2312 解方程 (数论,hash) 第一次外出学习讲过的题目,然后被讲课人的一番话惊呆了. 这个题,我想着当年全国只有十几个满分.....然后他又说了句我考场A这道题时,用了5个模数 确实 ...

  3. [CodeForces - 1225C]p-binary 【数论】【二进制】

    [CodeForces - 1225C]p-binary [数论][二进制] 标签: 题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory limit 5 ...

  4. Codeforces Gym 100463B Music Mess Hash 逻辑题

    Music Mess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments ...

  5. CodeForces 1056E - Check Transcription - [字符串hash]

    题目链接:https://codeforces.com/problemset/problem/1056/E One of Arkady's friends works at a huge radio ...

  6. codeforces 633C. Spy Syndrome 2 hash

    题目链接 C. Spy Syndrome 2 time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  7. CodeForces - 615D Multipliers(数论)

    http://codeforces.com/problemset/problem/615/D 题意 给出m个质因子,组成一个数n.问n的约数的乘积是多少,输出mod 1e+7的结果. 分析 从输入我们 ...

  8. Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论

    n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...

  9. [CodeForces - 447A] A - DZY Loves Hash

    A - DZY Loves Hash DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert ...

随机推荐

  1. Timeline Storyteller 现已加入自定义图表库

    前言 下载地址: https://store.office.com/en-us/app.aspx?assetid=WA104381136&sourcecorrid=328f5e2b-e973- ...

  2. 2017-2018 ACM-ICPC Latin American Regional Programming Contest GYM101889

    挺有意思的一套题,题也没有啥毒瘤了,本来是队切的结果种种原因大家全挂机了. 只补了百人题,一共7个,其他的暂时先不补了,,也不会嘛qwq H:签到 #include <bits/stdc++.h ...

  3. laravel之路由

    laravel之路由设置 代码如下: 访问就是: 代码附上: <?php /*|--------------------------------------------------------- ...

  4. Java 中的泛型

    泛型的一般意义: 泛型,又叫 参数多态或者类型参数多态.在强类型的编程语言中普遍作用是:加强编译时的类型安全(类型检查),以及减少类型转换的次数. Java 中的 泛型: 编译时进行 类型擦除 生成与 ...

  5. c++ __declspec

    dllimport 和dllexport 用__declspec(dllexport),__declspec(dllimport)显式的定义dll接口给调用它的exe或dll文件,用 dllexpor ...

  6. swust oj 956

    约瑟夫问题的实现 2000(ms) 65535(kb) 3266 / 10775 n个人围成一个圈,每个人分别标注为1.2.....n,要求从1号从1开始报数 ,报到k的人出圈,接着下一个人又从1开始 ...

  7. RDLC报表刷新问题

    使用RDLC做报表,当数据源发生改变时重新绑定数据发现报表没有变化,跟踪时发现数据绑定已经正确执行,前端也显示了加载过程,但内容未刷新. 在代码中使用了 ReportViewer1.LocalRepo ...

  8. Mastering MariaDB 神秘的MariaDB 中文翻译版

    是某群的哥们义务翻译的,宣传一下,还没时间时间读,粗滤看了全部翻译完了300多页佩服 https://github.com/CMant/Mastering-MariaDB- 原地址:如果你需要读,请s ...

  9. [Day15]常用API(Object类、String类)

    1.Java的API(API: Application(应用) Programming(程序) Interface(接口)) Java API是JDK中提供使用的类,类已经将底层代码进行封装 在JDK ...

  10. [math] sagemath

    官网首页:http://www.sagemath.org 首页里引出的两个教程 http://www.gregorybard.com/Sage.html http://sagebook.gforge. ...