当前位置:网站首页>"Scoi2016" delicious problem solution
"Scoi2016" delicious problem solution
2022-06-26 13:58:00 【__ LazyCat__】
link :#2016. 「SCOI2016」 delicious - subject - LibreOJ (loj.ac)
The question : Given a sequence , Multiple query intervals [ l , r ] [l,r] [l,r] The number in a i + x a_{i}+x ai+x And b b b XOR maximum , Give out... Every time you ask b , x , l , r b,x,l,r b,x,l,r.
Answer key : If it doesn't come with this x , It's a persistent 01trie The naked question of , But add x after , It is difficult to judge a particular number by bits . But you can judge a range , Greedy from high to low . Each query if this bit gets and b Whether there is such a number in the reverse value , If it exists, take it like this , Or take it in reverse . At the same time, we need to add x The influence of . Judge whether there is a number in a value range of a certain interval , Obviously, the chairman tree can be maintained . Complexity O ( n l o g n l o g w ) O(nlog\ nlog\ w) O(nlog nlog w) ,w Value range .
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=2e5+5;
int a[maxn],n,m,b,x,l,r,mx;
int ls[maxn*20],rs[maxn*20],sum[maxn*20],rt[maxn],now;
void update(int u,int&v,int l,int r,int pos)
{
v=++now,ls[v]=ls[u],rs[v]=rs[u],sum[v]=sum[u]+1;
if(l==r)return;
int mid=l+r>>1;
if(pos<=mid)update(ls[u],ls[v],l,mid,pos);
else update(rs[u],rs[v],mid+1,r,pos);
return;
}
int query(int u,int v,int l,int r,int ql,int qr)
{
if(ql<=l&&r<=qr)return sum[v]-sum[u];
int mid=l+r>>1,res=0;
if(ql<=mid)res+=query(ls[u],ls[v],l,mid,ql,qr);
if(mid<qr)res+=query(rs[u],rs[v],mid+1,r,ql,qr);
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>m; mx=2e5;
for(int i=1;i<=n;i++)
{
cin>>a[i],update(rt[i-1],rt[i],1,mx,a[i]);
}
for(int i=1;i<=m;i++)
{
cin>>b>>x>>l>>r;
int ans=0,res=0;
for(int j=17;j>=0;j--)
{
int p=(b>>j&1)^1;
if(query(rt[l-1],rt[r],1,mx,res+p*(1<<j)-x,res+(1+p)*(1<<j)-1-x))
{
ans+=1<<j,res+=p*(1<<j);
}
else res+=(p^1)*(1<<j);
}
cout<<ans<<"\n";
}
return 0;
}
边栏推荐
- 【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
- Applicable and inapplicable scenarios of mongodb series
- Global variable vs local variable
- KITTI Detection dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
- Create your own cross domain proxy server
- d检查类型是指针
- 7.Consul服务注册与发现
- 计算两点之间的距离(二维、三维)
- Postman自动化接口测试
- CVPR 2022文档图像分析与识别相关论文26篇汇集简介
猜你喜欢

Cloudcompare - Poisson reconstruction

A must for programmers, an artifact utools that can improve your work efficiency n times

Wechat applet -picker component is repackaged and the disabled attribute is added -- below

Input text to automatically generate images. It's fun!

Self created notes (unique in the whole network, continuously updated)

使用 Performance 看看浏览器在做什么

NVM installation tutorial

7.consul service registration and discovery

古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資

嵌入式virlog代码运行流程
随机推荐
【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
李航老师新作《机器学习方法》上市了!附购买链接
Taishan Office Technology Lecture: four cases of using bold font
Bigint: handles large numbers (integers of any length)
shell脚本详细介绍(四)
MongoDB系列之Window环境部署配置
A few lines of code can realize complex excel import and export. This tool class is really powerful!
D中不用GC
三维向量的夹角
Exercises under insect STL string
虫子 类和对象 中
I met the problem of concurrent programming in an interview: how to safely interrupt a running thread
Reprint - easy to use wechat applet UI component library
Postman自动化接口测试
A collection of common tools for making we media videos
虫子 STL string 下 练习题
Basic type of typescript
古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
GO语言-管道channel
证券开户安全吗,有没有什么危险啊