当前位置:网站首页>"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;
}
边栏推荐
- Aesthetic experience (episode 238) Luo Guozheng
- I met the problem of concurrent programming in an interview: how to safely interrupt a running thread
- 7-2 the cubic root of a number
- Gurivat sprint Harbour Exchange listed: created “multiple first”, received 900 million yuan Investment from IDG capital
- Wechat applet SetData dynamic variable value sorting
- D中不用GC
- Half search, character array definition, character array uses D11
- A collection of common tools for making we media videos
- 去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
- Global variable vs local variable
猜你喜欢

33、使用RGBD相机进行目标检测和深度信息输出

Design of simple digital circuit traffic light

ES中索引别名(alias)的到底有什么用

计算两点之间的距离(二维、三维)

shell脚本详细介绍(四)

2021-10-18 character array

Detailed introduction to shell script (4)

三维向量的夹角

Hands on data analysis unit 3 model building and evaluation

Calculate the distance between two points (2D, 3D)
随机推荐
Network remote access using raspberry pie
Here document interaction free and expect automatic interaction
Common operation and Principle Exploration of stream
DataGrip配置的连接迁移
Svn commit error after deleting files locally
Is it safe to open a securities account? Is there any danger
Original code, inverse code and complement code
A few lines of code can realize complex excel import and export. This tool class is really powerful!
Generate JDE dot train
ES基于Snapshot(快照)的数据备份和还原
Insect operator overloaded a fun
ICML 2022 | limo: a new method for rapid generation of targeted molecules
awk工具
Included angle of 3D vector
KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
Lamp compilation and installation
三维向量的夹角
D check type is pointer
Introduction to 26 papers related to CVPR 2022 document image analysis and recognition
HW蓝队溯源流程详细整理