疾风亦有归途


私信TA

用户名:uq_75623990602

访问量:3349

签 名:

等  级
排  名 9578
经  验 1088
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

解题思路:
每计算出来一对数相异或等于x时,将其下标存在pair数组中,下次输入区间时,首先匹配若数组中每对下标在此区间内,则其内存在两数异或等于x,可直接输出yes,省去继续判断的过程。
注意事项:
注意超时。
参考代码:

#include <iostream>

#include <vector>

#include <set>

#include <string>

#include <map>

#include <queue>

#include <stack>

#include <cstdio>

#include <cstring>//strlen、strcmp 

#include <cmath>

#include <cstdlib>//malloc

#include <algorithm>

using namespace std;



int main() {

int n,m;

long long x;

scanf("%d %d %lld",&n,&m,&x);

long long a[n+1];

int s,e;

for(int i = 1;i <= n;i++){

scanf("%lld",&a[i]);

}

bool is;

pair<int,int> isx[n/2+1];

int ii = 0;

for(int i = 0;i < m;i++){

scanf("%d%d",&s,&e);

is = false;

for(int h = 0;h <= ii;h++){

if(s <= isx[h].first && e >= isx[h].second){

is = true;

break;

}

}

if(is){

printf("yes\n");

continue;

}

for(int j = s;j <= e;j++){

for(int k = j+1;k <= e;k++){

if((a[j]^a[k]) == x){

is = true;

isx[ii].first = j;

isx[ii++].second = k;

break;

}

}

if(is){

break;

}

}

if(is)

printf("yes\n");

else

printf("no\n");

}


return 0;

}



 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区