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 ...
随机推荐
- [LOJ6433] [PKUSC2018] 最大前缀和
题目链接 LOJ:https://loj.ac/problem/6433 Solution 注意到最大前缀要满足什么性质,假设序列\(a[1..n]\)的最大前缀是\(s_x\),那么显然要满足所有\ ...
- python ID3决策树实现
环境:ubuntu 16.04 python 3.6 数据来源:UCI wine_data(比较经典的酒数据) 决策树要点: 1. 如何确定分裂点(CART ID3 C4.5算法有着对应的分裂计算方式 ...
- ASP.NET面试题130道
130道ASP.NET面试题 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. ...
- SQL递归获取树型路径中文名称
项目中遇到一个树型结构表要根据任意传入节点获取它从根节点一直到自身节点的全部路径的中文名称,并且用'>'与分隔. 我使用在sqlServer中写了一个解析函数方便开发调用. USE [RP_ER ...
- Mongodb 学习笔记(二) :索引
Mongodb 是基于集合建立索引 (Index),索引的作用类似于传统关系型数据库,目的是为了提高查询速度 . 如果没有建立索引, Mongodb 在读取数据时必须扫描集合中的 所有文档记录. 这 ...
- JS函数的三种方式
函数,一段能够自动完成某些功能的代码块,函数的出现,既解决了重复使用重一功能的需求,又可以避免代码的臃肿性. 使用函数有两个要求:必须调用后才可以执行;函数名不要和关键字以及系统函数相同; 函数主要有 ...
- dom 页面位置和大小,元素的位置和大小,鼠标位置
dom里面三种跟位置相关的元素 页面位置和大小,元素的位置和大小,鼠标位置 ①window:位置(position):(screenLeft, screenTop) [(screenX, screen ...
- requests模块 简单使用
目录 requests模块 简单使用 Anaconda简单了解 简单了解 requests模块 使用requests模块 爬取搜狗首页源码数据 实现一个简易的网页采集器 解决乱码问题 解决UA检测问题 ...
- excel2016打开为空白界面解决办法
前言 excel2016打开文件为空白的界面,明显不正常. 解决方法 https://blog.csdn.net/b2345012/article/details/94134401 以上.
- Java System Reports
You use Java System Reports as a problem detection and analysis tool to: ● Monitor the AS Java ...