【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
yes 1
no
yes 1
no
yes 2
no
yes 3
Sample Output
HINT
Notice:输入第二个整数是序列中权值的范围Lim,即1<=ai(1<=i<=n)<=Lim。
依旧主席树模板,无需离散化。
1<=Lim<=10000
Source
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 10000010
using namespace std;
int sum[N],root[],ls[N],rs[N];
int n,m,lim,sz;
void updata(int l,int r,int x,int &y,int v)
{
y=++sz;
sum[y]=sum[x]+;
ls[y]=ls[x]; rs[y]=rs[x];
if (l==r) return;
int mid=(l+r)>>;
if (v<=mid) updata(l,mid,ls[x],ls[y],v);
else updata(mid+,r,rs[x],rs[y],v);
} int query(int L,int R)
{
int l=,r=n,temp=(R-L+)>>,x=root[L-],y=root[R],mid;
while (l<r)
{
if (sum[y]-sum[x]<=temp) return ;
mid=(l+r)>>;
if (sum[ls[y]]-sum[ls[x]]>temp)
{
r=mid; x=ls[x]; y=ls[y];
}
else if (sum[rs[y]]-sum[rs[x]]>temp)
{
l=mid+, x=rs[x]; y=rs[y];
}
else return ;
}
return l;
} int main()
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
int a;
scanf("%d",&a);
updata(,n,root[i-],root[i],a);
}
// scanf("%d",&m);
for (int i=;i<=m;i++)
{
int aa,bb;
scanf("%d%d",&aa,&bb);
int pos=query(aa,bb);
printf("%d\n",pos);
// if (pos==0) printf("no\n");
//else printf("yes %d\n",pos);
}
return ;
}
【BZOJ2223/3524】[Coci 2009]PATULJCI的更多相关文章
- 【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 ...
- 【BZOJ2223&&3524】PATULJCI [主席树]
PATULJCI Time Limit: 10 Sec Memory Limit: 259 MB[Submit][Status][Discuss] Description Input 第一行两个整数 ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- bzoj 2223 [Coci 2009]PATULJCI
[Coci 2009]PATULJCI Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1286 Solved: 553[Submit][Status ...
- 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI
不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...
- 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
求区间内个数大于rank的一个数 主席树求一下就好啦! /************************************************************** Problem: ...
随机推荐
- sql server 本地复制订阅 实现数据库服务器 读写分离(转载)
转载地址:http://www.cnblogs.com/echosong/p/3603270.html 再前段echosong 写了一遍关于mysql 数据同步实现业务读写分离的文章,今天咱们来看下S ...
- 使用 Log4Net 记录日志
第一步:下载Log4Net 下载地址:http://logging.apache.org/log4net/download_log4net.cgi 把下载的 log4net-1.2.11-bin-n ...
- 攻城狮在路上(壹) Hibernate(八)--- 映射Hibernate组成关系
一.使用组成关系的原则: 在不导致数据冗余的前提下,尽可能减少数据库表的数目及表之间的外键参照关系,因为建立多个表的连接是很耗时的操作. 举例说明:Customer类中的Address属性,可以通过组 ...
- js 节点 document html css 表单节点操作
js 节点 document html css 表单节点操作 节点操作:访问.属性.创建 (1)节点的访问:firstChild.lastChild.childNodes.parentChild(父子 ...
- WPF 自定义Metro Style窗体
为了使WPF程序在不同版本的操作系统上保持一致的显示效果,我们需要重写WPF控件样式.这篇博客将展示如何创建一个Metro Style的WPF窗体. 首先先看一下最终窗体的效果图, 通过截图我们可以看 ...
- hdu 4031 2011成都赛区网络赛A题 线段树 ***
就是不知道时间该怎么处理,想了好久,看了别人的题解发现原来是暴力,暴力也很巧妙啊,想不出来的那种 -_-! #include<cstdio> #include<iostream&g ...
- linux网络协议
网络协议 本章节主要介绍linxu网络模型.以及常用的网络协议分析以太网协议.IP协议.TCP协议.UDP协议 一.网络模型 TCP/IP分层模型的四个协议层分别完成以下的功能: 第一层 网络接口层 ...
- visio 交叉线 不出现拱形怎么办?
- UI背景构建
个中原因不是很明白 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android=& ...
- python学习第二天
dict字典 把数据放入dict:直接赋值.初始化时指定 pop删除key set集合 add添加元素 remove删除元素 字符串str是不可变对象,对字符串的操作都会返回新的字符串 pass 什么 ...