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.原因,工作队列被占用,只需 ...
随机推荐
- (转)当margin-top、padding-top的值为百分比时是如何计算的?
本文链接:https://blog.csdn.net/qq_27437967/article/details/72625900问题:当margin-top.padding-top的值是百分比时,分别是 ...
- Laravel-admin 表单提交同时验证俩个以上的字段唯一值
$name = isset(request()->all()['name']) ? request()->all()['name'] : ''; $id = isset(request() ...
- 如何在LinuxKernel中操作file(set_fs與get_fs)
在Kernel 中,照理說能存取至 0 ~ 4GB.但是實作層面卻是只能讓我們使用到3GB ~ 4GB 這會導致我們無法使用open(),write()這些在user space下的function. ...
- centos7 上pip install mysqlclient的时候报错OSError: mysql_config not found,
yum install mysql-devel gcc gcc-devel python-devel
- RPC框架调用过程详解
RPC框架调用过程详解 2017年09月16日 21:14:08 荷叶清泉 阅读数 6275 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. ...
- 108、如何使用 Secret? (Swarm15)
参考https://www.cnblogs.com/CloudMan6/p/8068057.html 我们经常要想容器传递敏感信息,最常见的就是密码.比如: docker run -e MYS ...
- 梳理common-io工具包
title: 梳理common-io工具包 comments: false date: 2019-08-28 14:21:58 description: 对common-io工具包中的常用类进行整理, ...
- H5的video标签在网页上播放MP4视频时只有声音没有画面
最近做一个项目时,发现mp4文件播放时没有图像,只有声音,代码检查了N次,都没有问题,就算是直接使用网上的实例代码,也只能播放实例视频,mp4文件绝对路径,相对路径也都试了,还是不能播放我的mp4. ...
- IIS7发布asp.net mvc提示404
之前服务器用的都是2003Server的服务器,发布mvc项目都没问题,今天换了一台机器,系统为Windows Server2008 R2 64位的发布mvc项目后就提示: 百度看到好多人说在web ...
- MySQL字段值按照拼音首字母排序
最简单.快速的方法: 将需要进行排序的字段编码设置为GBK,然后在查询时直接使用asc/desc就可以啦