BZOJ 4571: [Scoi2016]美味
二次联通门 : BZOJ 4571: [Scoi2016]美味
/*
BZOJ 4571: [Scoi2016]美味 dalao们都在说这题如果没有加法balabala就可以用可持久化trie解决了
然而我连那个也不会啊QAQ 此题用主席树
从高位到低位贪心
能填1就填1,也就是查询一段区间有没有某个范围的数
(然而由乃dalao说可持久化线段树和可持久化trie是一个东西)
*/
#include <cstdio>
#include <iostream>
#include <cstring> const int BUF = ;
char Buf[BUF], *buf = Buf; inline void read (int &now)
{
for (now = ; !isdigit (*buf); ++ buf);
for (; isdigit (*buf); now = now * + *buf - '', ++ buf);
} const int _L = ( << ) - ;
#define Max 200010
int root[Max * ], c[Max], S;
inline int max (int a, int b) { return a > b ? a : b; }
class President_Tree
{
private : int tree[Max * ][], size[Max * ];
int T_C; public : President_Tree () { T_C = ; }
void Change (int &now, int last, int l, int r, int key)
{
now = ++ T_C;
memcpy (tree[now], tree[last], sizeof tree[now]);
size[now] = size[last] + ;
if (l == r) return ;
int Mid = l + r >> ;
if (key <= Mid)
Change (tree[now][], tree[last][], l, Mid, key);
else Change (tree[now][], tree[last][], Mid + , r, key);
} int Query (int l, int r, int b, int x, int L, int R)
{
if (l == r) return b ^ l;
int Mid = l + r >> ; -- S;
if (b & ( << S))
{
if (Q (L, R , , _L, max (, l - x), max (, Mid - x)))
return Query (l, Mid, b, x, L, R);
else return Query (Mid + , r, b, x, L, R);
}
else
{
if (Q (L, R, , _L, max (, Mid + - x), max (, r - x)))
return Query (Mid + , r, b, x, L, R);
else return Query (l, Mid, b, x, L, R);
}
} int Q (int L, int R, int x, int y, int l, int r)
{
if (x == l && y == r) return size[R] - size[L];
int Mid = x + y >> ;
if (r <= Mid)
return Q (tree[L][], tree[R][], x, Mid, l, r);
else if (l > Mid)
return Q (tree[L][], tree[R][], Mid + , y, l, r);
else
return Q (tree[L][], tree[R][], x, Mid, l, Mid) + Q (tree[L][], tree[R][], Mid + , y, Mid + , r);
}
};
President_Tree Tree; int Main ()
{
fread (buf, , BUF, stdin);
int N, M; register int i, j; read (N), read (M);
int x, b, l, r;
for (i = ; i <= N; ++ i)
read (c[i]), Tree.Change (root[i], root[i - ], , _L, c[i]); for (i = ; i <= M; ++ i)
{
read (b), read (x), read (l), read (r); S = ;
printf ("%d\n", Tree.Query (, _L, b, x, root[l - ], root[r]));
}
return ;
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {;}
BZOJ 4571: [Scoi2016]美味的更多相关文章
- bzoj 4571: [Scoi2016]美味 (主席树)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 题面; 4571: [Scoi2016]美味 Time Limit: 30 Sec ...
- bzoj 4571 [Scoi2016]美味——主席树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 按位考虑,需要的就是一个区间:比如最高位就是(2^k -x). 对于不是最高位的位置该 ...
- BZOJ.4571.[SCOI2016]美味(主席树 贪心)
题目链接 要求 \(b\ xor\ (a_j+x)\) 最大,应让 \(a_j+x\) 的最高位尽可能与b相反.带个减法Trie树好像很难做?反正我不会. 从最高位开始,如果这位b是0/1,判断是否存 ...
- bzoj4571: [Scoi2016]美味
4571: [Scoi2016]美味 Time Limit: 30 Sec Memory Limit: 256 MB Submit: 275 Solved: 141 [Submit][Status][ ...
- 【bzoj4571&&SCOI2016美味】
4571: [Scoi2016]美味 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 656 Solved: 350[Submit][Status][ ...
- bzoj [Scoi2016]美味
[Scoi2016]美味 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 721 Solved: 391[Submit][Status][Discus ...
- [洛谷P3293] [SCOI2016]美味
洛谷题目链接:[SCOI2016]美味 题目描述 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1<=i<=n).有 m 位顾客,第 i 位顾客的期望值为 ...
- 【BZOJ4571】[Scoi2016]美味 主席树
[BZOJ4571][Scoi2016]美味 Description 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1≤i≤n).有 m 位顾客,第 i 位顾客的期望值 ...
- BZOJ 4570: [Scoi2016]妖怪
二次联通门 : BZOJ 4570: [Scoi2016]妖怪 二次联通门 : luogu P3291 [SCOI2016]妖怪 LibreOJ : LibreOJ #2015. 「SCOI2016 ...
随机推荐
- Docker2 docker commit方法镜像制作
一.前期准备 1.下载一个centos镜像,进入容器,安装wget docker pull centos docker run -it centos bash [root@web1 ~]# docke ...
- 线程池ThreadPool实战
线程池ThreadPool 线程池概念 常用线程池和方法 1.测试线程类 2.newFixedThreadPool固定线程池 3.newSingleThreadExecutor单线程池 4.newCa ...
- 深入理解JVM(四) -- 垃圾内存回收的判定方法和内容
上一篇文章我们学到了对象在内存中是如何存储的已经是如何被访问的,这篇文章将介绍当内存空间不够时,虚拟机将怎样判定对象可不可以被回收已经哪些地方会发生回收. 垃圾回收主要(不是全部)发生在堆内存中,当一 ...
- React Native 开发豆瓣评分(六)添加字体图标
添加依赖 yarn add react-native-vector-icons Link 依赖 react-native link react-native-vector-icons 使用默认字体图标 ...
- 74.js---移动端文章的瀑布流的实现。
移动端文章的瀑布流的实现. 1.首先在前端html页面已经通过PHP代码循环完全数据. 2.然后在js先全部隐藏,通过判断滑动到底部,每次加载一部分数据,直到数据全部显示完全. js代码: // ...
- 我与SAP成都研究院吴院长的二三事
这几天Jerry没怎么看手机,今天才注意到,昨天SAP中国研究院公众号上发布了一篇文章:SAP高管说: 体验经济时代下的SAP客户体验.仔细一看,这不是咱SAP成都研究院的吴院长么. 在今年没有发生部 ...
- 【idea】scala&sbt+idea安装配置与测试
一.IDEA安装 下载Community版的IDEA,Ultimate是免费试用版(相当于用到后面要给钱的) ideaIC-2019.2.3.tar.gz 解压IDEA: tar -zxvf idea ...
- array_reduce() 与 array_map()
相似部分: 二者同为 处理数组函数,可遍历 数组中的每一个元素, 对其通过 function callback(){} 处理. 不同处: 参数: array_reduce( array, callba ...
- 基于django的生成二维码的接口
原理就是在视图层写一个将数据生成二维码的视图函数: def generate_qrcode(request, data): img = qrcode.make(data) buf = BytesIO( ...
- 解决 Jumpserver coco 使用登录用户(ldap)进行SSH连接目标主机,忽略系统用户
前言 Jumpserver 作为国内流行的开源堡垒机,很多公司都在尝试使用,同时 Jumpserver 为了契合众多公司的用户认证,也提供了 LDAP 的用户认证方式,作为 Jumpserver 的用 ...