2019 Hang electrical multi-correction first hdu6579 Operation

Operation

Topic Portal

Problem-solving ideas

The number to the right as much as possible high discharge, based linear configuration when in position while recording its original sequence, may be inserted at that time if there is a position into a digital position is smaller than the new, old put into after the squeeze. Only ignore smaller than l, the position can be found by this linear configuration prefix group, a prefix and a maximum seek time.

code show as below

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

inline int read(){
    int res = 0, w = 0; char ch = 0;
    while(!isdigit(ch)){
        w |= ch == '-', ch = getchar();
    }
    while(isdigit(ch)){
        res = (res << 3) + (res << 1) + (ch ^ 48);
        ch = getchar();
    }
    return w ? -res : res;
}

const int N = 1000005;

int a[N];
int b[N][40], pos[N][40];

void insert(int k, int x)
{
    for(int i = 30; i >= 0; i --){
        b[k][i] = b[k - 1][i];
        pos[k][i] = pos[k - 1][i];
    }
    int t = k;
    for(int i = 30; i >= 0; i --){
        if((x >> i) & 1){
            if(b[t][i]){
                if(pos[t][i] < k){
                    swap(b[t][i], x);
                    swap(pos[t][i], k);
                }
                x ^= b[t][i];
            }
            else {
                b[t][i] = x;
                pos[t][i] = k;
                break;
            }
        }
    }
}

int query(int l, int r)
{
    int ans = 0;
    for(int i = 30; i >= 0; i --){
        if(pos[r][i] >= l){
            if((ans ^ b[r][i]) > ans)
                ans ^= b[r][i];
        }
    }
    return ans;
}

int main()
{
    int T;
    cin >> T;
    while(T --){
        int n, m;
        n = read(), m = read();
        for(int i = 1; i <= n; i ++){
            a[i] = read();
            insert(i, a[i]);
        }  
        int last = 0;
        for(int i = 1; i <= m; i ++){
            int opt;
            opt = read();
            if(opt == 0){
                int l, r;
                l = read(), r = read();
                l = (l ^ last) % n + 1;
                r = (r ^ last) % n + 1;
                if(l > r)
                    swap(l, r);
                last = query(l, r);
                printf("%d\n", last);
            }
            else {
                int x = read();
                ++n;
                insert(n, x ^ last);
            }
        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/whisperlzw/p/11243293.html