2 条题解
-
0
//本题是不是有点问题 使用ump后极致优化也过不了 只能线段树? 上一个题解也过不了 我这个题解能多过一些#include<bits/stdc++.h> using namespace std; //#define int long long /* ///////////////////////////////////////////////////////////// 非常经典的题今天一定一定拿下 n q x n个固定区间+q次查询 问区间内是否有俩个数 a^b=x //异或问题的双对象:a^b=x---a=x^b--对于每个b找对于a为b^x; 查找:某个区间1:有没有这个数k或2:有几个或3:第n个的位置 思路:ump+二分查找 1: ump<int,vector<int>> ump[a[i]].push_back(i) 一堆相同的数字下标放进一堆 2: 因为有顺序的放入 所以一定一定有序(相同数字的下标) */ const int N=2e5+5; int a[N]; unordered_map<int,vector<int>> ump; int n,q,x; signed main() { std::ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); cin>>n>>q>>x; for(int i=1;i<=n;i++) { cin>>a[i]; ump[a[i]].push_back(i);//存地址 } // for(auto &it:ump)--------没有必要排序 我们在依次插入时候 下标一定有序 // { // sort(it.second.begin(),it.second.end()); // } int l,r; while(q--) { cin>>l>>r; bool flag=0; for(int i=l;i<=r;i++) { int aim=a[i]^x; if(ump.count(aim))//如果有才走 { auto j=lower_bound(ump[aim].begin(),ump[aim].end(),l);//在目标下标组中找第一个大于等于l if(j!=ump[aim].end()&&*j<=r&&*j!=i)//找得到+在区间+去重 { flag=1; break; } } } if(flag) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n"; } return 0; } -
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; #define x first #define y second const int N = 1e5 + 10, mod = 998244353; unordered_map<int, vector<int>> m; int a[N], x, n, q; bool check(int l, int r) { for(int i = l; i <= r; i ++) { int t = x ^ a[i]; if(m.count(t)) { auto j = lower_bound(m[t].begin(), m[t].end(), l); // auto k = lower_bound(m[t].begin(), m[t].end(), *j + 1); // if(j != m[t].end() && *j <= r && *j != i || k != m[t].end() && *k <= r && *k != i) // return true; if(j != m[t].end() && *j <= r && *j != i) return true; } } return false; } void solve() { cin >> n >> q >> x; for(int i = 1; i <= n; i ++) { cin >> a[i]; m[a[i]].push_back(i); } for(auto i : m) sort(i.y.begin(), i.y.end()); while(q --) { int l, r; cin >> l >> r; if(check(l, r)) cout << "Yes\n"; else cout << "No\n"; } } int main(){ int t = 1; // cin >> t; while(t --) solve(); }
- 1
信息
- ID
- 432
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- 递交数
- 122
- 已通过
- 18
- 上传者