时间限制 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. zabbix3.4.7主动模式监控日志(多关键字)

    日志监控原理 1.Zabbix Server和Zabbix Agent会追踪日志文件的大小和最后修改时间,并且分别记录在字节计数器和最新的时间计数器中. 2.Agent会从上次读取日志的地方开始读取日 ...

  2. shell 基本概述

    SHELL的概念 SHELL是一个命令行解释器,它为用户提供了一个向Linux内核发送请求以便运行程序的界面系统级程序, 用户可以用shell来启动,挂起,停止甚至是编写一些程序. ​ Shell还是 ...

  3. Win10系列:UWP界面布局基础7

    2.附加属性 有一些XAML元素,其自身的属性大多是在其它的元素中声明和使用的,该元素本身却很少使用,这些在其他元素中声明和使用的属性被称为附加属性(Attached Properties).附加属性 ...

  4. day23 模块02

    核能来袭--模块 2 1.nametuple() 2.os模块 3.sys模块(重点) 4.序列化 (四个函数) 5.pickle(重点) 6.json(重点中的重点) 1.nametuple() 命 ...

  5. C++11新特性,bind,基于对象

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  6. 前端基础之JavaScript进阶

    一.流程控制 if - else var a = 10; if (a >5){ console.log("yes"); }else { console.log("n ...

  7. jstree使用新的

    1.首先准备jstree树的dom元素 <p id="flowList_ul" class="flowList_ul"></p> 2.初 ...

  8. jdk8-全新时间和日期api

    1.jdk8日期和时间api是线程安全的 1.java.time  处理日期时间 2.java.time.temporal: 时间校正器.获取每个月第一天,周几等等 3.java.time.forma ...

  9. Nginx+Flume+Hadoop日志分析,Ngram+AutoComplete

    配置Nginx yum install nginx (在host99和host101) service nginx start开启服务 ps -ef |grep nginx看一下进程 ps -ef | ...

  10. AVD Manager 模拟器使用

    一.模拟器配置 1.双击启动AVD Manager,进入配置界面 2.点Create按钮创建 3.配置模拟器基本信息 --AVD Name:设备名称,自己定义一个,用英文(不要用中文) --Devic ...