1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" using namespace std; #define MAXN 1000006
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; #define P 418254373 const double eps = 8e-10; int n , m; int A[MAXN];
int b[MAXN][31] , p[MAXN][31];
void ins( int ps , int x , int idx ) { for( int i = 29 ; i >= 0 ; -- i ) if( x & ( 1 << i ) ) { if( !b[ps][i] ) { b[ps][i] = x , p[ps][i] = idx; return; } if( p[ps][i] < idx ) swap( idx , p[ps][i] ) , swap( x , b[ps][i] ); x ^= b[ps][i]; } }
int que( int l , int r ) { int ret = 0; for( int i = 29 ; i >= 0 ; -- i ) if( ( ~ret & ( 1 << i ) ) && b[r][i] && p[r][i] >= l ) ret ^= b[r][i]; return ret; }
void solve() { cin >> n >> m; rep( i , 1 , n ) { scanf("%d",A + i); memcpy( b[i] , b[i - 1] , sizeof b[i] ); memcpy( p[i] , p[i - 1] , sizeof p[i] ); ins( i , A[i] , i ); } int op , l , r , x , last = 0; rep( i , 1 , m ) { scanf("%d",&op); if( op == 0 ) { scanf("%d%d",&l,&r); l = ( l ^ last ) % n + 1 , r = ( r ^ last ) % n + 1; if( l > r ) l ^= r ^= l ^= r; printf("%d\n",last = que( l , r ) ); } else { scanf("%d",&x); x ^= last; ++ n; memcpy( b[n] , b[n - 1] , sizeof b[n] ); memcpy( p[n] , p[n - 1] , sizeof p[n] ); ins( n , x , n ); } } }
signed main() {
int T;cin >> T;while( T-- ) solve();
}
|