Codeforces - Choosing The Commander
题目链接:Choosing The Commander
#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相关推荐
- Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或)
Educational Codeforces Round 23:E. Choosing The Commander(字典树01异或) 题意: 3种操作: 1 插入一个数 2 删除一个数 3 给出一个数 ...
- Educational Codeforces Round 23 E. Choosing The Commander 字典树
题目连接:E. Choosing The Commander 题意:士兵有个值,指挥官有两个p,l三种操作,第一种添加一个值为p的士兵,第二种删除一个值为p的士兵,(士兵pi只会尊敬pi^p<l ...
- CF817E Choosing The Commander
CF817E Choosing The Commander 题意: 有qqq次操作,每次操作有三种类型,分别是 1pi1 p_i1pi把 pip_ipi 加入集合 SSS 2pi2 p_i2pi ...
- Codeforces - Choosing Capital for Treeland
题目链接:Codeforces - Choosing Capital for Treeland 显然,如果确定首都之后,我们可以O(n)计算出这个点的答案. 然后这个东西可以换根吗?显然是可以的.换根 ...
- 树形DP——Codeforces Choosing Capital for Treeland
http://codeforces.com/problemset/problem/219/D 题意:给一个n节点的有向无环图,要找一个这样的点:该点到其它n-1要逆转的道路最少,(边<u,v&g ...
- CF817E Choosing The Commander 01tire 贪心
看到集合和异或,可以想到01tire(但是我没有想到). 让后就可以对于每次插入和删除一个数,都在01tire树上操作即可.让后记录一下到当前位(当然是从高位到低位啦)有相同前缀的数的个数.例如样例建 ...
- 【cf817E】Choosing The Commander
第一次写字典树题,记录一下 #include<cstdio> #include<iostream> #include<cmath> #include<vect ...
- codeforces 794E Choosing Carrot
目录 codeforces 794E Choosing Carrot 题意 题解 Code codeforces 794E Choosing Carrot 题目传送门 题意 给出一个长度为\(n\)的 ...
- Codeforces 1088E Ehab and a component choosing problem(树形DP)
Codeforces 1088E Ehab and a component choosing problem(树形DP) 题意 给一棵树,要求从中选一些联通分量,使得平均联通分量重量总和最大.如果有多 ...
最新文章
- Android 标签 (FlexboxLayout实现标签)
- 从源码分析DEARGUI之动态绘图的两种方法
- 好消息,scott的asp.net 2.0数据导航系列全部出版了
- KMS Server相关资料
- Cisco ASA Web ××× 配置详解
- php自定义按钮,vue实现自定义按钮的方法介绍(附代码)
- 上百套HTML5登录页面模板
- 已解决IndentationError: unindent does not match any outer indentation level
- centos7.3根目录空间扩展
- 用计算机算出女儿身高,孩子身高预测计算器准吗
- vue支付项目-APP支付宝支付功能
- JAVA实现经典游戏俄罗斯方块
- 第十五周 项目一 (3)验证交换排序
- Java编程思想随笔
- 让手机支持OTG,不看绝对后悔! - 我也做一回搬运工,解决RFID读卡器OTG支持问题
- 【python量化交易学习】pandas获取mysql数据,使用pyecharts画K线图,ma移动均线。
- 各种中文分词工具的使用方法
- 卷积神经网络的网络结构——VGGNet
- 设备防病毒-深信达MCK(云私钥)
- Aspose.Pdf使用教程分享