BZOJ 4408: [Fjoi 2016]神秘数 主席树 + 神题
Code:
#include<bits/stdc++.h>
#define lson ls[x]
#define mid ((l+r)>>1)
#define rson rs[x]
#define maxn 300003
#define inf 1000000001
#define setIO(s) freopen(s".in","r",stdin)
using namespace std;
int cnt;
int ls[maxn*20], rs[maxn*20], sumv[maxn*20], root[maxn];
void build(int &x,int l,int r)
{
x=++cnt;
if(l==r)return;
if(mid>=l) build(lson, l,mid);
if(r>mid) build(rson,mid+1,r);
}
int update(int x,int l,int r,int k,int delta)
{
int oo=++cnt;
ls[oo]=ls[x], rs[oo]=rs[x], sumv[oo]=sumv[x]+delta;
if(l==r) return oo;
if(k<=mid) ls[oo]=update(lson,l,mid,k,delta);
else rs[oo]=update(rson,mid+1,r,k,delta);
return oo;
}
int query(int u,int v,int l,int r,int L,int R)
{
if(l>=L&&r<=R) return sumv[v]-sumv[u];
int tmp=0;
if(L<=mid) tmp+=query(ls[u],ls[v],l,mid,L,R);
if(R>mid) tmp+=query(rs[u],rs[v],mid+1,r,L,R);
return tmp;
}
int main()
{
// setIO("input");
int n,q,i,a,l,r;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%d",&a);
root[i]=update(root[i-1],1,inf,a,a);
}
scanf("%d",&q);
while(q--)
{
scanf("%d%d",&l,&r);
int mx=0,pos=0,sum;
while(1)
{
sum=query(root[l-1],root[r],1,inf,mx+1,pos+1);
if(sum<=0) break;
mx=pos+1, pos+=sum;
}
printf("%d\n",pos+1);
}
return 0;
}
BZOJ 4408: [Fjoi 2016]神秘数 主席树 + 神题的更多相关文章
- BZOJ 4408: [Fjoi 2016]神秘数 [主席树]
传送门 题意: 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13},8无法表示为集合S的子集的和,故集合S的神秘数为8.现给定n个正整数a[1]. ...
- Bzoj 4408: [Fjoi 2016]神秘数 可持久化线段树,神题
4408: [Fjoi 2016]神秘数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 128[Submit][Status ...
- BZOJ 4408: [Fjoi 2016]神秘数 可持久化线段树
4408: [Fjoi 2016]神秘数 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4408 Description 一个可重复数字集 ...
- BZOJ 4408: [Fjoi 2016]神秘数
4408: [Fjoi 2016]神秘数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 464 Solved: 281[Submit][Status ...
- bzoj 4408: [Fjoi 2016]神秘数 数学 可持久化线段树 主席树
https://www.lydsy.com/JudgeOnline/problem.php?id=4299 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1 ...
- ●BZOJ 4408 [Fjoi 2016]神秘数
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=4408 题解: 主席树 首先,对于一些数来说, 如果可以我们可以使得其中的某些数能够拼出 1- ...
- BZOJ4408&4299[Fjoi 2016]神秘数——主席树
题目描述 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13},1 = 1 2 = 1+1 3 = 1+1+1 4 = 4 5 = 4+1 6 = ...
- 【bzoj4408】[Fjoi 2016]神秘数 主席树
题目描述 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13},1 = 12 = 1+13 = 1+1+14 = 45 = 4+16 = 4+1+1 ...
- 4408: [Fjoi 2016]神秘数
4408: [Fjoi 2016]神秘数 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 452 Solved: 273 [Submit][Stat ...
随机推荐
- 010-elasticsearch5.4.3【四】-聚合操作【一】-度量聚合【metrics】-min、max、sum、avg、count
一.概述 度量类型聚合主要针对的number类型的数据,需要ES做比较多的计算工作 参考向导:地址 import org.elasticsearch.search.aggregations.Aggre ...
- Maven install报错:MojoFailureException ,To see the full stack trace of the errors, re-run Maven with the -e switch.解决
报错日志: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to ...
- template标签就相当于React中的fragment
template标签就相当于React中的fragment
- jmeter之分布式压测
很多性能大牛说一台机器的压测其实不准确,于是搜索网上的分布式压测练习了一番 目录 1.环境准备 2.控制机和压测机配置 3.执行分布式压测 1.环境准备 1.1准备一台windows作为控制机(mas ...
- @SuppressWarnings https://www.cnblogs.com/fsjohnhuang/p/4040785.html
一.前言 编码时我们总会发现如下变量未被使用的警告提示: 上述代码编译通过且可以运行,但每行前面的“感叹号”就严重阻碍了我们判断该行是否设置的断点了.这时我们可以在方法前添加 @SuppressWar ...
- TensorFlow学习笔记-总结与排错
总结 为了学习和使用tensorflow作为工具, 我决定逐步亲自动手一行行写一下: [x] MNIST手写模型; [x] MNIST多层感知机(前馈神经网络,2层); [x] MNIST卷积网络(2 ...
- sqluldr2 oracle直接导出数据为文本的小工具使用
近期客户有需求,导出某些审计数据,供审计人进行核查,只能导出成文本或excel格式的进行查看,这里我们使用sqluldr2工具进行相关数据的导出. oracle导出数据为文本格式比较麻烦,sqluld ...
- loading 加载工具
loading 加载工具:http://loading.awesomes.cn/
- 《剑指offer》面试题15 链表中的倒数第k个节点 Java版
书中方法:用两个节点一次遍历求得倒数第k个节点.注意头节点为空,k<=0,k大于节点个数的情况. public ListNode find(ListNode head, int k){ if(h ...
- C Yuhao and a Parenthesis
Yuhao and a Parenthesis time limit per test 2 seconds memory limit per test 256 megabytes input stan ...