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
(
), 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)
.
The second line of input contains
integers,
(
), separated by single spaces;
is the number of the courier company that delivered the
-th package (in shipment chronology).
The
lines that follow specify the time period queries, one per line.
Each query is specified by two integers,
and
(
), separated by a single space.
These mean that the courier company dominating in the period between the shipments of the
-th and the
-th package, including those, is to be determined.
In tests worth
of total score, the condition
holds, and in tests worth
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
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 ...
随机推荐
- 在kubernetes集群上用helm安装Datadog(Monitoring)
Datadog is a monitoring service that gathers monitoring data from your containers within your Azure ...
- jar的打包与共享
做成jar包的,有个弊处,打包apk时会暴露源码,当然也有解决方案,放在最后讲. 先来解释如何生成jar: 新建工程,将工程编译至无错,右键工程Export... 在弹出的提示框中选择Java文件夹下 ...
- FFMEPG -- A ffmpeg and SDL Tutorial : tutorial05
修改了同步播放ffmpeg问题.并且增加可以放大视频. // tutorial05.c // A pedagogical video player that really works! // // C ...
- ( 大数 startsWith substring) Exponentiation hdu1063
Exponentiation Time Limit: 2000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- ElasticSearch搜索介绍四
ElasticSearch搜索 最基础的搜索: curl -XGET http://localhost:9200/_search 返回的结果为: { "took": 2, &quo ...
- SDRAM学习笔记(二)
上一篇博客主要讲解了一下SDRAM整体结构以及PCB方面的注意事项.接下来讲解一下需要用到的一些命令. 1.常用命令的缩写 上述是常用到的一些指令集. 2.模式寄存器 (1)突发长度 通过对A0~ ...
- 附录A Spring Boot应用启动器
spring Boot应用启动器基本的一共有44种,具体如下: 1)spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. 2)spring- ...
- mybatis中Parameter index out of range (1 > number of parameters, which is 0).
Parameter index out of range (1 > number of parameters, which is 0).(参数索引超出范围) 在mybatis里面写就是应该是 l ...
- CentOS6.x下yum安装MySQL5.5/5.6
1. 安装mysql-5.5的yum源 # rpm -ivh http://repo.mysql.com/yum/mysql-5.5-community/el/6/x86_64/mysql-commu ...
- JAVA Socket 编程---Socket 和 ServerSocket
一,Socket Socket的选项 1) TCP_NODELAY:默认值为false.表示采用Negale算法.当设置为true时,表示关闭Socket缓冲,立即发送数据. Socket默认发送数据 ...