\(\mathcal{Description}\)

  OurOJ.

  给定序列 \(\{a_n\}\) 和一个二元运算 \(\operatorname{op}\in\{\operatorname{and},\operatorname{or},\operatorname{xor}\}\),对于 \(i\in[2,n]\),求出 \(\max_{j\in[1,i)}\{a_i\operatorname{op} a_j\}\) 以及 \(|\arg\max_{j\in[1,i)}\{a_i\operatorname{op} a_j\}|\)。

  \(n\le10^5\),\(a_i<2^{16}\)。

\(\mathcal{Solution}\)

  也许算是 Meet in Middle?从左到右在线更新可用的 \(a_j\) 信息并求出对于当前 \(i\) 的答案,维护一个 \(f(u,v)\),表示选取的 \(a_j\) 的高八位是 \(u\) 且 \(a_i\) 的低八位是 \(v\) 时,低八位能得到的最大值以及方案数。那么更新时,用当前 \(a_j\) 的低八位更新所有 \(f(u,i)\);查询时枚举高八位选择的值 \(i\),并用 \(f(i,v)\) 更新答案。最终复杂度为 \(\mathcal O(n\sqrt A)\)。

  确实是比较巧妙的复杂度平衡,也是一个实用的 trick√

\(\mathcal{Code}\)

/*~Rainybunny~*/

#include <bits/stdc++.h>

#define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i ) typedef std::pair<int, int> PII;
#define fi first
#define se second const int MAXN = 1e5, MAXSV = 1 << 8;
int n, a[MAXN + 5];
char op[5];
PII f[MAXSV][MAXSV]; inline void update( const int x, const auto& opt ) {
int h = x >> 8, l = x ^ h << 8;
rep ( i, 0, MAXSV - 1 ) {
int v = opt( i, l );
if ( f[h][i].fi < v ) f[h][i] = { v, 1 };
else if ( f[h][i].fi == v ) ++f[h][i].se;
}
} inline PII query( const int x, const auto& opt ) {
int l = x & ( ( 1 << 8 ) - 1 );
PII ret( 0, 0 );
rep ( h, 0, MAXSV - 1 ) if ( f[h][l].se ) {
int cur = opt( h, x >> 8 ) << 8 | f[h][l].fi;
if ( ret.fi < cur ) ret = { cur, f[h][l].se };
else if ( ret.fi == cur ) ret.se += f[h][l].se;
}
return ret;
} inline void solve( const auto& opt ) {
update( a[1], opt );
rep ( i, 2, n ) {
PII ans( query( a[i], opt ) );
printf( "%d %d\n", ans.fi, ans.se ), update( a[i], opt );
}
} int main() {
scanf( "%d %s", &n, op );
rep ( i, 1, n ) scanf( "%d", &a[i] );
if ( op[0] == 'x' ) {
solve( []( const int u, const int v ) { return u ^ v; } );
} else if ( op[0] == 'a' ) {
solve( []( const int u, const int v ) { return u & v; } );
} else {
solve( []( const int u, const int v ) { return u | v; } );
}
return 0;
}

Solution -「LOCAL」二进制的世界的更多相关文章

  1. Solution -「LOCAL」大括号树

    \(\mathcal{Description}\)   OurTeam & OurOJ.   给定一棵 \(n\) 个顶点的树,每个顶点标有字符 ( 或 ).将从 \(u\) 到 \(v\) ...

  2. Solution -「LOCAL」过河

    \(\mathcal{Description}\)   一段坐标轴 \([0,L]\),从 \(0\) 出发,每次可以 \(+a\) 或 \(-b\),但不能越出 \([0,L]\).求可达的整点数. ...

  3. Solution -「LOCAL」Drainage System

    \(\mathcal{Description}\)   合并果子,初始果子的权值在 \(1\sim n\) 之间,权值为 \(i\) 的有 \(a_i\) 个.每次可以挑 \(x\in[L,R]\) ...

  4. Solution -「LOCAL」Burning Flowers

      灼之花好评,条条生日快乐(假装现在 8.15)! \(\mathcal{Description}\)   给定一棵以 \(1\) 为根的树,第 \(i\) 个结点有颜色 \(c_i\) 和光亮值 ...

  5. Solution -「LOCAL」画画图

    \(\mathcal{Description}\)   OurTeam.   给定一棵 \(n\) 个点的树形随机的带边权树,求所有含奇数条边的路径中位数之和.树形生成方式为随机取不连通两点连边直到全 ...

  6. Solution -「LOCAL」ZB 平衡树

    \(\mathcal{Description}\)   OurOJ.   维护一列二元组 \((a,b)\),给定初始 \(n\) 个元素,接下来 \(m\) 次操作: 在某个位置插入一个二元组: 翻 ...

  7. Solution -「LOCAL」舟游

    \(\mathcal{Description}\)   \(n\) 中卡牌,每种三张.对于一次 \(m\) 连抽,前 \(m-1\) 次抽到第 \(i\) 种的概率是 \(p_i\),第 \(m\) ...

  8. Solution -「LOCAL」充电

    \(\mathcal{Description}\)   给定 \(n,m,p\),求序列 \(\{a_n\}\) 的数量,满足 \((\forall i\in[1,n])(a_i\in[1,m])\l ...

  9. Solution -「LOCAL」「cov. 牛客多校 2020 第五场 C」Easy

    \(\mathcal{Description}\)   Link.(完全一致)   给定 \(n,m,k\),对于两个长度为 \(k\) 的满足 \(\left(\sum_{i=0}^ka_i=n\r ...

随机推荐

  1. Shell 里空语句怎么写 - 半角的冒号

    Python 里的空语句写作pass for x in range(10): pass Shell 里的空语句写作 : #!/bin/bash for x in {1..10} do #echo $x ...

  2. 强化学习实战 | 自定义gym环境之显示字符串

    如果想用强化学习去实现扫雷.2048这种带有数字提示信息的游戏,自然是希望自定义 gym 环境时能把字符显示出来.上网查了很久,没有找到gym自带的图形工具Viewer可以显示字符串的信息,反而是通过 ...

  3. 微信小程序封装mixins方法

    在app.js中这样引入 import '@src/utils/mixins' mixins函数如下 /** * 封装类似vue的混入功能 */ let native = Page Page = (o ...

  4. synchronized学习笔记

    概述 我们都知道加锁的目的就是:序列化访问临界资源,即同一时刻只能有一个线程访问临界资源(同步互斥访问).在java对象中,每一个对象有且只有一个同步锁.这也意味着,同步锁依赖于对象而存在,当我们访问 ...

  5. Easticsearch概述(API使用)二

    Rest简介 一种软件架构风格,而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务端互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制 Rest的操作分为以 ...

  6. 个人作业2-6.4-Python爬取顶会信息

    1.个人作业2 数据爬取阶段 import requestsfrom lxml import etreeimport pymysqldef getdata(url): # 请求CVPR主页 page_ ...

  7. 【刷题-LeetCode】307. Range Sum Query - Mutable

    Range Sum Query - Mutable Given an integer array nums, find the sum of the elements between indices ...

  8. golang中的RPC开发-2

    RPC简介 远程过程调用(Remote Procedure Call,RPC)是一个计算机通信协议 该协议允许运行于一台计算机的程序调用另一台计算机的子程序,而程序员无需额外地为这个交互作用编程 如果 ...

  9. java-包概述

    1 package face_package; 2 3 import face_packagedemo.DemoA; 4 5 /* 包(package) 6 * 1,对类文件进行分类管理. 7 * 2 ...

  10. el表达式中的${param}用法

    el表达式中的${param}? 1. 2. ${param.name} 等价于 request.getParamter("name"),这两种方法一般用于服务器从页面或者客户端获 ...