Test instructions
Give a array of length n, and a b array of length m;
Existing one matrix A[i][j]=a[i] xor b[j];
The K-value of a piece of a matrix in Q-time;
n<=1000,m<=300000,q<=500,a[i],b[i]<2^31;
Exercises
is another K-value problem, but obviously it is not possible to list the matrix to evaluate the value;
But the range of N and Q is a little weird = =;
So consider a range of 1-n for each questioning violence enumeration;
And then, to these numbers to find the big K value;
If the query is the maximum value, then on the persistence of trie greedy on it;
K Large value Similarly, record a size indicating that there are several numbers in the subtree;
Then look at the relationship between the size of the subtree and the K what, this step and the Chairman tree is actually similar;
And here are n trees, then put the N-Tree a start ...
And the chair with the Repair tree (tree array set of Chairman tree?) ) implementation is the same;
Time complexity O (31*M+31*QN);
It's kind of stupid to feel the problem, but I just didn't think of it.
Must be thought by some k short-circuit misled;
Code:
#include <queue> #include <stdio.h> #include <string.h> #include <algorithm> #define N 1100# Define M 310000using namespace std;struct trie{trie *next[2];int Size;trie ();} *null=new trie (), *root[m],*nol[n],*nor[n];trie::trie () {next[0]=next[1]=null;size=0;} int a[n];void init () {null->next[0]=null->next[1]=null;for (int i=0;i<m;i++) Root[i]=null;} void Insert (Trie *&no,int x,int d) {trie *p=new trie (); *p=*no;no=p;p->size++;if (d==-1) return; Insert (p->next [!! (1<<d&x)],x,d-1);} int query (int u,int d,int k,int deep) {if (deep==-1) return 0;int upp=0;bool index,flag;for (int i=u;i<=d;i++) {index=! ( 1<<deep&a[i]); upp+=nor[i]->next[index]->size-nol[i]->next[index]->size;} Flag= (K<=upp); for (int i=u;i<=d;i++) {index= (!! (1<<deep&a[i])) ^flag;nol[i]=nol[i]->next[index];nor[i]=nor[i]->next[index];} Return Flag<<deep|query (u,d,k-(!flag) *upp,deep-1);} int main () {init (); int n,m,q,c,i,j,k,x,y,u,d,l,r,ans;scanf ("%d%d", &n, &m), for (i=1;i<=n;i++) scanf ("%d", a+i), and for (i=1;i<=m;i++) {scanf ("%d", &x); Root[i]=root[i-1];insert ( ROOT[I],X,31);} scanf ("%d", &q), for (c=1;c<=q;c++) {scanf ("%d%d%d%d%d", &u,&d,&l,&r,&k); for (I=u;i<=d ; i++) Nol[i]=root[l-1],nor[i]=root[r];ans=query (u,d,k,31);p rintf ("%d\n", ans); return 0;}
bzoj-4103 XOR operation