LibreOJ #517. 「LibreOJ β Round #2」计算几何瞎暴力
二次联通门 : 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」计算几何瞎暴力的更多相关文章
- [LOJ#517]. 「LibreOJ β Round #2」计算几何瞎暴力[trie]
题意 题目链接 分析 记操作异或和为 \(tx\) ,最后一次排序时的异或和为 \(ax\) ,每个数插入时的 \(tx\) 记为 \(b\). 我们发现,一旦数列排序,就会变得容易操作. 对于新加入 ...
- 「LibreOJ β Round #2」计算几何瞎暴力
https://loj.ac/problem/517 题解 首先我们如果没有排序这个骚操作的话,可以直接记一下各个数位的前缀和,然后异或标记给全局打,查询的时候先把区间信息提取出来然后整体异或就好了. ...
- LibreOJ #528. 「LibreOJ β Round #4」求和
二次联通门 : LibreOJ #528. 「LibreOJ β Round #4」求和 /* LibreOJ #528. 「LibreOJ β Round #4」求和 题目要求的是有多少对数满足他们 ...
- LibreOJ #527. 「LibreOJ β Round #4」框架
二次联通门 : LibreOJ #527. 「LibreOJ β Round #4」框架 /* LibreOJ #527. 「LibreOJ β Round #4」框架 %% xxy dalao 对于 ...
- LibreOJ #526. 「LibreOJ β Round #4」子集
二次联通门 : LibreOJ #526. 「LibreOJ β Round #4」子集 /* LibreOJ #526. 「LibreOJ β Round #4」子集 考虑一下,若两个数奇偶性相同 ...
- LibreOJ #525. 「LibreOJ β Round #4」多项式
二次联通门 : LibreOJ #525. 「LibreOJ β Round #4」多项式 官方题解 : /* LibreOJ #525. 「LibreOJ β Round #4」多项式 由于会有多种 ...
- LibreOJ #524. 「LibreOJ β Round #4」游戏
二次联通门 : LibreOJ #524. 「LibreOJ β Round #4」游戏 /* LibreOJ #524. 「LibreOJ β Round #4」游戏 找找规律就会发现.. 当有X的 ...
- LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿
二次联通门 : LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 /* LibreOJ #507. 「LibreOJ NOI Round #1」接竹竿 dp 记录一下前驱 ...
- LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律
二次联通门 : LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 /* LibreOJ #516. 「LibreOJ β Round #2」DP 一般看规律 set ...
随机推荐
- 【解决方案】ArcGIS导入要素集后没反应
内容源自:ArcGIS10.2基础教程(丁华) 书上要求: 1.在“练习”文件夹中新建一个名为“沈阳”的个人地理数据库和名为“shenyang”的要素集,设置地理坐标为“Xi'an 1980”,高程坐 ...
- 使用HttpClient调用接口
一,编写返回对象 public class HttpResult { // 响应的状态码 private int code; // 响应的响应体 private String body;get/set ...
- Apple SIP简介及在Clover中如何控制
Apple SIP简介及在Clover中如何控制 来源 http://www.yekki.me/apple-sip-overview-and-how-to-disable-it-in-clover/ ...
- springCloud学习3(Netflix Hystrix弹性客户端)
springcloud 总集:https://www.tapme.top/blog/detail/2019-02-28-11-33 本次用到全部代码见文章最下方. 一.为什么要有客户端弹性模式 所 ...
- 约束布局ConstraintLayout
Android新特性介绍,ConstraintLayout完全解析 约束布局ConstraintLayout用法全解析 约束布局ConstraintLayout看这一篇就够了
- 什么影响了mysql的性能-硬件资源及系统方面优化
随着数据量的增大,数据库的性能问题也是个值得关注的问题,很多公司对mysql性能方面没有太过重视,导致服务浪费过多资源.mysql服务性能差从而直接影响用户体验,这里我们简单的先来聊聊什么影响了mys ...
- Codeforces C. Jzzhu and Cities(dijkstra最短路)
题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Tensorflow简单实践系列(一):安装和运行
TensorFlow 是谷歌开发的机器学习框架. 安装 TensorFlow 直接使用 pip 安装即可,添加豆瓣镜像可以加快速度: pip install tensorflow -i https:/ ...
- 账户(/etc/passwd、/etc/shadow)与组(/etc/group、/etc/gshadow)文件解析
1. 账户信息文件 账户信息被保存在 /etc/passwd 文件中,通过命令 cat /etc/passwd 查看文件内容如下: [root@192 ~]# cat /etc/passwdroot: ...
- Vue 项目中 ESlint 配置
前言 对于 ESlint 这一块一直存在一些疑问,今天看到一个文章内容挺好的,这里拿来了. 一.eslint 安装 1.全局安装 npm i -g eslint 全局安装的好处是,在任何项目我们都可以 ...