传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3524

http://www.lydsy.com/JudgeOnline/problem.php?id=2223

【题解】

由于出现次数超过区间长度的一半的数最多只有1个,所以就可以分两半找了。。

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + , SN = * + ;
const int mod = 1e9+; int n, a[M], rt[M], p; struct CMT {
int ch[SN][], w[SN], siz;
inline void set() { siz = ; }
inline void up(int x) {
if(!x) return ;
w[x] = w[ch[x][]] + w[ch[x][]];
}
inline void edt(int &x, int y, int l, int r, int ps) {
x = ++siz;
ch[x][] = ch[y][], ch[x][] = ch[y][]; w[x] = w[y];
if(l == r) {
++ w[x];
return ;
}
int mid = l+r>>;
if(ps <= mid) edt(ch[x][], ch[y][], l, mid, ps);
else edt(ch[x][], ch[y][], mid+, r, ps);
up(x);
}
inline int query(int x, int y, int l, int r) {
if(w[y] - w[x] < p) return ;
if(l == r) return l;
int mid = l+r>>, p0 = w[ch[y][]] - w[ch[x][]], p1 = w[ch[y][]] - w[ch[x][]];
if(p0 > p) return query(ch[x][], ch[y][], l, mid);
else if(p1 > p) return query(ch[x][], ch[y][], mid+, r);
else return ;
}
}T; int main() {
int Q, l, r;
cin >> n >> Q;
for (int i=, t; i<=n; ++i) {
scanf("%d", &t);
T.edt(rt[i], rt[i-], , n, t);
}
while(Q--) {
scanf("%d%d", &l, &r);
p=(r-l+)/;
printf("%d\n", T.query(rt[l-], rt[r], , n));
}
return ;
}

bzoj3524/2223 [Poi2014]Couriers的更多相关文章

  1. [bzoj3524/2223][Poi2014]Couriers_主席树

    Couriers bzoj-3524 Poi-2014 题目大意:给定n个数的序列,询问区间内是否存在一个在区间内至少出现了(区间长度>>1)次的数.如果有,输出该数,反之输出0. 注释: ...

  2. [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树

    题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...

  3. 【BZOJ3524】 [Poi2014]Couriers

    Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. ...

  4. 【bzoj3524】[Poi2014]Couriers 主席树

    题目描述 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. 输入 第一行 ...

  5. BZOJ3524:[POI2014]Couriers

    浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...

  6. 【BZOJ3524/2223】[Poi2014]Couriers 主席树

    [BZOJ3524][Poi2014]Couriers Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大 ...

  7. [BZOJ2223][BZOJ3524][Poi2014]Couriers 主席树

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 2436  Solved: 960[Submit][St ...

  8. BZOJ 3524: [Poi2014]Couriers [主席树]

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1892  Solved: 683[Submit][St ...

  9. BZOJ 3524: [Poi2014]Couriers

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1905  Solved: 691[Submit][St ...

随机推荐

  1. 软件图书,偏.net方向

    深入理解计算机系统(原书第2版) 作者:Randal E.Bryant:1981年在麻省理工学院获计算机科学博士学位,现任美国卡内基·梅隆大学计算机学院院长 内容: 深入浅出地介绍了处理器.编译器.操 ...

  2. Git命令常用清单

    本文从以下十个方面,介绍Git命令的常用清单: 一.新建代码库 二.配置 三.增加/删除文件 四.代码提交 五.分支 六.标签 七.查看信息 八.远程同步 九.撤销 十.其他 每天使用 Git ,但是 ...

  3. Sublime Text怎么设置文件在新标签打开?

    设置Sublime Text新标签页tab打开文件.Sublime Text Files not opening a new tab?每次打开文件,Sublime Text总是把当前的tab打开的文件 ...

  4. 在MySQL中如何使用覆盖索引优化limit分页查询

    背景 今年3月份时候,线上发生一次大事故.公司主要后端服务器发生宕机,所有接口超时.宕机半小时后,又自动恢复正常.但是过了2小时,又再次发生宕机. 通过接口日志,发现MySQL数据库无法响应服务器.在 ...

  5. Halcon 学习笔记3 仿射变换

    像素的减少 开运算(较少) 腐蚀(去除更多) 对灰度图像的开运算或腐蚀 相当于将灰度图像变暗 像素增加 闭运算(较少) 膨胀(较多) 对灰度图像的闭运算或膨胀 相当于将灰度图像变亮 仿射变换 另外一种 ...

  6. docker-py execute echo无效

    错误写法: cli.execute('9b2606a50304','echo "bibo">/tmp/1.txt')   争取写法: cli.execute('9b2606a ...

  7. [九]SpringBoot 之 定时任务

    代码: package me.shijunjie.config; import org.springframework.context.annotation.Configuration; import ...

  8. Android开发性能优化总结(一)

    安卓开发应用首先要讲究良好的用户体验,如果一款软件卡顿现象严重,不流畅,经常崩溃,那么将给用户带来极不良好的体验,从而损失用户. 在实际开发和学习中,我总结了一下关于安卓性能的优化,供大家参考交流. ...

  9. [ACM]Codeforces Round #534 (Div. 2)

    A. Splitting into digits Vasya has his favourite number n. He wants to split it to some non-zero dig ...

  10. 【bzoj1022】小约翰的游戏John

    Portal -->bzoj1022 Solution ​  这题其实是裸的反Nim,这里主要是为了写反Nim游戏的证明 ​  首先给出反Nim(anti-nim)的定义和结论: [定义]桌子上 ...