题目大意

对于一个整数序列 \(a_{0...5}\),我们定义它的价值为:

\(f(a)=max(|a_0-a_3|,|a_1-a_4|,|a_2-a_5|)\oplus a_0 \oplus a_1 \oplus a_2 \oplus a_3 \oplus a_4 \oplus a_5\)

其中 \(\oplus\) 是异或操作。

现在给定序列 \(b_{0...5}\),你需要求对于所有满足 \(\forall i,0\leq a_i\leq b_i\) 的序列 \(a\) 的 \(f(a)\) 之和。

由于答案可能很大,你只需要输出答案对 \(2^{64}\) 取模后的值。

对于所有数据,有 \(0\leq b_i\leq 30000\)

时间限制:3 s

空间限制:512 MB

解题思路

是个不太难的题,然而我不会最后一档分。

考场做法是 \(f_{i,j}\) 表示 \(\max\) 不大于 \(i\),\(6\) 个数的异或值为 \(j\) 的方案数。

转移前缀和优化一下,再用奇怪的技巧加个 fwt 就可以有 62pts 了。

考虑如何把都是 \(O(b^2)\) 的时空复杂度降下去,一个套路的做法是把异或值每一位拆开计算。

\(f_{i,j,0/1}\) 表示 \(\max\) 不大于 \(i\),第 \(j\) 位为 \(0/1\) 的方案数,对于每一对分开求,再用 \(f\) dp 就不难了。

那 \(f\) 怎么求 ? 想到差一定是可以卷积的 (将数组翻转),把每一组,每一位,每一种 \(0/1\) 情况分开卷。

接下来的 dp 就和之前的暴力 dp 差不多了。

#include <bits/stdc++.h>
using namespace std; const int B(30005), BIT(16); int b[6];
int f[3][BIT][B][2]; inline void read(int &x ){
x = 0; int f = 1, c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
x *= f;
} namespace prep{
const int mod(998244353), G(3), Gi(332748118);
int n;
int a[1 << 16], b[1 << 16], c[1 << 16], rev[1 << 16]; inline void MOD(int &x){ x = x + ((x >> 31) & mod); }
inline int qpow(int x, int a){
int sum = 1; while(a){
if(a & 1) sum = 1LL * sum * x % mod;
x = 1LL * x * x % mod, a >>= 1;
} return sum;
}
void init(int len){
n = 1; while(n < len) n <<= 1;
for(int i(0); i < n; ++i) rev[i] = (rev[i >> 1] >> 1) | (i & 1) * (n >> 1);
}
void NTT(int *a, int n, int op){
int g = op == 1 ? G : Gi, inv = qpow(n, mod - 2);
for(int i(0); i < n; ++i) if(i < rev[i]) swap(a[i], a[rev[i]]);
for(int len(2), hf(1); len <= n; len <<= 1, hf <<= 1){
int wn = qpow(g, (mod - 1) / len);
for(int bs(0); bs < n; bs += len){
int w = 1;
for(int p(0); p < hf; ++p, w = 1LL * w * wn % mod){
int x = a[bs + p], y = 1LL * w * a[bs + hf + p] % mod;
MOD(a[bs + p] = x + y - mod);
MOD(a[bs + hf + p] = x - y);
}
}
}
if(op == -1) for(int i(0); i < n; ++i) a[i] = 1LL * a[i] * inv % mod;
}
void work(int t, int bit, int la, int lb, int x, int y){
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
/* 将这一位符合枚举要求的取出来卷积 */
for(int i(0); i <= la; ++i) a[i] = ((i >> bit) & 1) == x;
for(int i(0); i <= lb; ++i) b[i] = ((i >> bit) & 1) == y;
/* 因为差是定值所以翻转一下 */
reverse(b, b + lb + 1);
init(la + lb + 2);
NTT(a, n, 1), NTT(b, n, 1);
for(int i(0); i < n; ++i) c[i] = 1LL * a[i] * b[i] % mod;
NTT(c, n, -1);
for(int i(0); i <= la; ++i) MOD(f[t][bit][i][x ^ y] += c[i + lb] - mod);
for(int i(0); i <= lb; ++i) MOD(f[t][bit][lb - i][x ^ y] += c[i] - mod);
}
void calc(int t, int bit, int la, int lb){
for(int x(0); x <= 1; ++x)
for(int y(0); y <= 1; ++y)
work(t, bit, la, lb, x, y);
/* 两数相等的时候算重了一次 */
f[t][bit][0][0] = 1LL * f[t][bit][0][0] * qpow(2, mod - 2) % mod;
f[t][bit][0][1] = 1LL * f[t][bit][0][1] * qpow(2, mod - 2) % mod;
}
}
namespace DP{
#define ULL unsigned long long
ULL ans, pre[4][B][2], dp[4][B][2];
void solve(int bit){
memset(dp, 0, sizeof(dp));
memset(pre, 0, sizeof(dp));
for(int t(1); t <= 3; ++t)
for(int i(0); i < B; ++i)
for(int j(0); j <= 1; ++j)
pre[t][i][j] = f[t - 1][bit][i][j] + (i ? pre[t][i - 1][j] : 0);
for(int j(0); j < B; ++j) dp[0][j][0] = 1;
for(int i(1); i <= 3; ++i)
for(int j(0); j < B; ++j){
for(int x(0); x <= 1; ++x)
for(int y(0); y <= 1; ++y)
dp[i][j][x ^ y] += dp[i - 1][j][x] * pre[i][j][y];
}
for(int i(B - 1); i; --i)
for(int j(0); j <= 1; ++j)
dp[3][i][j] -= dp[3][i - 1][j];
for(int i(0); i < B; ++i) for(int j(0); j <= 1; ++j)
if(((i >> bit) & 1) ^ j) ans += dp[3][i][j] * (1ULL << bit);
}
} int main(){
// freopen("C.in", "r", stdin);
// freopen("C.out", "w", stdout);
for(int i(0); i < 6; ++i) read(b[i]);
for(int i(0); i < 16; ++i)
for(int j(0); j < 3; ++j)
prep :: calc(j, i, b[j], b[j + 3]);
for(int i(0); i < 16; ++i) DP :: solve(i);
cout << DP :: ans << endl;
return 0;
}

[题解] XOR Problem的更多相关文章

  1. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  2. 2014 百度之星 1003 题解 Xor Sum

    Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheu ...

  3. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

  4. 【CF1174D】 Ehab and the Expected XOR Problem - 构造

    题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...

  5. cf1088D Ehab and another another xor problem (构造)

    题意:有两数a,b,每次你可以给定c,d询问a xor c和b xor d的大小关系,最多询问62次($a,b<=2^{30}$),问a和b 考虑从高位往低位做,正在做第i位,已经知道了a和b的 ...

  6. CF D. Ehab and the Expected XOR Problem 贪心+位运算

    题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...

  7. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)

    参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...

  8. Codeforces.1088D.Ehab and another another xor problem(交互 思路)

    题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...

  9. cf1088D. Ehab and another another xor problem(思维)

    题意 题目链接 系统中有两个数\((a, b)\),请使用\(62\)以内次询问来确定出\((a, b)\) 每次可以询问两个数\((c, d)\) 若\(a \oplus c > b \opl ...

随机推荐

  1. 在Spring框架中如何更有效地使用JDBC?

    使用SpringJDBC 框架,资源管理和错误处理的代价都会被减轻.所以开发者只需写statements 和 queries从数据存取数据,JDBC也可以在Spring框架提供的模板类的帮助下更有效地 ...

  2. Springmvc入门基础(六) ---拦截器应用demo

    1.拦截器定义 Spring Web MVC 的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理. 2.拦截器demo demo需求: 拦截用户请求,判断用 ...

  3. mapper.xml文件中标签没有提示的解决

    1.首先我们来看看mapper.xml的头文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTY ...

  4. 浏览器视图层级中的“根”:<html>和<body>的属性研究

    做前端开发的同学都会知道,每一个UI系统(比如IOS或Android)中都会有一个view hierarchy(视图层级)的概念,即所有的可视元素(大到一个页面,小到一个button)都在一个树形结构 ...

  5. HTML5与类有关的扩充

    对于传统HTML而言,HTML5是一个叛逆.所有之前的版本对JavaScript接口的描述都不过三言两语,主要篇幅都用于定义标记,与JavaScript相关的内容一概交由DOM规范去定义. 而HTML ...

  6. C#复杂XML反序列化为实体对象两种方式

    前言 今天主要讲的是如何把通过接口获取到的Xml数据转换成(反序列化)我们想要的实体对象,当然Xml反序列化和Json反序列化的方式基本上都是大同小异.都是我们事先定义好对应的对应的Xml实体模型,不 ...

  7. leetcode-剑指 Offer II 012. 左右两边子数组的和相等

    题目描述: 给你一个整数数组 nums ,请计算数组的 中心下标 . 数组 中心下标 是数组的一个下标,其左侧所有元素相加的和等于右侧所有元素相加的和. 如果中心下标位于数组最左端,那么左侧数之和视为 ...

  8. java中接口interface可以持有多个类的共享常量

    3.接口持有多个类的共享常量  接口另一主要功能,马克-to-win: 可以使用接口来引入多个类的共享常量.所有的这些变量名都将作为常量看待.所有定义在接口中的常量都默认为public.static和 ...

  9. java如何读取和遍历properties文件

    在java项目开发过程中,使用properties文件作为配置基本上是必不可少的,很多如系统配置信息,文件上传配置信息等等都是以这种方式进行保存.同时学会操作properties文件也是java基础. ...

  10. in a frame because it set 'X-Frame-Options' to 'sameorigin'

    不是所有网站都给  iframe嵌套的,  有的网站设置了  禁止嵌套!!! 浏览器会依据X-Frame-Options的值来控制iframe框架的页面是否允许加载显示出来, 看你们公司这么设置了!! ...