传送门.

位运算的比较基本的题。

考虑枚举\(i\),然后二进制位从大到小考虑, 对于第\(w\)位,如果\(a[i][w]=1\),那么对\(j、k\)并没有什么限制。

如果\(a[i][w]=0\),那么我们希望\((a[j]~and~a[k])[w]=1\),结合前面的限制,就是给定\(x\),问有没有\(x∈a[j]~and~a[k](i<j<k)\)。

那么这应该是做一个高维后缀max和次max就能解决的事。

Code:


#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x; i <= y; i ++)
#define ff(i, x, y) for(int i = x; i < y; i ++)
#define fd(i, x, y) for(int i = x; i >= y; i --)
#define pp printf
#define ll long long
using namespace std; const int N = 1e6 + 10; int n, a[N]; const int M = 1 << 21; int f[M], g[M]; void add(int x, int i) {
if(x > f[i]) {
g[i] = f[i];
f[i] = x;
} else
if(x > g[i]){
g[i] = x;
}
} const int inf = 1e9; int main() {
scanf("%d", &n);
fo(i, 1, n) {
scanf("%d", &a[i]);
add(i, a[i]);
}
fo(i, 0, 20) {
ff(j, 0, 1 << 21) {
if(!(j >> i & 1)) {
add(f[j + (1 << i)], j);
add(g[j + (1 << i)], j);
}
}
}
ff(j, 0, 1 << 21) {
if(f[j] != g[j]) {
f[j] = g[j];
} else {
f[j] = 0;
}
}
int ans = 0;
fo(i, 1, n - 2) {
int x = 0;
fd(j, 20, 0) {
if(!(a[i] >> j & 1)) {
x += 1 << j;
if(g[x] <= i) {
x -= 1 << j;
}
}
}
ans = max(ans, x | a[i]);
}
pp("%d", ans);
}

Codeforces F. Bits And Pieces(位运算)的更多相关文章

  1. Codeforces 1208F Bits And Pieces 位运算 + 贪心 + dp

    题意:给你一个序列a, 问a[i] ^ (a[j] & a[k])的最大值,其中i < j < k. 思路:我们考虑对于每个a[i]求出它的最优解.因为是异或运算,所以我们从高位向 ...

  2. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) F. Bits And Pieces sosdp

    F. Bits And Pieces 题面 You are given an array

  3. F. Anton and School 位运算 + 化简

    http://codeforces.com/contest/734/problem/F 因为 x + y = (x & y) + (x | y) 有了这个公式后,然后应该手动模拟一下,把公式化 ...

  4. Codeforces 1208F - Bits And Pieces(高维前缀和)

    题面传送门 题意:求 \(\max\limits_{i<j<k}a_i|(a_j\&a_k)\). \(1\leq n \leq 10^6,1\leq a_i\leq 2\time ...

  5. CodeForces 165E Compatible Numbers(位运算 + 好题)

    wo integers x and y are compatible, if the result of their bitwise "AND" equals zero, that ...

  6. CF1208F Bits And Pieces

    CF1208F Bits And Pieces 传送门 思路 这里要运用SOS-DP的思路(\(\text{Sum over Subsets}\)).我在另外一篇博客里介绍过,如有需要可以搜索一下我的 ...

  7. leetcode - 位运算题目汇总(下)

    接上文leetcode - 位运算题目汇总(上),继续来切leetcode中Bit Manipulation下的题目. Bitwise AND of Numbers Range 给出一个范围,[m, ...

  8. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  9. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

随机推荐

  1. 1.MVC的初步了解

    1.MVC简单介绍 1)原理(如图)如果想更加深入了解原理,可以访问此地址(https://www.cnblogs.com/uicodeintoworld/p/8950877.html) 理解:客户端 ...

  2. linux编译php

    ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/loc ...

  3. linux下svn安装、配置及钩子

    一.安装 直接运行命令用YUM安装: yum install subversion -y   二.创建svn版本库目录 mkdir -p /var/svn/svnrepos   三.创建版本库 生成文 ...

  4. AcWing 231. 天码 (容斥)打卡

    题目:https://www.acwing.com/problem/content/233/ 题意:给你n个不同的数,让你选取一个四元组,gcd为1,让你求这样的四元组数量是多少 思路:我们单独直接去 ...

  5. [CSP-S模拟测试51]题解

    错失人生中第一次AK的机会…… A.attack 支配树板子题.考场上发明成功√ 首先支配树上两点路径之间的点都是必经之点,根据这个性质我们就可以yy出建树的方法.跑拓扑,在每个点(设为$x$)即将入 ...

  6. 【Java架构:基础技术】一篇文章搞掂:Linux

    基于CentOS 一.安装[暂略] 二.使用和登录[赞略] 三.使用yum CentOS自带yum,这里暂时不介绍安装方式 四.使用yum安装JDK 1.检查系统是否有安装open-jdk rpm - ...

  7. ThinkPHP5使用jwt进行会话验证

    以往,没有做过前后端分离的项目之前,都是服务器渲染的模板,然后用cookie和session进行账号的权限验证或者是登录状态的管理.后来接触了vue和小程序之后,在进行前后端分离的时候,就会遇到权限验 ...

  8. GDB can't continue if no space left

    [root@premta ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 36G 36G 0 100% /tmpfs 1.5G ...

  9. datetime中strptime用法

    import datetime day20 = datetime.datetime.strptime('2020-01-01 0:0:0', '%Y-%m-%d %H:%M:%S')nowdate = ...

  10. GCD 与XOR

    题目:UVA12716 题意:  问 gcd(i,j) = i ^ j  的对数(j <=i <= N ) N的范围为30000000,有10000组样例 分析: 有几个结论:(1)若 a ...