BZOJ2223 [Coci 2009]PATULJCI
求区间内个数大于rank的一个数
主席树求一下就好啦!
/**************************************************************
Problem: 2223
User: rausen
Language: C++
Result: Accepted
Time:704 ms
Memory:54712 kb
****************************************************************/ #include <cstdio>
#include <algorithm> using namespace std;
const int N = 3e5 + ;
const int Cnt_chair = ; struct chair_node {
chair_node *ls, *rs;
int cnt;
} *root[N], mempool[Cnt_chair], *cnt_chair = mempool, *null; int n, mx, ans; inline int read() {
int x = ;
char ch = getchar();
while (ch < '' || '' < ch)
ch = getchar();
while ('' <= ch && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x;
} #define mid (l + r >> 1)
void chair_insert(chair_node *p, chair_node *&q, int l, int r, int x) {
(q = ++cnt_chair) -> cnt = p -> cnt + ;
if (l == r) return;
if (x <= mid)
q -> rs = p -> rs, chair_insert(p -> ls, q -> ls, l, mid, x);
else
q -> ls = p -> ls, chair_insert(p -> rs, q -> rs, mid + , r, x);
} int chair_query(chair_node *p, chair_node *q, int l, int r, int rank) {
if (l == r) return l;
if (q -> ls -> cnt - p -> ls -> cnt > rank)
return chair_query(p -> ls, q -> ls, l, mid, rank);
if (q -> rs -> cnt - p -> rs -> cnt > rank)
return chair_query(p -> rs, q -> rs, mid + , r, rank);
return ;
}
#undef mid int main() {
int Q, i, l, r;
n = read(), mx = read();
null = cnt_chair;
null -> cnt = , null -> ls = null -> rs = null;
root[] = null;
for (i = ; i <= n; ++i)
chair_insert(root[i - ], root[i], , mx, read());
Q = read();
while (Q--) {
l = read(), r = read();
if (l > r) swap(l, r);
ans = chair_query(root[l - ], root[r], , mx, (r - l + ) >> );
if (ans == ) printf("no\n");
else printf("yes %d\n", ans);
}
return ;
}
(p.s. 数组开小了连WA两发。。。555)
BZOJ2223 [Coci 2009]PATULJCI的更多相关文章
- BZOJ2223[Coci 2009]PATULJCI——主席树
题目描述 输入 先输入一个数n,然后一个数表示这n个数中最大的是多少,接下来一行n个数.然后一个数m,最后m行询问每次两个数l,r. 输出 no或者yes+这个数 样例输入 10 3 1 2 1 2 ...
- 2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)
传送门 主席树经典题目. 直接利用主席树差分的思想判断区间中数的个数是否合法然后决定左走右走就行了. 实际上跟bzoj3524是同一道题. 代码: #include<bits/stdc++.h& ...
- 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI
不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...
- bzoj 2223 [Coci 2009]PATULJCI
[Coci 2009]PATULJCI Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1286 Solved: 553[Submit][Status ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- 【BZOJ2223/3524】[Coci 2009]PATULJCI
Description Input Output 10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10 Sample Input ...
- 【bzoj2223】[Coci 2009]PATULJCI 主席树
题目描述 样例输入 10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10 样例输出 no yes 1 no yes 1 no yes ...
- bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI
题目链接1 题目链接2 主席树模板题 两题有细节不同 #include<algorithm> #include<iostream> #include<cstdlib> ...
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...
随机推荐
- matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图
一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...
- sql server 里的文件和文件组使用
转自:https://www.cnblogs.com/woodytu/p/5821827.html 参考:https://www.sqlskills.com/blogs/paul/files-and- ...
- mysql 数据操作 单表查询 group by group_concat() 函数
# group_concat() 和concat() 一样拼接字符串 用在分组里 需求:查看每个职位都有哪些员工名字 把所有员工成员的名字都列出来 把每个职位里的员工姓名列出来 mysql> s ...
- nodejs中Async详解之一:流程控制
为了适应异步编程,减少回调的嵌套,我尝试了很多库.最终觉得还是async最靠谱. 地址:https://github.com/caolan/async Async的内容分为三部分: 流程控制:简化十种 ...
- [py]python的深拷贝和浅拷贝
Python深复制浅复制or深拷贝浅拷贝 简单点说 copy.copy 浅拷贝 只拷贝父对象,不会拷贝对象的内部的子对象. copy.deepcopy 深拷贝 拷贝对象及其子对象 用一个简单的例子说明 ...
- #C++初学记录
输入与输出,头文件. #include<iostream> #include<algorithm> using namespace std; int main() { char ...
- 分页组件vue和jsp版本
vue版本 <template> <div class="com-vscroll"> <slot name="mcontent"& ...
- 2016 CCPC 长春 Solution
A - Hanzo vs. Genji 留坑. B - Fraction 水. #include <bits/stdc++.h> using namespace std; inline i ...
- linux sar命令详解及使用
sar(System Activity Reporter系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况.系统调用的使用情 ...
- python ConfigParser读取配置文件,及解决报错(去掉BOM)ConfigParser.MissingSectionHeaderError: File contains no section headers的方法
先说一下在读取配置文件时报错的问题--ConfigParser.MissingSectionHeaderError: File contains no section headers 问题描述: 在练 ...