题目传送门

  传送门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. python2.7环境下的flask项目导入模块失败解决办法

    如下一个flask项目的目录: 这个flask项目在python3.6环境下可以正常启动,但是在python2.7环境下如下报错提示: 提醒模块找不到.如下解决方法: 只需要在views目录里面加一个 ...

  2. 进程池原理及效率测试Pool

    为什么会有进程池的概念? 当我们开启50个进程让他们都将100这个数减1次减到50,你会发现特别慢! 效率问题,原因: 1,开辟内存空间.因为每开启一个进程,都会开启一个属于这个进程池的内存空间,因为 ...

  3. 多线程之批量插入小demo

    多线程之批量插入 背景 昨天在测试mysql的两种批量更新时,由于需要入库大量测试数据,反复执行插入脚本,过程繁琐,档次很低,测试完后我就想着写个批量插入的小demo,然后又想写个多线程的批量插入的d ...

  4. HTML5语音合成Speech Synthesis API简介

    by zhangxinxu from http://www.zhangxinxu.com/wordpress/?p=5865本文可全文转载,但需得到原作者书面许可,同时保留原作者和出处,摘要引流则随意 ...

  5. spring管理的类如何调用非spring管理的类

    spring管理的类如何调用非spring管理的类. 就是使用一个spring提供的感知概念,在容器启动的时候,注入上下文即可. 下面是一个工具类. import org.springframewor ...

  6. python扫描端口脚本

    # -*- coding:utf8 -*- # # Python: 2.7.8 # Platform: Windows # Authro: wucl # Program: 端口扫描 # History ...

  7. C语言中tm结构体

    struct tm { int tm_sec; /* Seconds. [0-60] (1 leap second) */ int tm_min; /* Minutes. [0-59] */ int ...

  8. Oracle 11g R2创建数据库之手工建库方式

    在之前的博文当中梳理了关于DBCA静默方式创建数据库的过程,本文就手工通过SQL*PLUS客户端采用CREATE DATABASE语句创建数据库.这种建库方式就是完全使用手工SQL语句创建数据库,通常 ...

  9. 抓取html 生成图片

      <!DOCTYPE html>   <html>   <head>   <script type="text/javascript" ...

  10. Angela启动步骤

    1.在web目录下执行 grunt watch (如果不在目录下执行不能识别,当然首先安装node.js) 2.随便改一个文件,会自动重新生成代码(在dest目录下会生成可执行的代码) 3.如果有de ...