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.原因,工作队列被占用,只需 ...
随机推荐
- spring配置文件拆分策略及方法
一.拆分策略 如果一个开发人员负责一个模块,我们采用公用配置(包括数据源.事务等)+每个系统模块一个单独配置文件(包括Dao.Service.Web控制器)的形式 如果是按照分层进行的分工,我们采用公 ...
- win10 远程桌面ubuntu16
一. 软件安装 1.1. 打开终端,安装xrdp,vncserver sudo apt-get install xrdp vnc4server xbase-clients 1.2. desktop s ...
- Centos8 重启网卡方法
问题情况: 1.虚机centos8 修改为静态ip后,由于网卡网段变更,无法上网 2.最小化安装,没有ifconfig 3.firewalld,selinux关闭 4.ping 不通物理机 根本原因: ...
- C++练习 | 基于栈的中缀算术表达式求值(double类型
#include<iostream> #include<stack> #include<cmath> using namespace std; char ch; b ...
- JavaScript Let 和 Const
来源:菜鸟教程:https://www.runoob.com/js/js-let-const.html JavaScript let 和 const ECMAScript 2015(ECMAScrip ...
- layui2.5 修改layuicms
雷哥layui2.5版本学习 学习地址: https://www.bilibili.com/video/av59813890/?p=30 注意: 修改layuicms时注意下面是缓存的js, < ...
- Python中的xrld模块
一. 什么是xrld模块 python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库. 二. 使用介绍 . empty(空的), number, ...
- ProGuard 最全混淆规则说明
Input/Output Options 输入输出选项 -include filename 递归引入目录的配置文件 -basedirectory directoryname -injars class ...
- 打不开Call Hierarchy和History的解决方法
Eclipse打不开Call Hierarchy和History的解决方法 工作中一直使用Eclipse,之前都好好的,最近突然出了问题. 一开始是发现按Ctrl+Alt+H打不开Call Hie ...
- golang(3):strings和strconv使用 & 时间和日期类型 & 指针类型 & 流程控制 & 函数
strings和strconv使用 . strings.HasPrefix(s string, prefix string) bool: // 判断字符串s是否以prefix开头 . . string ...