E. Choosing The Commander
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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:

  • pi — one warrior with personality pi joins Vova's army;
  • pi — one warrior with personality pi leaves Vova's army;
  • 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.

Input

The first line contains one integer q (1 ≤ q ≤ 100000) — the number of events.

Then q lines follow. Each line describes the event:

  • pi (1 ≤ pi ≤ 108) — one warrior with personality pi joins Vova's army;
  • 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);
  • 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.
Output

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.

Example
Input
5
1 3
1 4
3 6 3
2 4
3 6 3
Output
1
0
Note

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数的更多相关文章

  1. Educational Codeforces Round 23 A-F 补题

    A Treasure Hunt 注意负数和0的特殊处理.. 水题.. 然而又被Hack了 吗的智障 #include<bits/stdc++.h> using namespace std; ...

  2. Educational Codeforces Round 23.C

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. 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 ...

  4. 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 ...

  5. Educational Codeforces Round 23 D. Imbalanced Array 单调栈

    D. Imbalanced Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 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 ...

  7. Educational Codeforces Round 23 补题小结

    昨晚听说有教做人场,去补了下玩. 大概我的水平能做个5/6的样子? (不会二进制Trie啊,我真菜) A. 傻逼题.大概可以看成向量加法,判断下就好了. #include<iostream> ...

  8. Educational Codeforces Round 23

    A题 分析:注意两个点之间的倍数差,若为偶数则为YES,否则为NO #include "iostream" #include "cstdio" #include ...

  9. Educational Codeforces Round 40千名记

    人生第二场codeforces.然而遇上了Education场这种东西 Educational Codeforces Round 40 下午先在家里睡了波觉,起来离开场还有10分钟. 但是突然想起来还 ...

随机推荐

  1. GUI保存打开对话框

    %uigetfile uigetfile doc uigetfile %规定打开文件类型 uigetfile('*.m'); %输出参数意义 [a,b,c] = uigetfile('*.m');%a ...

  2. 51Nod 1212 无向图最小生成树 (路径压缩)

    N个点M条边的无向连通图,每条边有一个权值,求该图的最小生成树.   Input 第1行:2个数N,M中间用空格分隔,N为点的数量,M为边的数量.(2 <= N <= 1000, 1 &l ...

  3. printf、fprintf、sprintf和snprintf 区别

    都是把格式好的字符串输出,只是输出的目标不一样: 1 printf,是把格式字符串输出到标准输出(一般是屏幕,可以重定向). 2 sprintf,是把格式字符串输出到指定字符串中,所以参数比print ...

  4. java-工厂方法模式学习笔记

    1.工厂模式分三种 1.1 普通工厂模式:就是建立一个工厂类,对实现了同一接口的一些类进行实例创建,如下图所示: 就以老司机开车(土豪开奔驰,宝马:屌丝骑自行车)为例,说明一下普通工厂模式: 首先,创 ...

  5. Kali linux apt-get update 失败,无release……(最有效)

    设置源 编辑 /etc/apt/sources.list nano /etc/apt/sources.list 清空文件内所有内容后添加 deb http://mirrors.ustc.edu.cn/ ...

  6. Golang内存分配内置函数之new函数

    new函数用来分配内存,主要分配值类型,比如int.float32.struct等,返回的是指针 package main import ( "fmt" ) func main() ...

  7. PHP多进程非阻塞模式下结合原生Mysql与单进程效率测试对比

    公司在做游戏服务器合并的时候,对大批量数据表做了合并操作,难免会出现数据格式不一致问题.根据玩家反映BUG排查,是因为某个模块下日志表出现了数据格式问题导致. 目前想到的是有两种方案解决,第一种就是把 ...

  8. nginx动静态分离以及配置https(安全组强行切换以及导致的问题解决)

    公司原来的网络采用http/https同时支持的方式,http并不会强制自动跳转到https,最近要求强制切换,导致了一系列问题.趁今天测试完成了,整理如下: 1.要求HTTP自动跳转到HTTPS: ...

  9. svg动态添加小人

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  10. Educational Codeforces Round 40 (Rated for Div. 2) Solution

    从这里开始 小结 题目列表 Problem A Diagonal Walking Problem B String Typing Problem C Matrix Walk Problem D Fig ...