传送门.

位运算的比较基本的题。

考虑枚举\(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. 【leetcode】923. 3Sum With Multiplicity

    题目如下: Given an integer array A, and an integer target, return the number of tuples i, j, k  such tha ...

  2. Oracle with as语法

    with as优点 增加了sql的易读性,如果构造了多个子查询,结构会更清晰: 更重要的是:“一次分析,多次使用”,这也是为什么会提供性能的地方,达到了“少读”的目标 用法:给查询的语句起个别名 e. ...

  3. Mybatis基于XML配置SQL映射器(二)

    Mybatis之XML注解 之前已经讲到通过 mybatis-generator 生成mapper映射接口和相关的映射配置文件: 下面我们将详细的讲解具体内容 首先我们新建映射接口文档  sysUse ...

  4. nucleus学习

    task的TCB结构: typedef struct TC_TCB_STRUCT { /* Standard thread information first. This information is ...

  5. 探索Redis设计与实现8:连接底层与表面的数据结构robj

    本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...

  6. GIL - global interpreter lock

    python是一个解释型语言,但是可以使用多个解释器.比如C++,但是可以用不同的编译器来编译成可执行代码.有名的编译器例如GCC,INTEL C++,Visual C++等.Python也一样,同样 ...

  7. Centos7安装部署SonarQube7.9.1教程

    0.参考文档 LTS 7.9.1 新特性:https://www.sonarqube.org/sonarqube-7-9-lts/ JDK11 下载地址: 链接:https://pan.baidu.c ...

  8. windows下Mysql5.7表名不区分大小写问题

    前言 Windwos文件系统本身是不区分大小写的,但是Linux文件系统是支持大小写的.于是安装在Linux下的Mysql导出到windows下可能因为大小写问题导致错误,因此要开启window下My ...

  9. HTML5: HTML5 内联 SVG

    ylbtech-HTML5: HTML5 内联 SVG 1.返回顶部 1. HTML5 内联 SVG HTML5 支持内联 SVG. 什么是SVG? SVG 指可伸缩矢量图形 (Scalable Ve ...

  10. HTML5: HTML5 应用程序缓存

    ylbtech-HTML5: HTML5 应用程序缓存 1.返回顶部 1. HTML5 应用程序缓存 使用 HTML5,通过创建 cache manifest 文件,可以轻松地创建 web 应用的离线 ...