二次联通门 : LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力

/*
LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力 叫做计算几何
实则毒瘤数据结构 看到xor后
考虑Trie树
Trie树的每一个节点保存的是以当前子树中每个二进制位的个数 给Trie打一个全局xor标记,如果标记这一位是1,就交换它的两个儿子 另外维护一个前缀和
前缀和存的是没sort过的值的和
Trie维护的是sort之后的值 1操作直接在前缀和后加就好
2操作在前缀和和Trie树中一起查 */
#include <cstdio>
#include <iostream>
#define rg register
const int BUF = ; char Buf[BUF], *buf = Buf; typedef long long LL;
inline void read (int &n)
{
bool temp = false;
for (n = ; !isdigit (*buf); ++ buf) if (*buf == '-') temp = true;
for (; isdigit (*buf); n = n * + *buf - '', ++ buf);
if (temp) n = -n;
}
#define Max 200009
struct T_D { T_D *c[]; int s, thb[]; }; int s[Max][], v[Max];
int _T, _S, C, T;
class Trie
{
private : T_D poor[Max * ], *Tail, *Root, *null;
private :
inline T_D *New ()
{ T_D *now = Tail ++; now->c[] = now->c[] = null, now->s = ; return now; }
public :
Trie ()
{
Tail = poor, null = Tail ++, null->c[] = null->c[] = null;
null->s = , Root = New ();
}
void Insert (const int &k)
{
T_D *n = Root; ++ T;
for (rg int i = , j; i >= ; -- i)
{
if (n->c[(k >> i) & ] == null) n->c[(k >> i) & ] = New ();
n = n->c[(k >> i) & ], ++ n->s;
for (j = ; j <= ; ++ j) n->thb[j] += (k >> j) & ;
}
}
inline void P (const int &key)
{
v[++ C] = key;
for (rg int i = ; i <= ; ++ i) s[C][i] = s[C - ][i] + ((key >> i) & );
}
inline void ReBuild () { for (; C; Insert (v[C --])); _S = _T; }
LL Find (int k)
{
T_D *n = Root; LL r = ; rg int i, j;
for (i = ; i >= ; -- i)
{
if (k == ) break;
if (k < n->c[(_S >> i) & ]->s) n = n->c[(_S >> i) & ];
else
{
T_D *p = n->c[(_S >> i) & ]; k -= p->s;
for (j = ; j <= ; ++ j)
if ((_T >> j) & ) r += (LL) (p->s - p->thb[j]) << j;
else r += (LL) p->thb[j] << j;
n = n->c[(_S >> i) & ^ ];
}
}
for (i = ; i <= ; ++ i)
{
if (((_T >> i) & ) && n->thb[i] == ) r += (LL) k << i;
if (((_T >> i) & ) == && n->thb[i]) r += (LL) k << i;
}
return r;
}
LL Q (int k)
{
if (k <= T) return Find (k); LL r = Find (T); k -= T;
for (rg int i = ; i <= ; ++ i)
if ((_T >> i) & ) r += (LL) (k - s[k][i]) << i;
else r += (LL) s[k][i] << i;
return r;
}
void Cg (const int key) { _T ^= key; return ; }
} D;
int main (int argc, char *argv[])
{
fread (buf, , BUF, stdin); int N, M, x, t, y; read (N); rg int i;
for (i = ; i <= N; ++ i) read (x), D.P (x);
for (read (M); M; -- M)
{
read (t);
if (t == ) read (x), D.P (x ^ _T);
else if (t == )
read (x), read (y), printf ("%I64d\n", D.Q(y) - D.Q(x - ));
else if (t == ) read (x), D.Cg (x);
else D.ReBuild ();
}
return ;
}

LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力的更多相关文章

  1. [LOJ#517]. 「LibreOJ β Round #2」计算几何瞎暴力[trie]

    题意 题目链接 分析 记操作异或和为 \(tx\) ,最后一次排序时的异或和为 \(ax\) ,每个数插入时的 \(tx\) 记为 \(b\). 我们发现,一旦数列排序,就会变得容易操作. 对于新加入 ...

  2. 「LibreOJ β Round #2」计算几何瞎暴力

    https://loj.ac/problem/517 题解 首先我们如果没有排序这个骚操作的话,可以直接记一下各个数位的前缀和,然后异或标记给全局打,查询的时候先把区间信息提取出来然后整体异或就好了. ...

  3. LibreOJ #528. 「LibreOJ β Round #4」求和

    二次联通门 : LibreOJ #528. 「LibreOJ β Round #4」求和 /* LibreOJ #528. 「LibreOJ β Round #4」求和 题目要求的是有多少对数满足他们 ...

  4. LibreOJ #527. 「LibreOJ β Round #4」框架

    二次联通门 : LibreOJ #527. 「LibreOJ β Round #4」框架 /* LibreOJ #527. 「LibreOJ β Round #4」框架 %% xxy dalao 对于 ...

  5. LibreOJ #526. 「LibreOJ β Round #4」子集

    二次联通门 : LibreOJ #526. 「LibreOJ β Round #4」子集 /* LibreOJ #526. 「LibreOJ β Round #4」子集 考虑一下,若两个数奇偶性相同 ...

  6. LibreOJ #525. 「LibreOJ β Round #4」多项式

    二次联通门 : LibreOJ #525. 「LibreOJ β Round #4」多项式 官方题解 : /* LibreOJ #525. 「LibreOJ β Round #4」多项式 由于会有多种 ...

  7. LibreOJ #524. 「LibreOJ β Round #4」游戏

    二次联通门 : LibreOJ #524. 「LibreOJ β Round #4」游戏 /* LibreOJ #524. 「LibreOJ β Round #4」游戏 找找规律就会发现.. 当有X的 ...

  8. LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿

    二次联通门 : LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 /* LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 dp 记录一下前驱 ...

  9. LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律

    二次联通门 : LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 /* LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 set ...

随机推荐

  1. springboot 接口参数校验

    前言 在开发接口的时候,参数校验是必不可少的.参数的类型,长度等规则,在开发初期都应该由产品经理或者技术负责人等来约定.如果不对入参做校验,很有可能会因为一些不合法的参数而导致系统出现异常. 上一篇文 ...

  2. 解决vue-cli项目开发中跨域问题

    一.开发环境中跨域 使用 Vue-cli 创建的项目,开发地址是 localhost:8080,需要访问非本机上的接口http://10.1.0.34:8000/queryRole.不同域名之间的访问 ...

  3. 浅谈JS中 var let const 变量声明

    浅谈JS中 var let const 变量声明 用var来声明变量会出现的问题: 1. 允许重复的变量声明:导致数据被覆盖 2. 变量提升:怪异的数据访问.闭包问题 3. 全局变量挂载到全局对象:全 ...

  4. JavaScript实现网页回到顶部效果

    在浏览网页时,当我们浏览到网页底部,想要立刻回到网页顶部时,这时候一般网页会提供一个回到顶部的按钮来提升用户体验,以下代码实现了该功能 HTML代码: <p id="back-top& ...

  5. Django:实现读写分离

    库的配置 1.读写分离 settings配置 #settings.py 配置库信息,生成2个库 DATABASES = { 'default': { 'ENGINE': 'django.db.back ...

  6. 【vue】vue生命周期---精简易懂-----【XUEBIG】

    主要的生命周期函数分类:    - 创建期间的生命周期函数:(只会调用一次)       + beforeCreate:实例刚在内存中被创建出来,此时,还没有初始化好 data 和 methods 属 ...

  7. [Java] Eclipse中复制全限定名(Copy Qualified Name)的效果

    在Eclipse中,使用“ Copy Qualified Name”复制类的全限定名有两种效果: (1)选中工程上的java文件,右键 - Copy Qualified Name 复制的效果是带斜杠的 ...

  8. SpringBoot2.x项目初始化

    1. 项目初始化说明 使用SpringBoot生成器 修改application.properties为application.yml 启动运行SpringBoot项目 2. 初始化项目 Spring ...

  9. 注入 Istio sidecar

    注入 Istio sidecar 网格中的每个 Pod 都必须伴随一个 Istio 兼容的 Sidecar 一同运行. 下文中将会介绍两种把 Sidecar 注入到 Pod 中的方法:使用 istio ...

  10. angularcli 第八篇(router 路由)

    更多详细:https://segmentfault.com/a/1190000009265310 一.标题:页面有两个按钮(test1.test2),点击这两个按钮,跳转相应页面~ 注:可直接创建一个 ...