NC15731. I. Five Day Couple
描述
Mingming, a cute girl of ACM/ICPC team of Wuhan University, is alone since graduate from high school. Last year, she used a program to match boys and girls who took part in an active called Boy or Girl friend in five days.
She numbered n () boys from 1 to \(n\), by their date of birth, and given i-th boy a number () in almost random. (We do not mean that in your input is generated in random.). Then she numbered m () girls from 1 to m, and given i-th girl a number () in the same way.
Also, i-th girl said that she only wanted to be matched to a boy whose age is between , which means that she should only be matched to a boy numbered from , ().
Mingming defined a rate R(i,j) to measure the score when the i-th boy and j-th girl matched. Where where means bitwise exclusive or. The higher, the better.
Now, for every girl, Mingming wants to know the best matched boy, or her "Mr. Right" can be found while her . As this is the first stage of matching process and Mingming will change the result manually, two girls can have the same "Mr. Right".
输入描述
The first line contains one number n.
The second line contains n integers, the i-th one is .
The third line contains an integer m.
Then followed by m lines, the j-th line contains three integers .
输出描述
Output m lines, the i-th line contains one integer, which is the matching rate of i-th girl and her Mr. Right.
示例1
输入:
4 19 19 8 10 2 1 1 4 5 1 4
输出:
18 22
C++14(g++5.4) 解法, 执行用时: 1443ms, 内存消耗: 4064K, 提交时间: 2018-05-12 17:02:09
#include <stdio.h> int main() { int i,n; int t; int a[100000]; int b, c, d; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } scanf("%d", &n); while (n--) { scanf("%d %d %d", &b, &c, &d); t = a[c-1] ^ b; for (i = c; i < d; i++) { if ((b ^ a[i]) > t) t = a[i] ^ b; } printf("%d\n", t); } }
C++11(clang++ 3.9) 解法, 执行用时: 951ms, 内存消耗: 1764K, 提交时间: 2018-04-22 20:18:59
#include<iostream> using namespace std;int a[100005];int main(){int n,m;scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d",&a[i]);scanf("%d",&m);int t,l,r;while(m--){scanf("%d%d%d",&t,&l,&r);int ma=0;for(int i=l;i<=r;i++)ma=max(a[i]^t,ma);printf("%d\n",ma);}return 0;}