4103: [Thu Summer Camp 2015] xor time limit: Sec Memory Limit: MB
Submit: 359 Solved: 188
[Submit] [Status] [Discuss] Description
Given a sequence of length n x={x1,x2,..., xn} and a sequence of length M y={y1,y2,..., ym}, the value of row J of column I in matrix A aij=xi xor YJ, each query given a rectangular area i∈[u,d],j∈[l,r], to find the AIJ of the K-large.
Input
The first line contains two positive integer n,m, representing the length of the two series
The second line contains n non-negative integer XI the third row contains m non-negative integers YJ The fourth line contains a positive integer p, which indicates the number of queries followed by P-line, each line contains 5 positive integers, used to describe a query, each line contains five positive integer u,d,l,r,k, meaning title said. Output
A total of P lines, each containing a non-negative integer, indicating the answer to this inquiry.
Sample Input3 3
1 2 4
7 6 5
3
1 2 1) 2 2
1 2 1) 3 4
2 3 2) 3 4Sample Output6
5
1HINT
For 100% of data, 0<=xi,yj<2^31,
1<=u<=d<=n<=1000,
1<=l<=r<=m<=300000,
1<=k<= (d-u+1) * (r-l+1),
1<=p<=500
Source
Acknowledgement anonymous Upload
Trie Tree for Sustainability
It is found that the range of N and M is very wide, so n can be violently enumerated, M is used to extract the interval of trie tree with persistence.
The topic requires a array of interval number and B array interval of the number of different or k large value, consider from high to low greedy, every time as far as possible to choose 1, otherwise choose 0.
So from high to low enumeration each bit, ask a array of each element corresponds to the size of the node in the Trie tree, and then determine whether this bit can fill 1.
Note: The trie tree that corresponds to each number of a array is saved separately.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath > #include <algorithm> #define F (I,j,n) for (int. i=j;i<=n;i++) #define D (i,j,n) for (int i=j;i>=n;i--) # Define ll long long#define N 1005#define M 300005using namespace Std;int n,m,q,cnt,x_1,x_2,y_1,y_2,k;int a[n],b[m];int sz[ M*35],c[m*35][2],rt[m];struct data{int x, y;} P[n];inline int read () {int X=0,f=1;char ch=getchar (); while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();} while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} void Insert (int x,int &y,int val,int tmp) {y=++cnt;sz[y]=sz[x]+1;c[y][0]=c[x][0];c[y][1]=c[x][1];if (tmp==-1) Return;int t= (val>>tmp) &1;insert (c[x][t],c[y][t],val,tmp-1);} int solve (int k,int tmp) {if (tmp==-1) return 0;int sum=0; F (i,x_1,x_2) {int t= (A[I]>>TMP) &1;sum+=sz[c[p[i].y][t^1]]-sz[c[p[i].x][t^1]];} if (sum>=k) {F (i,x_1,x_2) {int t= (a[i]>>tmp) &1;p[i].x=c[p[i].x][t^1];p [i].y=c[p[i].Y][T^1];} return solve (k,tmp-1) + (1<<tmp);} Else{f (i,x_1,x_2) {int t= (a[i]>>tmp) &1;p[i].x=c[p[i].x][t];p [i].y=c[p[i].y][t];} return solve (k-sum,tmp-1);}} int main () {n=read (); M=read (); F (I,1,n) a[i]=read (); F (i,1,m) b[i]=read (); F (i,1,m) Insert (rt[i-1],rt[i],b[i],30); Q=read (); while (q--) {x_1=read (); X_2=read (); Y_1=read (); Y_2=read (); K=read () ; F (i,x_1,x_2) p[i].x=rt[y_1-1],p[i].y=rt[y_2];p rintf ("%d\n", Solve (k,30));}}
bzoj4103 "THUSC2015" XOR operation