bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI
主席树模板题
两题有细节不同
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
#define CSC main
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
void inin(int &ret)
{
ret=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<='')ret*=,ret+=ch-'',ch=getchar();
ret=f?-ret:ret;
}
int root[],l[],r[],sum[];
int n,m,ed;
void update(int ll,int rr,int x,int &y,int xx)
{
y=++ed,sum[y]=sum[x]+;
if(ll==rr)return ;
l[y]=l[x],r[y]=r[x];
int mid=(ll+rr)>>;
if(xx<=mid)update(ll,mid,l[x],l[y],xx);
else update(mid+,rr,r[x],r[y],xx);
}
int query(int L,int R)
{
int ll=,rr=n,mid,x=root[L-],y=root[R],temp=(R-L+)>>;
while(ll<rr)
{
if(sum[y]-sum[x]<=temp)return ;mid=(ll+rr)>>;
if(sum[l[y]]-sum[l[x]]>temp)rr=mid,x=l[x],y=l[y];
else if(sum[r[y]]-sum[r[x]]>temp)ll=mid+,x=r[x],y=r[y];
else return ;
}
return ll;
}
int CSC()
{
inin(n),inin(m);
re(i,,n)
{
int x;inin(x);
update(,n,root[i-],root[i],x);
}
re(i,,m)
{
int ll,rr;inin(ll),inin(rr);
printf("%d\n",query(ll,rr));
}
return ;
}
bzoj3524
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define rre(i,r,l) for(int i=(r);i>=(l);i--)
#define re(i,l,r) for(int i=(l);i<=(r);i++)
#define Clear(a,b) memset(a,b,sizeof(a))
#define inout(x) printf("%d",(x))
#define douin(x) scanf("%lf",&x)
#define strin(x) scanf("%s",(x))
#define LLin(x) scanf("%lld",&x)
#define op operator
#define CSC main
typedef unsigned long long ULL;
typedef const int cint;
typedef long long LL;
using namespace std;
void inin(int &ret)
{
ret=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=;ch=getchar();}
while(ch>=''&&ch<='')ret*=,ret+=ch-'',ch=getchar();
ret=f?-ret:ret;
}
int root[],l[],r[],sum[];
int n,m,ed;
void update(int ll,int rr,int x,int &y,int xx)
{
y=++ed,sum[y]=sum[x]+;
if(ll==rr)return ;
l[y]=l[x],r[y]=r[x];
int mid=(ll+rr)>>;
if(xx<=mid)update(ll,mid,l[x],l[y],xx);
else update(mid+,rr,r[x],r[y],xx);
}int lim;
int query(int L,int R)
{
if(L>R)swap(L,R);
int ll=,rr=lim,mid,x=root[L-],y=root[R],temp=(R-L+)>>;
while(ll!=rr)
{
if(sum[y]-sum[x]<=temp)return ;mid=(ll+rr)>>;
if(sum[l[y]]-sum[l[x]]>temp)rr=mid,x=l[x],y=l[y];
else if(sum[r[y]]-sum[r[x]]>temp)ll=mid+,x=r[x],y=r[y];
else return ;
}
return ll;
}
int CSC()
{
inin(n),inin(lim);
re(i,,n)
{
int x;inin(x);
update(,lim,root[i-],root[i],x);
}inin(m);
re(i,,m)
{
int ll,rr;inin(ll),inin(rr);
int ans=query(ll,rr);if(ans)cout<<"yes ";else cout<<"no\n";
if(ans)printf("%d\n",ans);
}
return ;
}
bzoj2223
bzoj3524 [Poi2014]Couriers/2223 [Coci 2009]PATULJCI的更多相关文章
- bzoj 2223 [Coci 2009]PATULJCI
[Coci 2009]PATULJCI Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1286 Solved: 553[Submit][Status ...
- 主席树||可持久化线段树||BZOJ 3524: [Poi2014]Couriers||BZOJ 2223: [Coci 2009]PATULJCI||Luogu P3567 [POI2014]KUR-Couriers
题目:[POI2014]KUR-Couriers 题解: 要求出现次数大于(R-L+1)/2的数,这样的数最多只有一个.我们对序列做主席树,每个节点记录出现的次数和(sum).(这里忽略版本差值问题) ...
- BZOJ 2223 [Coci 2009]PATULJCI | 主席树练习 (好像是个权限题啊)
题目: 给个序列,问[l,r]区间内是否存在x>(r-l+1)>>1 题解: 好像大家都觉得这个题比较简单,没人写题解啊 先说BZOJ样例的格式应该是,第二个数是序列中数的范围(就是 ...
- BZOJ 2223: [Coci 2009]PATULJCI 主席树
Code: #include<bits/stdc++.h> #define maxn 300001 #define mid ((l+r)>>1) using namespace ...
- [BZOJ2223][BZOJ3524][Poi2014]Couriers 主席树
3524: [Poi2014]Couriers Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 2436 Solved: 960[Submit][St ...
- [bzoj3524==bzoj2223][Poi2014]Couriers/[Coci 2009]PATULJCI——主席树+权值线段树
题目大意 给定一个大小为n,每个数的大小均在[1,c]之间的数列,你需要回答m个询问,其中第i个询问形如\((l_i, r_i)\),你需要回答是否存在一个数使得它在区间\([l_i,r_i]\)中出 ...
- 2018.09.30 bzoj2223: [Coci 2009]PATULJCI(主席树)
传送门 主席树经典题目. 直接利用主席树差分的思想判断区间中数的个数是否合法然后决定左走右走就行了. 实际上跟bzoj3524是同一道题. 代码: #include<bits/stdc++.h& ...
- BZOJ2223 [Coci 2009]PATULJCI
求区间内个数大于rank的一个数 主席树求一下就好啦! /************************************************************** Problem: ...
- Bzoj3524 [Poi2014]Couriers
Description 给一个长度为n的序列a.1≤a[i]≤n. m组询问,每次询问一个区间[l,r],是否存在一个数在[l,r]中出现的次数大于(r-l+1)/2.如果存在,输出这个数,否则输出0 ...
随机推荐
- python中列表排序,字典排序,列表中的字典排序
#-*- encoding=utf-8 -*- # python3代码 import operator 一. 按字典值排序(默认为升序) x = {1:2, 3:4, 4:3, 2:1, 0:0} 1 ...
- pandas 中的DataFrame.where()使用
pandas.DataFrame.where DataFrame.where(cond, other=nan, inplace=False, axis=None, level=None, try_ca ...
- The end of the world
这首63年乡村及流行排行榜双料亚军的歌曲,(Cashbox 年终冠军)据说原是作者为怀念亡父写就,虽是流行曲风,但由Skeeter Davis演唱,却赋予其不同的生命,在键盘连绵的三连音中,少女诉说着 ...
- 使用find命令按条件查找多个文件并且拷贝至指定目录
命令格式如下 find / \( -name "*.war" -o -name "*.jar" \) | xargs -i cp {} ${wardir} 当需 ...
- Pycharm中如何使用科学计算库
1.简便起见 比起麻烦的安装各种库,我们选择最方便的Anaconda的conda或pip(兼容支持)安装相关库. Pycharm本身缺少numpy和matplotlib这些库,而另一个Python的开 ...
- Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice ...
- 软件工程-wordcount(C语言实现)
Github项目地址:https://github.com/xiaobaot/wordcount-wc/tree/master WC 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数 ...
- Redis、Mongo - 目录
redis redis字典取数据.列表取数据(数据量大) redis 实现栈 - python mongodb - 可视化工具 / pymongo - 使用方法
- 2018/03/08 每日一学PHP 之 常量defind 和 const区别
常量defind 和 const区别 什么是常量? 如字面理解的,在脚本执行期间不可改变的的量. 定义一个常量应该注意的事项? 1:常量默认大小写敏感,错误的大小写不会被识别为常量. 2:常量只能是标 ...
- javascript php 数组 json 对比 总结
看到这个博客,终于明白JavaScript 里只有一种 Array,不存在索引数组和关联数组. 1.在js中所有要素都是继承自Object对象的,任何对象都能通过obj["name" ...