当前位置:网站首页>"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;
}
边栏推荐
- On insect classes and objects
- awk工具
- C language ---getchar() and putchar()
- Applicable and inapplicable scenarios of mongodb series
- 计算两点之间的距离(二维、三维)
- Half search, character array definition, character array uses D11
- 三维向量的夹角
- 【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
- Ubuntu installation and configuration PostgreSQL (18.04)
- 2021-10-18 character array
猜你喜欢

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

windows版MySQL软件的安装与卸载

嵌入式virlog代码运行流程

网络远程访问的方式使用树莓派

character constants

基于PyTorch的生成对抗网络实战(7)——利用Pytorch搭建SGAN(Semi-Supervised GAN)生成手写数字并分类

Use performance to see what the browser is doing

33. Use rgbd camera for target detection and depth information output

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

Wechat applet magic bug - choose to replace the token instead of clearing the token, wx Getstoragesync will take the old token value instead of the new token value
随机推荐
DataGrip配置的连接迁移
VTK 圆柱体的生成与渲染
On insect classes and objects
Sed editor
Detailed sorting of HW blue team traceability process
ICML 2022 | LIMO: 一种快速生成靶向分子的新方法
Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them
A primary multithreaded server model
[hcsd application development training camp] one line of code second cloud evaluation article - experience from the experiment process
array
Use of wangeditor rich text editor
7.Consul服务注册与发现
Bug STL string
Basic type of typescript
Memory considerations under bug memory management
Lamp compilation and installation
shell脚本详细介绍(四)
7-2 a Fu the thief
MediaPipe手势(Hands)
Input text to automatically generate images. It's fun!