二次联通门 : 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 ;
}

最新文章

  1. PermGen space
  2. MySQL 联合索引详解
  3. NLog的使用
  4. oracle触发器加条件判断、dblink
  5. win7 共享问题,&quot;您可能没有权限使用网络资源&quot;
  6. RPM 包下载 GCC 4.8安装
  7. Cacti Install
  8. Iterator之java.util.ConcurrentModificationException
  9. JBPM4入门——6.流程实例的创建和执行
  10. createSQLQuery与createQuery的区别
  11. FFMPEG-数据结构解释(AVCodecContext,AVStream,AVFormatContext)
  12. git语言
  13. H5的新应用-指定视频的播放进度
  14. Kendo UI使用笔记
  15. android 删除相册图片并同步到图库
  16. spring boot 2.0 集成 shiro 和 pac4j cas单点登录
  17. sqlserver CLR sqlserver使用C# dll
  18. select * 和select 所有字段的区别
  19. 在CentOS6的上安装Windows2012R2的KVM虚拟机
  20. 使用Simple MvvmToolkit开发Android和iOS程序

热门文章

  1. webpack+vue-cil跨域配置接口地址代理
  2. nginx服务的基本配置
  3. C#操作mongodb(聚合函数)-分组找出每组的最大值
  4. 05-jQuery介绍
  5. 使用jquery.datatable.js注意事项
  6. 改变默认的多选框 checkbox 样式~
  7. 基于TCP通过socketserver简单实现并发效果
  8. 外部服务发现-ingress
  9. MySQL/MariaDB数据库的主从级联复制
  10. Android打包遇到的问题