HDU6579 Operation
问题分析
区间求异或和最大,比较自然的想到了线性基。而每次求一个区间的线性基显然是行不通的。我们考虑在每个位置求出首位置到当前位置的线性基。同时我们要使线性基中高位的位置所选的数尽量靠后。这样我们维护线性基的时候在同时维护一个位置信息就好了。
参考程序
#include <bits/stdc++.h>
//#define Debug
using namespace std;
const int Maxn = 1000010;
const int MaxBit = 30;
int n, m, A[ Maxn ], BitBase[ Maxn ][ MaxBit ], Pos[ Maxn ][ MaxBit ];
void Work();
int main() {
int TestCases;
scanf( "%d", &TestCases );
for( ; TestCases--; ) Work();
return 0;
}
void Work() {
scanf( "%d%d", &n, &m );
for( int i = 1; i <= n; ++i ) scanf( "%d", A + i );
memset( BitBase, 0, sizeof( BitBase ) );
memset( Pos, 0, sizeof( Pos ) );
for( int i = 1; i <= n; ++i ) {
for( int j = 0; j < MaxBit; ++j ) BitBase[ i ][ j ] = BitBase[ i - 1 ][ j ], Pos[ i ][ j ] = Pos[ i - 1 ][ j ];
int Position = i;
for( int j = MaxBit - 1; j >= 0; --j )
if( ( A[ i ] >> j ) & 1 )
if( BitBase[ i ][ j ] ) {
if( Pos[ i ][ j ] < Position ) {
swap( BitBase[ i ][ j ], A[ i ] );
swap( Pos[ i ][ j ], Position );
}
A[ i ] ^= BitBase[ i ][ j ];
} else {
BitBase[ i ][ j ] = A[ i ];
Pos[ i ][ j ] = Position;
break;
}
}
#ifdef Debug
for( int i = 1; i <= n; ++i ) {
for( int j = 0; j < MaxBit; ++j ) printf( "(%d,%d), ", BitBase[ i ][ j ], Pos[ i ][ j ] );
printf( "\n" );
}
#endif
int LastAns = 0;
for( int i = 1; i <= m; ++i ) {
int Opt; scanf( "%d", &Opt );
if( Opt == 1 ) {
++n; scanf( "%d", A + n );
A[ n ] ^= LastAns;
for( int j = 0; j < MaxBit; ++j ) BitBase[ n ][ j ] = BitBase[ n - 1 ][ j ], Pos[ n ][ j ] = Pos[ n - 1 ][ j ];
int Position = n;
for( int j = MaxBit - 1; j >= 0; --j )
if( ( A[ n ] >> j ) & 1 )
if( !BitBase[ n ][ j ] ) {
BitBase[ n ][ j ] = A[ n ];
Pos[ n ][ j ] = Position;
break;
} else {
if( Pos[ n ][ j ] < Position ) {
swap( BitBase[ n ][ j ], A[ n ] );
swap( Pos[ n ][ j ], Position );
}
A[ n ] ^= BitBase[ n ][ j ];
}
} else {
int l, r; scanf( "%d%d", &l, &r );
l = ( l ^ LastAns ) % n + 1;
r = ( r ^ LastAns ) % n + 1;
if( l > r ) swap( l, r );
LastAns = 0;
for( int j = MaxBit - 1; j >= 0; --j )
if( ( ( LastAns >> j ) & 1 ) == 0 && Pos[ r ][ j ] >= l )
LastAns ^= BitBase[ r ][ j ];
printf( "%d\n", LastAns );
}
}
return;
}
HDU6579 Operation的更多相关文章
- hdu-6579 Operation
题目链接 Operation Problem Description There is an integer sequence a of length n and there are two kind ...
- 2019杭电多校第一场hdu6579 Operation(线性基)
Operation 题目传送门 解题思路 把右边的数尽量往高位放,构造线性基的时候同时记录其在原序列中的位置,在可以插入的时候如果那个位置上存在的数字的位置比新放入的要小,就把旧的往后挤.用这种发现构 ...
- [2019杭电多校第一场][hdu6579]Operation(线性基)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6579 题目大意是两个操作,1个是求[l,r]区间子序列的最大异或和,另一个是在最后面添加一个数. 如果 ...
- 2019年杭电多校第一场 1002题Operation(HDU6579+线性基)
题目链接 传送门 题意 初始时有\(n\)个数,现在有\(q\)次操作: 查询\([l,r]\)内选择一些数使得异或和最大: 在末尾加入一个数. 题目强制在线. 思路 对于\(i\)我们记录\([1, ...
- 终端mysql Operation not permitted错误解决方案
前言 前段时间装mysql,就遇到了ln: /usr/bin/mysql: Operation not permitted的错误,网上好多方法都过时了,下边是我的解决方法 原因 这是因为苹果在OS X ...
- SVN:Previous operation has not finished; run 'cleanup' if it was interrupted
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...
- Mysql Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
MySQL字符串比较bug: select * from table_a a left join table_b b on a.field_a = b.field_b error: Illegal ...
- TNS-12535: TNS:operation timed out案例解析
一数据库突然连接不上,在自己电脑上使用SQL Developer也连接不上.立即使用SecureCRT连接上了这台服务器,从下面几个方面检查. 1:检查了数据库的状态是否正常 $ sqlplus / ...
- 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted
1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...
随机推荐
- DLL的创建与使用
一.动态链接库(DLL) 动态链接库提供了一种方法,使进程可以调用不属于其执行代码的函数.函数的可执行代码位于一个.dll文件中,该文件包含一个或多个已被编译.链接并使用它们的进程分开存储的函数. 优 ...
- 【NOIP2017】跳房子
这题我0分. 比赛时,我一眼出正解,哈哈,太水了! 这题不就是一个二分+DP+单调队列吗? 然而,细节决定成败. 我错了许多细节,就挂了. 我只考了0分... 首先,这题满足一个条件: 保证g变大后, ...
- ssh连接远程服务器出现Host key验证失败的解决方案
原因可能是云服务器重装过,解决方法是找到提示的know_hosts文件,将报错的那一行的秘钥删掉即可.
- spring boot jpa criteria api是如何生成JPQL的
当我们使用entityManager.createQuery(query)时,我们发现entityManager的注入对象如下: 也就是它:org.springframework.orm.jpa.Lo ...
- 虚拟机无法启动,提示:无法打开内核功能扩展“com.vmware.kext.vmci”: 无此文件或目录
打开 系统偏好设置->安全性与隐私->允许打开 即可
- ThinkPHP5框架缺陷导致远程命令执行(POC整合帖)
摘要 近日thinkphp团队发布了版本更新https://blog.thinkphp.cn/869075 ,其中修复了一处getshell漏洞. 影响范围 5.x < 5.1.31<= ...
- oracle重置dba用户密码
1.进入sqlplus里面: [oracle@master ~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Tue ...
- jQuery获取兄弟标签的文本
// 一个div里面有一个span标签和多个button标签,每个button标签都有id,span标签没有id,通过点击其中一个button标签,来获取到span标签的text function ( ...
- dedecms织梦网站本地迁移到服务器后,后台更新栏目文档提示模板文件不存在,无法解析文档!的解决办法
解决办法: 1.系统设置-系统基本参数-站点设置-网页主页链接,替换为空 2.系统设置-系统基本参数-核心设置-DedeCMS安装目录,替换为空
- ES数据架构与关系数据库Mysql
ES数据架构的主要概念(与关系数据库Mysql对比) MySQL ElasticSearch Database Index Table Type Row Document Column Field S ...