Educational Codeforces Round 23 E. Choosing The Commander trie数
2 seconds
256 megabytes
standard input
standard output
As you might remember from the previous round, Vova is currently playing a strategic game known as Rage of Empires.
Vova managed to build a large army, but forgot about the main person in the army - the commander. So he tries to hire a commander, and he wants to choose the person who will be respected by warriors.
Each warrior is represented by his personality — an integer number pi. Each commander has two characteristics — his personality pj and leadership lj (both are integer numbers). Warrior i respects commander j only if
(
is the bitwise excluding OR of x and y).
Initially Vova's army is empty. There are three different types of events that can happen with the army:
- 1 pi — one warrior with personality pi joins Vova's army;
- 2 pi — one warrior with personality pi leaves Vova's army;
- 3 pi li — Vova tries to hire a commander with personality pi and leadership li.
For each event of the third type Vova wants to know how many warriors (counting only those who joined the army and haven't left yet) respect the commander he tries to hire.
The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events.
Then q lines follow. Each line describes the event:
- 1 pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army;
- 2 pi (1 ≤ pi ≤ 108) — one warrior with personality pi leaves Vova's army (it is guaranteed that there is at least one such warrior in Vova's army by this moment);
- 3 pi li (1 ≤ pi, li ≤ 108) — Vova tries to hire a commander with personality pi and leadership li. There is at least one event of this type.
For each event of the third type print one integer — the number of warriors who respect the commander Vova tries to hire in the event.
5
1 3
1 4
3 6 3
2 4
3 6 3
1
0
In the example the army consists of two warriors with personalities 3 and 4 after first two events. Then Vova tries to hire a commander with personality 6 and leadership 3, and only one warrior respects him (
, and 2 < 3, but
, and 5 ≥ 3). Then warrior with personality 4 leaves, and when Vova tries to hire that commander again, there are no warriors who respect him.
题意:1增加一个数,2删除一个数,3求所有数^k<l的个数
思路:trie数,按位贪心即可;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<bitset>
#include<time.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-4
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e6+,M=4e6+,inf=,mod=1e9+;
const LL INF=1e18+,MOD=1e9+; int a[M][],sum[M],len;
void insertt(int x)
{
int num[];
memset(num,,sizeof(num));
int flag=;
while(x)
{
num[flag++]=x%;
x/=;
}
int u=,n=;
for(int i=n; i>=; i--)
{
if(!a[u][num[i]])a[u][num[i]]=++len;
u=a[u][num[i]];
sum[u]++;
}
}
void del(int x)
{
int num[];
memset(num,,sizeof(num));
int flag=;
while(x)
{
num[flag++]=x%;
x/=;
}
int u=,n=;
for(int i=n; i>=; i--)
{
if(!a[u][num[i]])a[u][num[i]]=++len;
u=a[u][num[i]];
sum[u]--;
}
} int getans(int x,int z)
{
int num[],flag=;
memset(num,,sizeof(num));
while(x)
{
num[flag++]=x%;
x/=;
}
int l[];flag=;
memset(l,,sizeof(l));
while(z)
{
l[flag++]=z%;
z/=;
}
int u=,n=;
int ans=;
for(int i=n;i>=;i--)
{
if(l[i]==)
{
if(!a[u][num[i]])break;
u=a[u][num[i]];
}
else
{
if(a[u][num[i]])
ans+=sum[a[u][num[i]]];
if(!a[u][!num[i]])break;
u=a[u][!num[i]];
}
}
return ans;
} int main()
{
int q;
scanf("%d",&q);
while(q--)
{
int t,p;
scanf("%d%d",&t,&p);
if(t==)insertt(p);
else if(t==)del(p);
else
{
int x;
scanf("%d",&x);
printf("%d\n",getans(p,x));
}
}
return ;
}
Educational Codeforces Round 23 E. Choosing The Commander trie数的更多相关文章
- Educational Codeforces Round 23 A-F 补题
A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...
- Educational Codeforces Round 23.C
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 23 B. Makes And The Product
B. Makes And The Product time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 23 F. MEX Queries 离散化+线段树
F. MEX Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Educational Codeforces Round 23 D. Imbalanced Array 单调栈
D. Imbalanced Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 23 C. Really Big Numbers 暴力
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 23 补题小结
昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...
- Educational Codeforces Round 23
A题 分析:注意两个点之间的倍数差,若为偶数则为YES,否则为NO #include "iostream" #include "cstdio" #include ...
- Educational Codeforces Round 40千名记
人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...
随机推荐
- 浏览器从输入URL到页面加载显示完成全过程解析
一 浏览器查找域名对应的 IP 地址(域名解析的过程,先进行缓存的查看): 1.在浏览器中输入www.qq.com域名,操作系统会先检查自己本地的hosts文件是否有这个网址映射关系,如果有,就先调用 ...
- IP代理(proxies参数)
在爬虫的过程中,我们经常会遇见很多网站采取了防爬取技术,或者说因为自己采集网站信息的强度和采集速度太大,给对方服务器带去了太多的压力. 如果你一直用同一个代理ip爬取这个网页,很有可能ip会被禁止访问 ...
- django框架基础
所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. 最简单的web框架 import socket sk = socke ...
- qt裁剪
1. qt裁剪是什么,qt有哪些模块 1.1 2. windows消息机制,qt的signal slot,android/ios消息机制?
- 相关Linux命令
#若服务不小心开启但是想关闭时,可以使用这个 命令:adstrtal.sh apps/apps(脚本 数据库用户名/密码) 若想启动命令:adstrtal.sh apps/apps ———————— ...
- logstash 5.1.1 学习
Logstash 5.1.1 安装配置 安装和配置 java 环境: [root@ ~]# tar xf jdk-8u71-linux-x64.tar.gz [root@ ~]# mv jdk1.8. ...
- spring Boot(十九):使用Spring Boot Actuator监控应用
spring Boot(十九):使用Spring Boot Actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台 ...
- Angular4.x 安装|创建项目|目录结构|创建组件
Angular4.x 安装|创建项目|目录结构|创建组件 安装最新版本的 nodejs node.js 官网:https://nodejs.org/zh-cn/ 去官网下载 node.js,下一步下一 ...
- 超详细 Nginx 极简教程,傻瓜一看也会!
什么是Nginx? Nginx (engine x) 是一款轻量级的Web 服务器 .反向代理服务器及电子邮件(IMAP/POP3)代理服务器. 什么是反向代理? 反向代理(Reverse Proxy ...
- U盘中病毒,文件消失或不显示
最近非常流行的一个病毒,将电脑或者U盘里的文件全部用快捷方式替换,真实文件被隐藏起来,下面我们就具体了解下此种病毒吧,做好预防与杀毒工作. 一.病毒名称 病毒名称:移动盘同名文件夹病毒;文件夹EXE病 ...