P3567 [POI2014]KUR-Couriers
题目描述
Byteasar works for the BAJ company, which sells computer games.
The BAJ company cooperates with many courier companies that deliver the games sold by the BAJ company to its customers.
Byteasar is inspecting the cooperation of the BAJ company with the couriers.
He has a log of successive packages with the courier company that made the delivery specified for each package.
He wants to make sure that no courier company had an unfair advantage over the others.
If a given courier company delivered more than half of all packages sent in some period of time, we say that it dominated in that period.
Byteasar wants to find out which courier companies dominated in certain periods of time, if any.
Help Byteasar out!
Write a program that determines a dominating courier company or that there was none.
给一个数列,每次询问一个区间内有没有一个数出现次数超过一半
输入输出格式
输入格式:
The first line of the standard input contains two integers,  and
 and  (
 ( ), separated by a single space, that are the number of packages shipped by the BAJ company and the number of time periods for which the dominating courier is to be determined, respectively.
), separated by a single space, that are the number of packages shipped by the BAJ company and the number of time periods for which the dominating courier is to be determined, respectively.
The courier companies are numbered from  to (at most)
 to (at most)  .
.
The second line of input contains  integers,
 integers,  (
 ( ), separated by single spaces;
), separated by single spaces;  is the number of the courier company that delivered the
 is the number of the courier company that delivered the  -th package (in shipment chronology).
-th package (in shipment chronology).
The  lines that follow specify the time period queries, one per line.
 lines that follow specify the time period queries, one per line.
Each query is specified by two integers,  and
 and  (
 ( ), separated by a single space.
), separated by a single space.
These mean that the courier company dominating in the period between the shipments of the  -th and the
-th and the  -th package, including those, is to be determined.
-th package, including those, is to be determined.
In tests worth  of total score, the condition
 of total score, the condition  holds, and in tests worth
 holds, and in tests worth  of total score
 of total score  .
.
输出格式:
The answers to successive queries should be printed to the standard output, one per line.
(Thus a total of  lines should be printed.) Each line should hold a single integer: the number of the courier company that dominated in the corresponding time period, or
 lines should be printed.) Each line should hold a single integer: the number of the courier company that dominated in the corresponding time period, or  if there was no such company.
 if there was no such company.
输入输出样例
7 5
1 1 3 2 3 4 3
1 3
1 4
3 7
1 7
6 6
1
0
3
0
4
说明
给一个数列,每次询问一个区间内有没有一个数出现次数超过一半
题解
板子题练练手
刚开始还以为区间指的是数的区间……结果WAWA大哭……
后来才发现如果是数的区间我好像根本不会做……
老老实实敲了个主席树板子
不懂得可以看看大佬的讲解
//minamoto
#include<bits/stdc++.h>
#define N 500005
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
char obuf[<<],*o=obuf;
void print(int x){
if(x>) print(x/);
*o++=x%+;
}
int sum[N*],L[N*],R[N*],t[N];
int n,q,cnt=;
void update(int last,int &now,int l,int r,int x){
if(!now) now=++cnt;
sum[now]=sum[last]+;
if(l==r) return;
int mid=(l+r)>>;
if(x<=mid) R[now]=R[last],update(L[last],L[now],l,mid,x);
else L[now]=L[last],update(R[last],R[now],mid+,r,x);
}
int query(int u,int v,int l,int r,int k){
if(l==r) return l;
int x=sum[L[v]]-sum[L[u]],y=sum[R[v]]-sum[R[u]];
int mid=(l+r)>>;
if(x*>k) return query(L[u],L[v],l,mid,k);
if(y*>k) return query(R[u],R[v],mid+,r,k);
return ;
}
int main(){
//freopen("testdata.in","r",stdin);
n=read(),q=read();
for(int i=;i<=n;++i){
int x=read();
update(t[i-],t[i],,n,x);
}
while(q--){
int x,y;
x=read(),y=read();
int k=query(t[x-],t[y],,n,y-x+);
print(k);
*o++='\n';
}
fwrite(obuf,o-obuf,,stdout);
return ;
}
P3567 [POI2014]KUR-Couriers的更多相关文章
- luogu P3567 [POI2014]KUR-Couriers
		二次联通门 : luogu P3567 [POI2014]KUR-Couriers MMP 指针 RE + MLE + WA..... 不得已...向黑恶的数组实力低头 /* 指针 */ #inclu ... 
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
		题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ... 
- 【BZOJ 3524】【Poi2014】Couriers  可持久化线段树
		为什么这个主席树叫可持久化线段树,我不知道,具体得问达神.我无限T,然后DaD3zZ一针见血地指出了我的N*50爆内存导致无限编译超时O)ZO)ZO)Z真是太神啦.以图为鉴: 达神题解传送门:http ... 
- 【BZOJ】【3524】【POI2014】Couriers
		可持久化线段树 裸可持久化线段树,把区间第K大的rank改成num即可……(往儿子走的时候不减少) 苦逼的我……MLE了一次(N*30),RE了一次(N*10)……数组大小不会开…… 最后开成N*20 ... 
- 2018.09.14 洛谷P3567 [POI2014]KUR-Couriers(主席树)
		传送门 简单主席树啊. 但听说有随机算法可以秒掉%%%(本蒟蒻并不会) 直接维护值域内所有数的出现次数之和. 当这个值不大于区间总长度的一半时显然不存在合法的数. 这样在主席树上二分查值就行了. 代码 ... 
- 洛谷P3567[POI2014]KUR-Couriers(主席树+二分)
		题意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半 题解: 最近比赛太多,都没时间切水题了,刚好日推了道主席树裸题,就写了一下 然后 WA80 WA80 WA0 WA90 WA80 ?? ... 
- BZOJ3524 & LOJ2432:[POI2014]代理商Couriers——题解
		https://www.lydsy.com/JudgeOnline/problem.php?id=3524 https://loj.ac/problem/2432 给一个长度为n的序列a.1≤a[i] ... 
- [洛谷P3567][POI2014]KUR-Couriers
		题目大意:给一个数列,每次询问一个区间内有没有一个数出现次数超过一半.有,输出这个数,否则输出$0$ 题解:主席树,查询区间第$\bigg\lfloor\dfrac{len+1}{2}\bigg\rf ... 
- P3567 [POI2014]KUR-Couriers 主席树
		这个题比一般主席树还要简单,但是用来练习主席树再好不过了,在这里我再放一下主席树板子. 代码: #include<iostream> #include<cstdio> #inc ... 
随机推荐
- [HAOI2015]按位或(min-max容斥,FWT,FMT)
			题目链接:洛谷 题目大意:给定正整数 $n$.一开始有一个数字 $0$,然后每一秒,都有 $p_i$ 的概率获得 $i$ 这个数 $(0\le i< 2^n)$.一秒恰好会获得一个数.每获得一个 ... 
- A1058. A+B in Hogwarts
			If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- a ... 
- 面板 JPanel,滚动面板 JScrollPane,文本域JTextArea
			容器中可以有多个JPanel面板,一个JPanel面板中可以有多个控件. 滚动面板 JScrollPane中只能有一个控件. public class Demo extends JFram ... 
- java连接mysql的过程
			今天突然心血来潮,想要用java连接mysql,记得以前是在vs2010的环境下用C#连接sql sever,其实他们的方法都差不多. 现在就可以简单的介绍下java如何连接mysql 第一步,设计m ... 
- Linux命令之tar
			tar命令 用处:打包,压缩,解压 一.打包 用发:tar + -cvf + 被打包的文件名或者文件夹名 (参数C的意思是打包,参数V的意思是打包时显示信息,参数f的意思是打包后文件的后缀名) 示例 ... 
- 06-开闭原则(OCP)
			1. 背景 在软件的生命周期内,因为变化.升级和维护等原因需要对软件原有代码进行修改时,可能会给旧代码中引入错误,也可能会使我们不得不对整个功能进行重构,并且需要原有代码经过重新测试. 2. 定义 ... 
- ATS metric query
			ATS metric query 参考:ATS metric query proxy.node.cache_hit_mem_ratio proxy.node.cache_hit_mem_ratio_a ... 
- 词典的实现(4)-使用Hash方式来实现词典
			1,实现思路 public class HashedDictionary<K, V> implements DictionaryInterface<K, V>, Seriali ... 
- npm webpack工具 (监听压缩等)
			压缩.监听变动自动打包,:开发后,js编译压缩及样式去空格等 $ webpack --config XXX.js //url使用另一份配置文件(比如webpack.config2.js)来打包 $ w ... 
- 第三次实验计算分段函数 第四次计算分段函数和循环NEW 第五次分支+循环加强版 实验报告
			一.实验题目,设计思路,实现方法 第四次分支+循环 加强版 (2-2计算个人所得税,2-7 装睡,2-8计算天数) 设计思路:2-2 用if-else的语句,与计算分段函数的题类似的做法:2-7 运用 ... 
