\(\mathtt{CF817E}\)

\(\mathcal{Description}\)

有 \(q\) 个操作\((1 \leq q \leq 10^{5})\):

1、加入一个数 \(p_i(1 \leq p_i \leq 10 ^ 8)\)

2、删去一个数 \(p_i(1 \leq p_i \leq 10 ^ 8)\)

3、询问集合中有多少数异或 \(p_i\) 后的值小于 \(l_i(1 \leq p_i,l_i \leq 10 ^ 8)\)

\(\mathcal{Solution}\)

第三种操作询问异或后的值,于是自然而然可以想到用 \(01trie\),所以可以把 \(p_i\) 插入到字典树内,\(1\) 操作是 \(+1\),\(2\) 操作就是 \(-1\),\(3\)操作询问是,把 \(p_i\) 的值遍历一遍,如果当前的位上是 \(0\),把指针转到 \(p_j\) 的位上,否则加上这个位上的数,把指针转到另一边。

\(\mathcal{Code}\)

#include<bits/stdc++.h>
#define pow(x, i) (x >> i)
using namespace std; const int N = 6e6 + 10, M = 30; int cnt[N], trie[N][2], tot = 1, n; inline int read() {
int x = 0, k = 1; char c = getchar();
for (; c < 48 || c > 57; c = getchar()) k ^= (c == '-');
for (; c >= 48 && c <= 57; c = getchar()) x = x * 10 + (c ^ 48);
return k ? x : -x;
} inline void add(int x, int dg) {
int p = 1;
for (int i = M; i >= 0; --i) {
if (dg == 1) trie[p][(pow(x, i) & 1)] = (trie[p][(pow(x, i) & 1)] != 0) ? trie[p][(pow(x, i) & 1)] : (++tot);
p = trie[p][(pow(x, i) & 1)], cnt[p] += dg;
}
} inline int ask(int x, int y) {
int p = 1;
int sum = 0;
for (int i = M; i >= 0; i--) {
int t = (pow(y, i) & 1), t1 = (pow(x, i) & 1);
if (t)
sum += cnt[trie[p][t1]], p = trie[p][t1 ^ 1];
else
p = trie[p][t1];
}
return sum;
} int main() {
n = read();
while (n--) {
int opt = read(), x = read();
if (opt == 1)
add(x, 1);
else if (opt == 2)
add(x, -1);
else if (opt == 3) {
int y = read();
printf("%d\n", ask(x, y));
}
}
return 0;
}

CF817E Choosing The Commander的更多相关文章

  1. Educational Codeforces Round 23 E. Choosing The Commander trie数

    E. Choosing The Commander time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Choosing The Commander CodeForces - 817E (01字典树+思维)

    As you might remember from the previous round, Vova is currently playing a strategic game known as R ...

  3. 817E. Choosing The Commander trie字典树

    LINK 题意:现有3种操作 加入一个值,删除一个值,询问pi^x<k的个数 思路:很像以前lightoj上写过的01异或的字典树,用字典树维护数求异或值即可 /** @Date : 2017- ...

  4. 01-trie练习

    这里用递归实现01-trie, 可以看做是区间长度为2的幂的权值线段树, 能实现权值的所有操作, 异或时, 翻转左右儿子即可. 练习1 CF 817E Choosing The Commander 大 ...

  5. Educational Codeforces Round 23 A-F 补题

    A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...

  6. Total Commander 8.52 Beta 1

    Total Commander 8.52 Beta 1http://www.ghisler.com/852_b1.php 10.08.15 Release Total Commander 8.52 b ...

  7. CF219D. Choosing Capital for Treeland [树形DP]

    D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...

  8. 如何修改Total Commander配件文件的位置

    今天测试了一下Total Commander最新版的安装文件,测试完成后,并删除.结果导致原先一直在使用的绿色版的Total Comander配件文件变成了测试的配件文件,导致许多配置都丢失了,因此不 ...

  9. 【荐1】Total Commander 7.57 个人使用设置 及 常用快捷键 备忘

    Total Commander 7.57a  下载地址:http://www.baidu.com/s?wd=total commander 7.57 破解版 软件整体预览图:(注意,下面的版本我用的是 ...

随机推荐

  1. Linux下tree的使用介绍

    1.在ubuntu系统中默认是没有tree这个命令的,需要安装,用下面的命令就可以安装tree这个命令工具sudo apt-get install tree. 2.首先来说说使用tree这个命令,就是 ...

  2. windows 安装 jenkins笔记

    Jenkins 所有镜像列表: http://mirrors.jenkins-ci.org/status.html 可在镜像网站上下载安装文件,比官方下载快些 jenkins 官网地址: https: ...

  3. go(一)基础知识

    一.第一个程序 基本程序结构 package main // 包 import "fmt" // 引入依赖代码 // 功能实现 func main() { fmt.Println( ...

  4. 二叉树入门(洛谷P1305)

    题目描述 输入一串完全二叉树,用遍历前序打出. 输入输出格式 输入格式: 第一行为二叉树的节点数n. 后面n行,每一个字母为节点,后两个字母分别为其左右儿子. 空节点用*表示 输出格式: 前序排列的完 ...

  5. 在ios微信中提交form,php端收不到参数的问题

    今天做h5页面时,微信浏览器中提交form表单,发现php端收不到post过来的参数,在普通浏览器中可以,安卓微信也可以,$_POST,$_GET,$_REQUEST等方式都不行. 后来,把form表 ...

  6. 《ArcGIS Runtime SDK for .NET开发笔记》--三维功能

    介绍 在ArcGIS Runtim SDK for .NET 10.2.6中,新添加了三维地图功能.在ArcGIS中,我们将三维地图称为Scene(场景),所以在Runtime SDK SDK for ...

  7. leetcode中的一些二分搜索树

    235(最近公共祖先) /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left ...

  8. vue轮播,展示pdf

    vue轮播,展示pdf 根据左侧图片格式,右侧展示相应的pdf文件与图片.(vue中不支持pdf格式,pdf文件要放在static文件里):代码如下: <template> <!-- ...

  9. Module not found: Error: Can't resolve '@babel/runtime/helpers/classCallCheck' and Module not found: Error: Can't resolve '@babel/runtime/helpers/defineProperty'

    These two mistakes are really just one mistake, This is because the following file @babel/runtime ca ...

  10. shell编程:函数的返回值

    函数的返回值两种形式 return 0-255 0表示成功,1-255表示失败-------通常用于判断 echo 返回一个字符串------------通常用于返回一个执行的结果 return.sh ...