洛谷 P8773 [蓝桥杯 2022 省 A] 选数异或 做题记录

前置芝士:无?

思路

搜线段树的 tag 找到了一道非线段树题(
因为 是可逆的,即我们既可以 ab=c 同时也有 ac=b
那么这启示我们,一个数 a 可以匹配的数一定为 ax
我们用 lst 记录每一个元素最后出现的位置,设 fi 为右端点为 i,左端点的最大值,使得这个区间内有一对数他们的异或和为 x
那么,根据我们上面写的,我们知道了 fi=max(fi1,lsta[i]x)
时间复杂度:O(nlogn+m)
难点/坑点: 无

点击查看代码
#include<bits/stdc++.h>

#define ll long long
#define i128 __int128

#define mem(a,b) memset((a),(b),sizeof(a))
#define m0(a) memset((a),0,sizeof(a))
#define m1(a) memset(a,-1,sizeof(a))
#define lb(x) ((x)&-(x))
#define lc(x) ((x)<<1)
#define rc(x) (((x)<<1)|1)
#define pb(G,x) (G).push_back((x))
#define For(a,b,c) for(int a=(b);a<=(c);a++)
#define Rep(a,b,c) for(int a=(b);a>=(c);a--)
#define in1(a) a=read()
#define in2(a,b) a=read(), b=read()
#define in3(a,b,c) a=read(), b=read(), c=read()
#define fst first 
#define scd second 
#define dbg puts("IAKIOI")

using namespace std;

int read() {
	int x=0,f=1; char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) f=(c=='-'?-1:1); 
	for(;c<='9'&&c>='0';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(int x) { if(x>=10) write(x/10); putchar('0'+x%10); }

const int mod = 998244353;
int qpo(int a,int b) {int res=1; for(;b;b>>=1,a=(a*a)%mod) if(b&1) res=res*a%mod; return res; }
int inv(int a) {return qpo(a,mod-2); }

#define maxn 200050

int n,m,x;
int a[maxn];
map<int,int> lst;
int f[maxn];

void work() {
	in3(n,m,x);
	For(i,1,n) {
		in1(a[i]);
		f[i]=max(f[i-1],lst[a[i]^x]);
		lst[a[i]]=i;
	}
	For(i,1,m) {
		int l,r;
		in2(l,r);
		cout<<(f[r]>=l?"yes":"no")<<'\n';
	}
}

signed main() {
//	ios::sync_with_stdio(false); 
//	cin.tie(0); cout.tie(0);
	int _=1;
//	_=read();
	For(i,1,_) {
		work();
	}
	return 0;
}
posted @   coding_goat_qwq  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示