=>Bitwise Queries
=> Coding
#include<iostream>
#include<vector>
using namespace std;
vector<int> myQuery(int N,vector<int> A,vector<vector<int>> queries){
vector<int> my;
int fVal,X,Y,counter=0;
for(int i=0;i<queries.size();i++){
X=queries[i][0];
for(int k=0;k<N;k++){
fVal=2*(A[k]|X)-(A[k]^X);
Y=queries[i][1];
if(fVal>=Y){
counter++;
}
}
my.push_back(counter);
counter=0;
}
cout<<"\n**Result***\n\n";
return my;
}
int main(){
int n,q,val,qVal;
cout<<"Enter the size of the array :";
cin>>n;
vector<int> arr;
for(int i=0;i<n;i++){
cin>>val;
arr.push_back(val);
}
cout<<"Enter the size of the query :";
cin>>q;
vector<vector<int>> query;
for(int i=0;i<q;i++){
vector<int> qRow;
for(int j=0;j<2;j++){
cin>>qVal;
qRow.push_back(qVal);
}
query.push_back(qRow);
}
vector<int> result;
result=myQuery(n,arr,query);
for(int i=0;i<result.size();i++){
cout<<result[i]<<endl;
}
}
Comments
Post a Comment