二次联通门 : 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. centos7 挂载未分配的硬盘空间

    =============================================== 2019/7/28_第1次修改                       ccb_warlock == ...

  2. 【leetcode-97 动态规划】 交错字符串

    (1过,调试很久) 给定三个字符串 s1, s2, s3, 验证 s3 是否是由 s1 和 s2 交错组成的. 示例 1: 输入: s1 = "aabcc", s2 = " ...

  3. cas sso docker部署service

    cas协议: 1. 拉取镜像 docker pull apereo/cas:${tag} 2. 启动容器 docker run --name cas -p : -p : apereo/cas:v5.3 ...

  4. spring使用JUnit测试,@Autowired无法注入原因

    在测试类上加入配置文件 代码如下 @RunWith(SpringJUnit4ClassRunner.class)// SpringJUnit支持,由此引入Spring-Test框架支持!  @Cont ...

  5. python 3.url了解与基础使用

    URL使用 视图: 我们运行项目在网页上查看到的我们称之为视图 视图一般在views.py下编辑 它的第一个参数永远都是request,通过它请求一些数据返回给网页给我们查看. 视图函数的返回结果必须 ...

  6. Android为TV端助力之QQ空间热更新技术

    直接上代码 package com.enjoy.patch; import android.content.Context;import android.os.Build;import android ...

  7. nginx小结

    1.nginx下部署网站 网站为:http://10.1.75.177:8000 nginx端口为80 配置如下: user nginx; worker_processes auto; error_l ...

  8. windows mysql 5.5.62 安装

    下载链接: https://dev.mysql.com/downloads/installer/ mysql下载这边有句话,虽然是32位的安装包,但是可以装在32位和64位上. 建议迅雷下载. 然后打 ...

  9. day 10 预科

    目录 IPO 编程 面向对象编程 类和对象 对象 类 定义类 定义对象 定义类语法 定义对象 (实例化对象) 定制对象独有特征 LeetCode检测机制 面向过程编程:面向(对着)-->过程(流 ...

  10. MySQL MHA候选主库选择

    MHA在选择新主库时,会将所有存活的从库分为下面几类: 存活从库数组:挑选所有存活的从库 最新从库数组: 挑选Master_Log_File+Read_Master_Log_Pos最高的从库 优选从库 ...