2019 Multi-University Training Contest 1 1002 Linear yl

The meaning of problems: 1. the end of the sequence of operations required addend 2. XOR maximum interval.

 

Seeking a maximum value of the exclusive OR section easily think of doing a linear group

When the match test block segment tree and to maintain a linear group, the results are the TLE

Before also thought to maintain suffix linear base, but do not know how to deal with the interval, did not think the position of the linear appearance of Jili Wei care

Positive solution should be to maintain a linear base for each suffix, each insert elements when they are location-right number appears in the highest choice, when queried as long as the current position appears so far to the right l on behalf of the interval can generate this number

#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)  
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))  
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x)  
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x)  
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long  
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second 
typedef vector<int> VI;
int read(){int x = 0,f = 1;char c = getchar();while (c<'0' || c>'9'){if (c == '-') f = -1;c = getchar();}
while (c >= '0'&&c <= '9'){x = x * 10 + c - '0';c = getchar();}return x*f;}
const double PI = acos(-1.0);
const double eps = 1e-9;
const int maxn = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7; 
int N,M,K;
struct xj{
    int a[32],pos[32];
    inline void init(){
        for(int i = 0; i <= 30; i ++) a[i] = pos[i] = 0;
    }
    inline void add(int x,int p){
        for(int i = 30; i >= 0 ; i --){
            if(!(x & (1 << i))) continue;
            if(!a[i]){
                a[i] = x; pos[i] = p;
                break;
            }else{
                if(p > pos[i])swap(a[i],x),swap(p,pos[i]);
                x ^= a[i];
            }
        }
    }
    inline int getmax(int l){
        int ans = 0;
        for(int i = 30; i >= 0; i --){
            if(pos[i] < l) continue;
            if(ans < (ans ^ a[i])) ans ^= a[i];
        }
        return ans;
    }
}pre[maxn];
int main(){
    int T; Sca(T);
    while(T--){
        Sca2(N,M);
        for(int i = 1; i <= N ; i ++){
            int x = read();
            pre[i] = pre[i - 1];
            pre[i].add(x,i);
        }
        int ans = 0;
        while(M--){
            int op = read();
            if(!op){
                int l = read() ^ ans,r = read() ^ ans;
                l = l % N + 1; r = r % N + 1;
                if(l > r) swap(l,r);
                ans = pre[r].getmax(l);
                Pri(ans);
            }else{
                int x = read() ^ ans;
                N++;
                pre[N] = pre[N - 1];
                pre[N].add(x,N);
            }
        }
    } 
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Hugh-Locke/p/11231897.html