bzoj3524/2223 [Poi2014]Couriers
传送门: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的更多相关文章
- [bzoj3524/2223][Poi2014]Couriers_主席树
Couriers bzoj-3524 Poi-2014 题目大意:给定n个数的序列,询问区间内是否存在一个在区间内至少出现了(区间长度>>1)次的数.如果有,输出该数,反之输出0. 注释: ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- 【BZOJ3524】 [Poi2014]Couriers
Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. ...
- 【bzoj3524】[Poi2014]Couriers 主席树
题目描述 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0. 输入 第一行 ...
- BZOJ3524:[POI2014]Couriers
浅谈主席树:https://www.cnblogs.com/AKMer/p/9956734.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem.p ...
- 【BZOJ3524/2223】[Poi2014]Couriers 主席树
[BZOJ3524][Poi2014]Couriers Description 给一个长度为n的序列a.1≤a[i]≤n.m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大 ...
- [BZOJ2223][BZOJ3524][Poi2014]Couriers 主席树
3524: [Poi2014]Couriers Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2436 Solved: 960[Submit][St ...
- BZOJ 3524: [Poi2014]Couriers [主席树]
3524: [Poi2014]Couriers Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 1892 Solved: 683[Submit][St ...
- BZOJ 3524: [Poi2014]Couriers
3524: [Poi2014]Couriers Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 1905 Solved: 691[Submit][St ...
随机推荐
- asp.net如何实现负载均衡方案讨论
请注意,本文内容分多次修改,如需阅读,请阅读完整,因为早期的观点是不太合理的,后面由于水平进步,已经做了修改! 我的目标是我一个人搭建一个负载均衡网站.不接受这是网络部,或者运维,或者系统部的事情,所 ...
- prototype.js中Function.prototype.bind方法浅解
prototype.js中的Function.prototype.bind方法: Function.prototype.bind = function() { var __method = this; ...
- PAT L1-032 Left-pad
https://pintia.cn/problem-sets/994805046380707840/problems/994805100684361728 根据新浪微博上的消息,有一位开发者不满NPM ...
- PAT 甲级 1019 General Palindromic Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
- 可以从Jar外部加载JDBC.properties的Spring-mybatis配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Spring Autowired原理
今天来整理一下Spring的自动装配 autowire一节,在这里我们要解决以下问题: 什么是自动装配? 自动装配的意义? 自动装配有几种类型? 如何启用自动装配? 自动装配将引发的问题? 一.什么是 ...
- 【C++】C++函数重载的总结
函数重载: 出现在相同作用域中的两个函数,如果具有相同的名字而形参表不同,则称为重载函数(overloaded function).一定要注意函数重载的两个关键词:形参列表和作用域. 任何程序有且仅有 ...
- 第120天:移动端-Bootstrap基本使用方法
一.Bootstrap使用 1.搭建Bootstrap页面骨架及项目目录结构 ``` ├─ /weijinsuo/ ··················· 项目所在目录 └─┬─ /css/ ···· ...
- Infinity NaN undefined和null
Infinity属性用于存放表示正无穷大的数值. 负无穷大是表示负无穷大一个数字值. 该属性为Global对象的一个只读属性, 所有主流浏览器均支持该属性. Infinity属性的值为Number类型 ...
- robot framework 安装
一.安装 Python 2.7 pip 和 setuptools (Python 的套件管理程式,最新版的Python 2.7.13已包含) Robot Framework (此工具本身) wxPyt ...