题目链接:Choosing The Commander


维护一个带删除的Trie,然后每次在Trie中找即可。

分别讨论一下。


AC代码:

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+10;
int t[N*30][2],idx,cnt[N*30],q;
inline void insert(int x,int v){int p=0;for(int i=26;i>=0;i--){int k=x>>i&1;if(!t[p][k])   t[p][k]=++idx;p=t[p][k];    cnt[p]+=v;}
}
int ask(int x,int y){int p=0,res=0;for(int i=26;i>=0;i--){if(y>>i&1){if(x>>i&1)  res+=cnt[t[p][1]],p=t[p][0];else res+=cnt[t[p][0]],p=t[p][1];}else{if(x>>i&1)   p=t[p][1];else p=t[p][0];}if(!cnt[p]) break;}return res;
}
signed main(){cin>>q;for(int i=1,op,p,l;i<=q;i++){scanf("%d %d",&op,&p);if(op==1)  insert(p,1);else if(op==2)    insert(p,-1);else scanf("%d",&l),printf("%d\n",ask(p,l));}return 0;
}

Codeforces - Choosing The Commander相关推荐

  1. Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或)

    Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或) 题意: 3种操作: 1 插入一个数 2 删除一个数 3 给出一个数 ...

  2. Educational Codeforces Round 23 E. Choosing The Commander 字典树

    题目连接:E. Choosing The Commander 题意:士兵有个值,指挥官有两个p,l三种操作,第一种添加一个值为p的士兵,第二种删除一个值为p的士兵,(士兵pi只会尊敬pi^p<l ...

  3. CF817E Choosing The Commander

    CF817E Choosing The Commander 题意: 有qqq次操作,每次操作有三种类型,分别是 1pi1 p_i1pi​把 pip_ipi​ 加入集合 SSS 2pi2 p_i2pi​ ...

  4. Codeforces - Choosing Capital for Treeland

    题目链接:Codeforces - Choosing Capital for Treeland 显然,如果确定首都之后,我们可以O(n)计算出这个点的答案. 然后这个东西可以换根吗?显然是可以的.换根 ...

  5. 树形DP——Codeforces Choosing Capital for Treeland

    http://codeforces.com/problemset/problem/219/D 题意:给一个n节点的有向无环图,要找一个这样的点:该点到其它n-1要逆转的道路最少,(边<u,v&g ...

  6. CF817E Choosing The Commander 01tire 贪心

    看到集合和异或,可以想到01tire(但是我没有想到). 让后就可以对于每次插入和删除一个数,都在01tire树上操作即可.让后记录一下到当前位(当然是从高位到低位啦)有相同前缀的数的个数.例如样例建 ...

  7. 【cf817E】Choosing The Commander

    第一次写字典树题,记录一下 #include<cstdio> #include<iostream> #include<cmath> #include<vect ...

  8. codeforces 794E Choosing Carrot

    目录 codeforces 794E Choosing Carrot 题意 题解 Code codeforces 794E Choosing Carrot 题目传送门 题意 给出一个长度为\(n\)的 ...

  9. Codeforces 1088E Ehab and a component choosing problem(树形DP)

    Codeforces 1088E Ehab and a component choosing problem(树形DP) 题意 给一棵树,要求从中选一些联通分量,使得平均联通分量重量总和最大.如果有多 ...

最新文章

  1. Android 标签 (FlexboxLayout实现标签)
  2. 从源码分析DEARGUI之动态绘图的两种方法
  3. 好消息,scott的asp.net 2.0数据导航系列全部出版了
  4. KMS Server相关资料
  5. Cisco ASA Web ××× 配置详解
  6. php自定义按钮,vue实现自定义按钮的方法介绍(附代码)
  7. 上百套HTML5登录页面模板
  8. 已解决IndentationError: unindent does not match any outer indentation level
  9. centos7.3根目录空间扩展
  10. 用计算机算出女儿身高,孩子身高预测计算器准吗
  11. vue支付项目-APP支付宝支付功能
  12. JAVA实现经典游戏俄罗斯方块
  13. 第十五周 项目一 (3)验证交换排序
  14. Java编程思想随笔
  15. 让手机支持OTG,不看绝对后悔! - 我也做一回搬运工,解决RFID读卡器OTG支持问题
  16. 【python量化交易学习】pandas获取mysql数据,使用pyecharts画K线图,ma移动均线。
  17. 各种中文分词工具的使用方法
  18. 卷积神经网络的网络结构——VGGNet
  19. 设备防病毒-深信达MCK(云私钥)
  20. Aspose.Pdf使用教程分享

热门文章

  1. Kafka(十一) 如何保证数据的不重复和不丢失
  2. ElementUI Tab 右边加按钮
  3. 苹果执行请求时出错_iOS网络请求错误整理
  4. 活动报名丨英伟达AI Lab科学家、GET3D一作高俊:从图像中学习3D对象的生成建模...
  5. 企业管理系统从五个方面改变传统办公
  6. MEDIATOR(中介者)模式
  7. 一个简单的FastAPI入门项目
  8. 配置NAT模式的网络连接
  9. css一行放不下省略号显示
  10. 接口调试插件RESTED使用post的方法