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 ...
随机推荐
- easyui-datagrid清空表中原有数据
$('#dg').datagrid('loadData', { total: 0, rows: [] });
- 关于 JS this
关于 JS this 1. this 与 普通函数 2. this 与 bind.call.apply 3. this 与 箭头函数 4. this 与 return 4.1 返回 引用对象 4.2 ...
- e.preventDefault()与e.stopPropagation()的区别
e.stopPropagation()阻止事件冒泡<table border='1'> <tr> <td><span>冒泡事件测试</span&g ...
- UCOS内存管理
STM32F10xxx内置64K字节的静态SRAM.它可以以字节.半字(16位)或全字(32位)访问 SRAM的起始地址是0x20000000 UCOSII //定义存储区 OS_MEM *DATA_ ...
- js 数组的深度拷贝 的四种实现方法
首先声明本人资质尚浅,本文只用于个人总结.如有错误,欢迎指正.共同提高. --------------------------------------------------------------- ...
- toString()和equals()方法详解
一:toString()方法 Object中toString方法 public String toString() { return getClass().getName() + "@&qu ...
- 使用awstats分析nginx日志
1.awstats介绍 本文主要是记录centos6.5下安装配置awstats,并统计nginx访问日志 1.1 awstats介绍 awstats是一款日志统计工具,它使用Perl语言编写,可统计 ...
- Linux下 启动tomcat 时候同时日志命令
./startup.sh && tail -f ../logs/catalina.out
- linux远程工具
实际工作中,linux系统都不会在我们自己的电脑上,linux系统安装在机房的服务器上,我们操作linux不可能跑到机房去,所以我们需要有一个工具,能在公司通过网络远程连接到机房的linux服务器上 ...
- 帝国CMS熊掌号数据主动推送插件【原创】
因为昨晚一个朋友他是帝国CMS做的网站,叫我给他做个熊掌号改造和熊掌号推送,所以花了一个小时时间做了这个插件,有需要的朋友可以拿去. 第一步:在后台执行以下数据库语句: CREATE TABLE `b ...