传送门

自认为是一道思想很妙的题。


直接分析问题。

如果没有xxx的干扰直接上可持久化01trie01trie01trie走人。

但现在有了xxx这个偏移量。

相当于把整个01trie01trie01trie向左平移了xxx。

这个感觉01trie01trie01trie维护不是很可做。

于是我们把可持久化01trie01trie01trie转成主席树。

发现只是把选择左/右子树变成了选择左/右半区间。

然后照样贪心查询就行了。

代码:

#include<bits/stdc++.h>
#define N 200005
#define M 100005
#define P 17
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int rt[N],son[N*30][2],siz[N*30],n,m,a[N],tot=0;
inline void update(int&p,int las,int l,int r,int k){
	p=++tot,son[p][0]=son[las][0],son[p][1]=son[las][1],siz[p]=siz[las]+1;
	if(l==r)return;
	int mid=l+r>>1;
	if(k<=mid)update(son[p][0],son[las][0],l,mid,k);
	else update(son[p][1],son[las][1],mid+1,r,k);
}
inline int query(int pl,int pr,int l,int r,int ql,int qr){
	if(ql>r||qr<l)return 0;
	if(ql<=l&&r<=qr)return siz[pr]-siz[pl];
	int mid=l+r>>1;
	if(qr<=mid)return query(son[pl][0],son[pr][0],l,mid,ql,qr);
	if(ql>mid)return query(son[pl][1],son[pr][1],mid+1,r,ql,qr);
	return query(son[pl][0],son[pr][0],l,mid,ql,mid)+query(son[pl][1],son[pr][1],mid+1,r,mid+1,qr);
}
inline int query(int l,int r,int val,int dta){
	int ret=0,xortmp=0;
	for(int i=P;~i;--i){
		int tmp=1<<i;
		if(val&tmp)if(query(rt[l-1],rt[r],1,200000,xortmp-dta,xortmp+tmp-dta-1))ret|=tmp;else xortmp|=tmp;
		else if(query(rt[l-1],rt[r],1,200000,xortmp+tmp-dta,xortmp+tmp*2-dta-1))ret|=tmp,xortmp|=tmp;
	}
	return ret;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;++i)update(rt[i],rt[i-1],1,200000,(a[i]=read()));
	for(int i=1,b,x,l,r;i<=m;++i)b=read(),x=read(),l=read(),r=read(),printf("%d\n",query(l,r,b,x));
	return 0;
}

2018.10.14 bzoj4571: [Scoi2016]美味(主席树)的更多相关文章

  1. BZOJ4571:[SCOI2016]美味(主席树,贪心)

    Description 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1≤i≤n).有 m 位顾客,第 i 位顾客的期望值为 bi,而他的偏好值为 xi . 因此,第 ...

  2. 【BZOJ4571】[Scoi2016]美味 主席树

    [BZOJ4571][Scoi2016]美味 Description 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1≤i≤n).有 m 位顾客,第 i 位顾客的期望值 ...

  3. bzoj 4571: [Scoi2016]美味 (主席树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 题面; 4571: [Scoi2016]美味 Time Limit: 30 Sec   ...

  4. BZOJ.4571.[SCOI2016]美味(主席树 贪心)

    题目链接 要求 \(b\ xor\ (a_j+x)\) 最大,应让 \(a_j+x\) 的最高位尽可能与b相反.带个减法Trie树好像很难做?反正我不会. 从最高位开始,如果这位b是0/1,判断是否存 ...

  5. P3293 [SCOI2016]美味 主席树+按位贪心

    给定长度为 \(n\) 序列 \(a[i]\) ,每次询问区间 \([l,r]\) ,并给定 \(b,x\) 中的一个数 \(p=a[i]\) ,使得最大化 \(b \bigoplus p^x\) 主 ...

  6. 2018.10.31 bzoj3339&&3585mex(主席树)

    传送门 双倍经验 直接上主席树,每个叶节点维护这个值出现的最右区间,非叶子节点维护当前值域内所有最右区间的最小值. 查询的时候只用在以root[qr]root[qr]root[qr]为根的树上面二分. ...

  7. [SCOI2016]美味——主席树+按位贪心

    原题戳这里 题解 让异或值最大显然要按位贪心,然后我们还发现加上一个\(x_i\)的效果就是所有\(a_i\)整体向右偏移了,我们对于\({a_i}\)开个主席树,支持查询一个区间中有多少个在\([L ...

  8. BZOJ4517[Scoi2016]美味——主席树

    题目描述 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1≤i≤n).有 m 位顾客,第 i 位顾客的期 望值为 bi,而他的偏好值为 xi .因此,第 i 位顾客认为 ...

  9. bzoj4571/luogu3293 美味 (主席树+贪心)

    首先想到建出可持久化trie树然后在上面贪心,但是它加了一个数所以不能这么做 但依然可以贪心,仿照上面那个的过程,如果设y是在第i位上^b是1的数(前面的位数已经贪好了),我只要在[l,r]范围内能有 ...

随机推荐

  1. 可视化库-seaborn-布局风格设置(第五天)

    1. sns.set_style() 进行风格设置, sns.set() 进行设置的重置, 五种风格 # 1.darkgrid# 2.whitegrid# 3.dark# 4.white# 5 tic ...

  2. Spring MVC 视图及视图解析器

    org.springframework.web.servlet.view.InternalResoureceViewResolve 把逻辑视图改为物理视图 可混用多种视图 不进过Handler直接进入 ...

  3. vector实现(只能装入string)

    #include<iostream> #include<string> #include<memory> #include<utility> using ...

  4. JavaScript中有三个可以对字符串编码的函数,分别是: escape(),encodeURI(),encodeURIComponent()

    JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape,decodeURI,decod ...

  5. 八月(The Summer is Gone)观后感

    第一次看到这部电影时觉得很亲近,黑白画面,国企改革的背景,浓浓的儿时画面感,原谅我只是一个三十不到的人,可能我比较早熟,对八九十年代还有些记忆,更早以前也通过电视.音乐.书籍等了解过一些,而那些听过又 ...

  6. Apache Hive 执行HQL语句报错 ( 10G )

    # 故障描述: hive > , ) as uuid, count(distinct(request_body["uuid"])) as count from log_bft ...

  7. 吴裕雄 python 数据处理(2)

    import pandas as pd data = pd.read_csv("F:\\python3_pachongAndDatareduce\\data\\pandas data\\hz ...

  8. spark cache table

    http://www.07net01.com/2015/11/961118.html http://www.cnblogs.com/charlotte77/p/5468968.html 文本读入和写出 ...

  9. [Fiddler] The connection to 'xxxxx.com' failed. <br />System.Security.SecurityException Failed to negotiate HTTPS connection with server.fiddler.network.https&gt; HTTPS handshake to intelte

    最近利用模拟发get请求的时候出现: [Fiddler] The connection to ‘xxxxx.com' failed. <br />System.Security.Secur ...

  10. nodejs 与 json

    nodeJs读取文件(readfile) j json 处理: var fileData = fs.readFileSync(file);if (fileData) { var j = {}; cal ...