\(\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;
}

最新文章

  1. CYQ.Data V5 从入门到放弃ORM系列:教程 - Log、SysLogs两个日志类使用
  2. WiFi流量劫持—— JS脚本缓存投毒
  3. Mui沉浸模式以及状态栏颜色改变
  4. 关于node.js杂记
  5. 深入浅出 - Android系统移植与平台开发(十) - led HAL简单设计案例分析
  6. WPF中获得控件相对于控件的相对位置
  7. 【poj1144】 Network
  8. HDU 1394
  9. 重装linux后
  10. xmlBean学习一
  11. Python 资源
  12. 编译错误“The run destination My Mac 64-bit is not valid for Running the scheme &#39;***&#39;,解决办法
  13. VC6安装错误——Error Launching acmboot.exe
  14. NT路径,DOS路径和Device路径互相转换
  15. ARTS打卡计划第二周-Tips-mysql-binlog-connector-java的使用
  16. face recognition[MobiFace]
  17. 异步核心接口IAsyncResult的实现
  18. can协议
  19. 基于Spring-Boot框架的Elasticsearch搜索服务器配置
  20. vertx读取配置文件,获得端口号

热门文章

  1. mysql limit 数据重复及遗漏
  2. 解决mac pro 软件损坏
  3. 2.第一个Codefirst实例
  4. 理解Python中的继承规则和继承顺序
  5. 【leetcode】424. Longest Repeating Character Replacement
  6. &lt;Jmeter入门不放弃&gt;之&lt;3.两种常见录制脚本的方法&gt;
  7. Delphi正则表达式使用方法(TPerlRegEx)
  8. this与super的语法比较
  9. The Accomodation of Students HDU - 2444 二分图判定 + 二分图最大匹配 即二分图-安排房间
  10. Mysq sql语句教程