题目描述:链接点此

这套题的github地址(里面包含了数据,题解,现场排名):点此

链接:https://www.nowcoder.com/acm/contest/104/H
来源:牛客网

题目描述

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.

输入例子:
4
19 19 8 10
2
1 1 4
5 1 4
输出例子:
18
22

-->

示例1

输入

4
19 19 8 10
2
1 1 4
5 1 4

输出

18
22 题目意思:就是给你n个数,然后m次询问,每次询问有三个数b,l,r,求在[l,r]范围内,和b异或值最大的值 异或最大一般用字典树 但是这个涉及区间询问,所以要中可持久化字典树
/*
data:2018.04.27
author:gsw
link:https://www.nowcoder.com/acm/contest/104/H
account:tonygsw
*/
#define ll long long
#define IO ios::sync_with_stdio(false); #include<iostream>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=1e5+; class Node{
public:
int cnt,ls,rs;
};
Node tr[maxn*];
int root[maxn];int cnt; int in(int pre,int x,int deep)
{
int num=++cnt;
tr[num]=tr[pre];
tr[num].cnt=tr[pre].cnt+;
if(deep<)return num;
if(!((x>>deep)&))tr[num].ls=in(tr[pre].ls,x,deep-);
else tr[num].rs=in(tr[pre].rs,x,deep-);
return num;
}
int query(int l,int r,int x,int deep)
{
if(deep<)return ;
if(!((x>>deep)&))
{
if(tr[tr[r].rs].cnt>tr[tr[l].rs].cnt)return (<<deep)+query(tr[l].rs,tr[r].rs,x,deep-);
else return query(tr[l].ls,tr[r].ls,x,deep-);
}
else
{
if(tr[tr[r].ls].cnt>tr[tr[l].ls].cnt)return (<<deep)+query(tr[l].ls,tr[r].ls,x,deep-);
else return query(tr[l].rs,tr[r].rs,x,deep-);
}
} int main()
{
int n,x,m,b,l,r;
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&x);
root[i]=in(root[i-],x,);
}
scanf("%d",&m);
for(int i=;i<=m;i++)
{
scanf("%d%d%d",&b,&l,&r);
printf("%d\n",query(root[l-],root[r],b,));
}
}

I. Five Day Couple--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)的更多相关文章

  1. “今日头条杯”首届湖北省大学程序设计竞赛--F. Flower Road

    题目链接:点这 github链接:(包含数据和代码,题解):点这 链接:https://www.nowcoder.com/acm/contest/104/E来源:牛客网 题目描述 (受限于评测机,此题 ...

  2. “今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛 )--E. DoveCCL and Resistance

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 链接:https://www.nowcoder.com/acm/contest/104/D来源:牛客网 题目描述 ...

  3. A. Srdce and Triangle--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    如下图这是“今日头条杯”首届湖北省大学程序设计竞赛的第一题,作为赛后补题 题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 Let  be a regualr tr ...

  4. D. Who killed Cock Robin--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 由于系统限制,C题无法在此评测,此题为现场赛的D题 Who killed Cock Robin? I, ...

  5. H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

    题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 Given n positive integers , your task is to calculat ...

  6. “东信杯”广西大学第一届程序设计竞赛(同步赛)H

    链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...

  7. 2019年广东工业大学腾讯杯新生程序设计竞赛(同步赛)E-缺席的神官

    链接:https://ac.nowcoder.com/acm/contest/3036/E 来源:牛客网 题目描述 面前的巨汉,让我想起了多年前的那次,但这个巨汉身上散布着让人畏惧害怕的黑雾.即使看不 ...

  8. Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again

    Minieye杯第十五届华中科技大学程序设计邀请赛现场同步赛 I Matrix Again https://ac.nowcoder.com/acm/contest/700/I 时间限制:C/C++ 1 ...

  9. 2018今日头条杯 E-Jump a Jump

    Problem E. Jump A JumpInput file: standard inputOutput file: standard outputTime limit: 1 secondsMemor ...

随机推荐

  1. Cisco基础(六):配置目前网络环境、项目阶段练习

    一.配置目前网络环境 目标: 一家新创建的IT公司,公司位于北京有80多台服务器 目前网络环境使用技术,通过端口映射技术将web服务器发布给Internet: 三层交换:汇聚接入层交换机 默认路由:实 ...

  2. BZOJ 2653: middle(主席树+二分答案)

    传送门 解题思路 首先可以想到一种暴力做法,就是询问时二分,然后大于等于这个值的设为1,否则设为-1,然后就和GSS1那样统计答案.但是发现这样时间空间复杂度都很爆炸,所以考虑预处理,可以用主席树来做 ...

  3. redis常用命令-2

    redis常用命令 type your_key #查看Key类型 del your_key #删除key keys * #所有key info #信息 /usr/local/bin/redis-cli ...

  4. Eclipes 安装windowbuilding

    一.找到对应版本的windowbuilder 打开这个链接:http://www.eclipse.org/windowbuilder/download.php eclipse的版本号可以在eclips ...

  5. ACM-ICPC 比赛环境的使用

    ACM-ICPC 现场赛不同的赛站可能比赛环境不同,不过一般都是 Ubuntu 系统.附带的软件可能略有不同,可能会有使用习惯的差异导致效率下降或者无法运行代码,但是在终端下编译运行代码都是相同的.本 ...

  6. crypto 密码加密

    转自 'use strict'; var crypto = require('crypto'); /** * generates random string of characters i.e sal ...

  7. 防止重复提交 aspx.net

    :服务器控制.后台生成一个token,存入session或者其他缓存里面.渲染表单时,给form一个隐藏的token(令牌).用户提交表单时:先判断表单里面的token是否存在,不存在拒绝接受此数据: ...

  8. Spring入门之生命周期

    好几日没有读东西了,今天本来要读mybatis原理部分,但是看到作者讲,只是学会用不用学那么深,遂直接开干spring,工作中一直用springboot,框架都是领导搭好的,每天的任务就是增删改查,挺 ...

  9. python+tushare获取上市公司财务报表:资产负债表

    接口:balancesheet 描述:获取上市公司资产负债表 积分:用户需要至少500积分才可以调取,具体请参阅本文最下方积分获取办法 注:tushare包下载和初始化教程,请查阅我之前的文章 提示: ...

  10. 38-python基础-python3-检查字典中是否存在键或值

    in 和 not in 操作符   请注意, 在前面的例子中,‘name’ in spam 本质上是一个简写版本.相当于'name' in spam.keys()