解题思路:
每计算出来一对数相异或等于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 人评分
【蟠桃记】 (C语言代码)浏览:664 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1162 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:613 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:798 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:548 |
C语言程序设计教程(第三版)课后习题6.3 (C语言代码)from DQM浏览:666 |
1642题解浏览:715 |
1024题解浏览:808 |
简单的a+b (C语言代码)浏览:531 |
C二级辅导-公约公倍 (C语言代码)浏览:483 |