\(\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. 第10篇用 ConfigMap 管理配置

        一.ConfigMap介绍管理配置: ConfigMap介绍 Secret 可以为 Pod 提供密码.Token.私钥等敏感数据:对于一些非敏感数据,比如应用的配置信息,则可以用 Config ...

  2. reduce 好东西

    reduce()方法可以搞定的东西,for循环,或者forEach方法有时候也可以搞定,那为啥要用reduce()?这个问题,之前我也想过,要说原因还真找不到,唯一能找到的是:通往成功的道路有很多,但 ...

  3. webpack 学习三 模式

    开发环境(development)和生产环境(production)的构建目标差异很大.在开发环境中,我们需要具有强大的.具有实时重新加载(live reloading)或热模块替换(hot modu ...

  4. anaconda3创建py2环境

    查看conda的py环境conda info -e # 创建一个名为python34的环境,指定Python版本是3.4(创建py27操作一样)conda create -n py34 python= ...

  5. MAS(转)

    1.为什么要使用微服务? 要说为什么要使用微服务,我们要先说下传统的企业架构模式-垂直架构/单块架构模式,简单点说:我们一般将系统分为三层架构,但是这是逻辑上的三层,而非物理上的三层,这就意味着经过编 ...

  6. css雪碧图实现数字切换

    vue中 css 雪碧图应用及数字切换demo 1. CSS Sprites一般只能使用到固定大小的盒子(box)里,这样才能够遮挡住不应该看到的部分. 2.使用css雪碧图的优点: 利用CSS Sp ...

  7. linux 应用层常用API/命令

    一 API 1. bsearch NAME bsearch - binary search of a sorted array SYNOPSIS #include <stdlib.h> v ...

  8. UVa 548 Tree (建树+前序后序)

    Description You are to determine the value of the leaf node in a given binary tree that is the termi ...

  9. 二.通过jenkins对系统的监控(1)

    说明:通过jenkins定时请求系统,判断系统是否挂了. 注:windows环境 1.新建一个自由风格的项目. 2.构建触发器选择定时构建. 3.执行windows批处理命令 4.构建后操作,发邮件 ...

  10. JS 常用字符串,数组操作

    JavaScript String/Array对象 JS String对象   String 对象属性 属性 描述 constructor 对创建该对象的函数的引用 length 字符串的长度 pro ...