二次联通门 : 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]美味的更多相关文章

  1. bzoj 4571: [Scoi2016]美味 (主席树)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 题面; 4571: [Scoi2016]美味 Time Limit: 30 Sec   ...

  2. bzoj 4571 [Scoi2016]美味——主席树

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4571 按位考虑,需要的就是一个区间:比如最高位就是(2^k -x). 对于不是最高位的位置该 ...

  3. BZOJ.4571.[SCOI2016]美味(主席树 贪心)

    题目链接 要求 \(b\ xor\ (a_j+x)\) 最大,应让 \(a_j+x\) 的最高位尽可能与b相反.带个减法Trie树好像很难做?反正我不会. 从最高位开始,如果这位b是0/1,判断是否存 ...

  4. bzoj4571: [Scoi2016]美味

    4571: [Scoi2016]美味 Time Limit: 30 Sec Memory Limit: 256 MB Submit: 275 Solved: 141 [Submit][Status][ ...

  5. 【bzoj4571&&SCOI2016美味】

    4571: [Scoi2016]美味 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 656  Solved: 350[Submit][Status][ ...

  6. bzoj [Scoi2016]美味

    [Scoi2016]美味 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 721  Solved: 391[Submit][Status][Discus ...

  7. [洛谷P3293] [SCOI2016]美味

    洛谷题目链接:[SCOI2016]美味 题目描述 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1<=i<=n).有 m 位顾客,第 i 位顾客的期望值为 ...

  8. 【BZOJ4571】[Scoi2016]美味 主席树

    [BZOJ4571][Scoi2016]美味 Description 一家餐厅有 n 道菜,编号 1...n ,大家对第 i 道菜的评价值为 ai(1≤i≤n).有 m 位顾客,第 i 位顾客的期望值 ...

  9. BZOJ 4570: [Scoi2016]妖怪

    二次联通门 : BZOJ 4570: [Scoi2016]妖怪 二次联通门 : luogu P3291 [SCOI2016]妖怪 LibreOJ : LibreOJ  #2015. 「SCOI2016 ...

随机推荐

  1. 「APIO2016」烟花表演

    「APIO2016」烟花表演 解题思路 又是一道 solpe trick 题,观察出图像变化后不找一些性质还是挺难做的. 首先令 \(dp[u][i]\) 为节点 \(u\) 极其子树所有叶子到 \( ...

  2. 【转载】Windows安装Redis并添加本地自启动服务

    概况 在windows本地搭建redis缓存,添加到本地计算机的服务中,保证每次开机自动启动服务. 第一步:下载redis(我的是计算机win10,64位) https://github.com/Mi ...

  3. Java 解决Emoji表情过滤问题(转载)

    本文作者 我是周洲 原文链接 https://blog.csdn.net/u012904383/article/details/79376707 本人使用的是第三种引入jar的方法 问题: Emoji ...

  4. Java 之 web服务器—Tomcat

    一.服务器 1.服务器 服务器:安装了服务器软件的计算机 2.服务器软件 服务器软件:接收用户的请求,处理请求,做出响应 3.Web 服务器软件 web 服务器软件:接收用户的请求,处理请求,做出响应 ...

  5. orangepi自启动打开一个终端并且运行脚本

    第一步: 在 /home/pi/.config 下创建一个文件夹,名称为 autostart,如果已经存在则不需要创建 第二步: 在autostart文件夹中创建桌面启动项文件,(文件名以 .desk ...

  6. vue项目配置Mock.js

    扯在前面 最近一直在忙跳槽的事情,博客也好久没有更新了,上次更新还是去年,不出意外的话,从今天起继续今年的博客之旅. 今天继续完善我之前的项目架构,从零开始搭建vue移动端项目到上线,有需要的同学可以 ...

  7. redis 异常 MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk

    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. 解决方 ...

  8. Android Exception Hook

    承接上一篇文章Android Inline Hook,接下来我们看一下android系统中基于异常的hook方式,这种方式与inline hook相比实现较为简单,但执行效率是它的短板. except ...

  9. Java注解annotation : invalid type of annotation member

    前言 首先,关于注解的介绍就不多描述了,网上有很多这方面的资料.本文主要是介绍如何处理标题中遇到的问题:invalid type of annotation member ? 正文 Annotatio ...

  10. CF: Long Number

                                                    题目链接 #include<iostream> #include<string> ...