题目大意:

给定长度为n的数列X={x1,x2,...,xn}和长度为m的数列Y={y1,y2,...,ym},令矩阵A中第i行第j列的值\(A_{ij} = x_i \text{ xor } y_j\)每次询问给定矩形区域\(i \in [u,d],j \in [l,r]\)找出第k大的\(A_{ij}\).

题解:

中午会宿舍的时候看了一眼题面hhhhhhhh.

瞄了一眼300000的数据范围就走了hhhhhhhh.

一中午想了快1h就是没做出来hhhhhhhhh.

直到下午来了机房看到了n<=1000 hhhhhh.

维护n颗可持久化01Trie暴力查询即可

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const int maxn = 1024;
const int maxm = 300010;
struct Node{
Node *ch[2];
int siz;
}*null,*root[maxm];
Node mem[maxm*40],*it;
inline void init(){
it = mem;null = it++;
null->ch[0] = null->ch[1] = null;
null->siz = 0;root[0] = null;
}
inline Node* insert(Node *rt,int x,int d){
Node *p = it++;*p = *rt;p->siz ++ ;
if(d == -1) return p;
int id = (x >> d)&1;
p->ch[id] = insert(p->ch[id],x,d-1);
return p;
}
int cnt;
Node *lnw[maxn],*rnw[maxn];int val[maxn];
int kth(int k,int d){
if(d == -1) return 0;
int tmp = 0;
for(int i=1,id;i<=cnt;++i){
id = (val[i] >> d) & 1;
tmp += rnw[i]->ch[id^1]->siz - lnw[i]->ch[id^1]->siz;
}
if(k <= tmp){
for(int i=1,id;i<=cnt;++i){
id = (val[i] >> d) & 1;
lnw[i] = lnw[i]->ch[id^1];
rnw[i] = rnw[i]->ch[id^1];
}return (1<<d) | kth(k,d-1);
}else{
for(int i=1,id;i<=cnt;++i){
id = (val[i] >> d) & 1;
lnw[i] = lnw[i]->ch[id];
rnw[i] = rnw[i]->ch[id];
}return kth(k - tmp,d-1);
}
}
int a[maxn],b[maxm];
int main(){
init();
int n,m;read(n);read(m);
for(int i=1;i<=n;++i) read(a[i]);
for(int i=1;i<=m;++i){
read(b[i]);
root[i] = insert(root[i-1],b[i],30);
}
int q;read(q);
while(q--){
int u,d,l,r,k;read(u);read(d);
read(l);read(r);read(k);
cnt = 0;
for(int i=u;i<=d;++i){
lnw[++cnt] = root[l-1];
rnw[cnt] = root[r];
val[cnt] = a[i];
}
printf("%d\n",kth(k,30));
}
getchar();getchar();
return 0;
}

bzoj 4103: 异或运算 可持久化Trie的更多相关文章

  1. BZOJ 4103: [Thu Summer Camp 2015]异或运算 可持久化trie

    开始想了一个二分+可持久化trie验证,比正解多一个 log 仔细思考,你发现你可以直接按位枚举,然后在可持久化 trie 上二分就好了. code: #include <bits/stdc++ ...

  2. [BZOJ4103][Thu Summer Camp 2015]异或运算 可持久化Trie树

    4103: [Thu Summer Camp 2015]异或运算 Time Limit: 20 Sec  Memory Limit: 512 MB Description 给定长度为n的数列X={x1 ...

  3. BZOJ 3689: 异或之 可持久化trie+堆

    和超级钢琴几乎是同一道题吧... code: #include <bits/stdc++.h> #define N 200006 #define ll long long #define ...

  4. 【bzoj4103】[Thu Summer Camp 2015]异或运算 可持久化trie树

    Description 给定长度为n的数列X={x1,x2,...,xn}和长度为m的数列Y={y1,y2,...,ym},令矩阵A中第i行第j列的值Aij=xi xor yj,每次询问给定矩形区域i ...

  5. BZOJ 3261: 最大异或和( 可持久化trie )

    搞成前缀和然后就可以很方便地用可持久化trie维护了.时间复杂度O((N+M)*25) -------------------------------------------------------- ...

  6. BZOJ 3261 最大异或和 可持久化Trie树

    题目大意:给定一个序列,提供下列操作: 1.在数组结尾插入一个数 2.给定l,r,x,求一个l<=p<=r,使x^a[p]^a[p+1]^...^a[n]最大 首先我们能够维护前缀和 然后 ...

  7. [十二省联考2019]异或粽子——可持久化trie树+堆

    题目链接: [十二省联考2019]异或粽子 求前$k$大异或区间,可以发现$k$比较小,我们考虑找出每个区间. 为了快速得到一个区间的异或和,将原序列做前缀异或和. 对于每个点作为右端点时,我们维护出 ...

  8. 洛谷.5283.[十二省联考2019]异或粽子(可持久化Trie 堆)

    LOJ 洛谷 考场上都拍上了,8:50才发现我读错了题=-= 两天都读错题...醉惹... \(Solution1\) 先求一遍前缀异或和. 假设左端点是\(i\),那么我们要在\([i,n]\)中找 ...

  9. bzoj3261: 最大异或和 可持久化trie

    题意:给定一个非负整数序列{a},初始长度为N. 有M个操作,有以下两种操作类型: 1.Ax:添加操作,表示在序列末尾添加一个数x,序列的长度N+1. 2.Qlrx:询问操作,你需要找到一个位置p,满 ...

随机推荐

  1. I2C驱动详解

    I2C讲解: 在JZ2440开发板上,I2C是由两条数据线构成的SCL,SDA:SCL作为时钟总线,SDA作为数据总线:两条线上可挂载I2C设备,如:AT24C08 两条线连接ARM9 I2C控制器, ...

  2. IOS ARC内存管理,提高效率避免内存泄露

    本文转载至 http://blog.csdn.net/allison162004/article/details/38756263 Cocoa内存管理机制 (1)当你使用new.alloc.copy方 ...

  3. javascript修改图片链接地址

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  4. 合理的布局,绚丽的样式,谈谈Winform程序的界面设计

    转载,不错的学习文章 阅读后,起初不太明白,试验了几次后明白了dev的强大.从事Winform开发很多年了,由于项目的需要,设计过各种各样的界面效果.一般来说,运用传统的界面控件元素,合理设计布局,能 ...

  5. Webpack探索【4】--- entry和output详解

    本文主要讲entry和output相关内容.

  6. ORM性能相关

    model: 先给一个简单的表结构 from django.db import models class User(models.Model): username=models.CharField(m ...

  7. [转载]设计模式的UML图

    1.抽象工厂(Abstract Factory)模式 意图:为特定的客户(或情况)提供特定系列的对象. 2.类的适配器(Adapter)模式 意图:将一个类的接口转换成客户希望的另外一个接口. 3.对 ...

  8. 关于 IN UPDATE TASK

    [转 http://blog.sina.com.cn/s/blog_6f74e6d50100sq57.html]更新程序必须用一个特殊的FM(update module)来实现. 1.Exportin ...

  9. Apache Shiro 使用手册(一)Shiro架构介绍(转发:http://kdboy.iteye.com/blog/1154644#bc2399255)

    一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户“登录”: 授权 - 访问控制: 密码加密 ...

  10. spring 注解事务

    前提:在applicationContext.xml中配置<tx:annotation-driven transaction-manager="transactionManager&q ...