时间限制 1 Second  内存限制 512 Mb

题目描述

HPU601球王争霸赛即将举行,ACMER纷纷参加.

现在有n个人报名参赛,每个人都有一个实力值 ai,实力值较大者获胜.

为保证比赛公平,我们定义比赛规则:

第一轮:[1, 2]pk,然后[3, 4]pk...最后[2i − 1, 2i]pk.

第二轮:[1, 2]W inner同[3, 4]W inner进行pk,然后[5, 6]W inner同[7, 8]W inner...

······

第m轮:最后一个W inner.

现在有q次询问,每次询问(u, v),第u轮第v个胜出者的编号?

输入

第一行一个正整数T,代表有T组测试数据. (1 ≤ T ≤ 10)

每组数据第一行输入正整数n, q,接下来n个正整数ai,表示实力值.(1 ≤ n, ai ≤ 2^16)(1 ≤ q ≤ 10)

接下来q行每行两个整数(u, v),询问第u轮第v个胜出者的编号.(0 ≤ u ≤ 16),(1 ≤ v ≤ 2^16)

输入保证每位选手的实力值ai都不相同,且询问合法

输入样例

1
2 2
2 1
0 2
1 1

输出样例

2
1

思路

线段树查询区间内的最大值,第n轮的第v个胜出者所在的区间为,因为每个人的实力值都不相同,所以可以用map标记每个人的实力值所对应的位置,然后套线段树模板就可以了

(数据比较水,比赛的时候因为没有线段树板子,行神好像是用暴力过去了,我忘了代码长啥样了,所以只有超级长的线段树的代码,行神的暴力代码好像只有五十行左右)

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=3e5+10;
const int mod=1e9+7;
using namespace std;
int a[maxn];
int father[maxn];
int MAX;
struct wzy
{
int left,right;
int value;
}node[maxn<<2];
void build(int i,int left,int right)
{
node[i].left=left;
node[i].right=right;
node[i].value=0;
if(left==right)
{
father[left]=i;
return;
}
build(i<<1,left,(right+left)/2);
build((i<<1)+1,(right+left)/2+1,right);
}
void update(int ri)
{
if(ri==1)
return ;
int fi=ri/2;
int l=node[fi<<1].value;
int r=node[(fi<<1)+1].value;
node[fi].value=max(l,r);
update(ri/2);
}
void query(int i,int l,int r)
{
if(node[i].left==l&&node[i].right==r)
{
MAX=max(MAX,node[i].value);
return ;
}
i=i<<1;
if(l<=node[i].right)
{
if(r<=node[i].right)
query(i,l,r);
else
query(i,l,node[i].right);
}
i+=1;
if(r>=node[i].left)
{
if(l>=node[i].left)
query(i,l,r);
else
query(i,node[i].left,r);
}
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
int t;
int n,q;
cin>>t;
while(t--)
{
map<int,int>mp;
cin>>n>>q;
MAX=0;//别忘清零......
build(1,1,n);
for(int i=1;i<=n;i++)
{
cin>>a[i];
mp[a[i]]=i;
node[father[i]].value=a[i];
update(father[i]);
}
int x,y;
while(q--)
{
MAX=0;
cin>>x>>y;
int r=(1<<x)*y;
int l=r-(1<<x)+1;
query(1,l,r);
cout<<mp[MAX]<<endl;
}
}
return 0;
}

HPU组队赛J:Ball King(线段树)的更多相关文章

  1. hdoj 1556 Color the ball【线段树区间更新】

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. hdu 1199 Color the Ball(离散化线段树)

    Color the Ball Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. ZOJ 2301 / HDU 1199 Color the Ball 离散化+线段树区间连续最大和

    题意:给你n个球排成一行,初始都为黑色,现在给一些操作(L,R,color),给[L,R]区间内的求染上颜色color,'w'为白,'b'为黑.问最后最长的白色区间的起点和终点的位置. 解法:先离散化 ...

  5. hdu 1556 Color the ball (技巧 || 线段树)

    Color the ballTime Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  6. Color the ball(线段树)

    Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  7. hdu1556 Color the ball 简单线段树

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 简单的线段树的应用 直接贴代码了: 代码: #include<iostream> # ...

  8. HDU 1556 Color the ball(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...

  9. 牛客网 中南林业科技大学第十一届程序设计大赛J题 二分+线段树

    https://www.nowcoder.com/acm/contest/124#question 题意  找第一个不小于K的数的下标,然后对它前一个数加一 解析   我们可以维护一个最大值数组  1 ...

随机推荐

  1. 把旧系统迁移到.Net Core 2.0 日记(4) - 使用EF+Mysql

    因为Mac 不能装SqlServer, 所以把数据库迁移到MySql,然后EntityFramework要改成Pomelo.EntityFrameworkCore.MySql 数据库迁移时,nvarc ...

  2. git开发过程的配置和使用

    git开发过程的使用 1.创建仓库 2.新建项目,填写项目名称等信息 3.初始化仓库,创建git仓库 git init 4.配置个人信息(配置过可忽略) git config --global use ...

  3. Use of undefined constant FTP_BINARY - assumed 'FTP_BINARY

    用Laravel中的filesystems里面的ftp上传文件时报错.在windows上开发,文件上传的时候碰到上面的问题,搜了些资料,发现是php7的ftp拓展默认未开启. 第一步:检查extens ...

  4. css 中的grid布局基础

    CSS Grid Layout为CSS引入了一个二维网格系统.网格可用于布局主要页面区域或小型用户界面元素. 网格是一组交叉的水平和垂直线 - 一组定义列,其他行.元素可以放在网格上,以行或者列为标准 ...

  5. RabbitMQ Dead Lettering(死信)

    死信,顾名思义,就是死掉的消息,死掉的消息是会被一般的队列丢弃的.如果这些消息很重要,而我们又需要,怎么办?凡事都有一个退路,现在就有一种方法可将这些死信消息存下来,那就是DLX(Dead Lette ...

  6. selenium登录界面,创建表单并填写提交

    #! python3 # -*- coding:utf8 -*- # https://selenium-python.readthedocs.io/api.html#selenium.webdrive ...

  7. C++输出数组名

    1.如果C++输出的数组是char类型的,那么输出的就是数组中的元素. 2.如果使用的是其他类型的数组作为输出的话,那么就是一个16进制的地址. 3.还是那句话,对数组的操作,很多时候都是指针的操作, ...

  8. linux系统安装mysql详细配置

    参考文章https://baijiahao.baidu.com/s?id=1584072431498789934&wfr=spider&for=pc https://www.5yun. ...

  9. 《软件调试 Windows概要》

    操作系统是计算机系统中的基本软件.它负责管理系统中的软硬件资源.通常都包括文件管理.内存管理.进程管理.打印管理.网络管理等基本功能.除此之外,支持调试也是操作系统设计的一项根本任务. 0x01  进 ...

  10. JavaWeb基础-Session和Cookie

    JSP状态管理 http的无状态性,服务器不会记得发送请求的浏览器是哪一个 保存用户状态的两大机制:session和cookie Cookie:是web服务器保存在客户端的一系列文本信息 作用:对特定 ...