传送门: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. 如何打开tensorboard观测训练过程

    TensorBoard是TensorFlow下的一个可视化的工具,能够帮助研究者们可视化训练大规模神经网络过程中出现的复杂且不好理解的运算,展示训练过程中绘制的图像.网络结构等. 最近本人在学习这方面 ...

  2. 词法分析用c++实现的

    #include<stdio.h>#include<string.h>int i,j,k,sign,flag,number,run;char ch;char word[10]; ...

  3. javascript 常用知识点

    1:浏览器是有缓存的,开发中可以通过快捷键绕过缓存 对于Windows驱动的系统:Ctrl + F5 对于Mac驱动的系统:Command + Shift + R. 2:精度问题 (符点和大数字可能会 ...

  4. [BZOJ4870][Shoi2017]组合数问题 dp+矩阵乘

    4870: [Shoi2017]组合数问题 Time Limit: 10 Sec  Memory Limit: 512 MB Description Input 第一行有四个整数 n, p, k, r ...

  5. ubuntu adduser

    ubuntu adduser 添加用户 hexan 到目录 /home/hexan 下.$ sudo adduser hexan -home /home/hexan 添加一个普通用户adduser [ ...

  6. 【BZOJ4456】旅行者(最短路,分治)

    [BZOJ4456]旅行者(最短路,分治) 题面 BZOJ Description 小Y来到了一个新的城市旅行.她发现了这个城市的布局是网格状的,也就是有n条从东到西的道路和m条从南到北 的道路,这些 ...

  7. BZOJ2595:[Wc2008]游览计划——题解(插头dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2595 Description Input 第一行有两个整数,N和 M,描述方块的数目. 接下来 N行 ...

  8. ZJOI 2017 二试 day0

    2017.4.25 话说4.24怒订正了6题,早上大扫除,把校服弄脏了too sad 中午从二中出发,只2个小时不到就抵达宾馆,开始先在大厅等候了半天(分配房间),和一试差不多.只是这个宾馆要远优于“ ...

  9. Splitter Control for Dialog

    原文链接地址:https://www.codeproject.com/Articles/595602/Splitter-Control-for-Dialog Introduction Yes, tha ...

  10. 最长上升子序列nlogn算法

    LIS问题是经典的动态规划问题,它的状态转移相信大家都很熟悉: f[i] = f[k] + 1  (k < i 且 A[k] < A[i]) 显然这样做复杂度是O(n^2) 有没有更快的算 ...