D - 秋实大哥与快餐店
秋实大哥与快餐店
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
朝为田舍郎,暮登天子堂。秋实大哥从小就怀抱有远大的理想,所以他开了一家快餐店。
秋实大哥根据菜的口感,给每一道菜一个唯一的CIDCID,同时对于前来的客人,根据他们的口味喜好,秋实大哥会给每一个客人一个PIDPID。
对于一个标号为PIDPID的客人,他对标号为CIDCID的菜的喜爱程度为PID∧CIDPID∧CID(∧∧表示按位异或),该值越大表示越喜欢。
秋实大哥实在太忙了,现在他需要你来帮忙照看一下他的店铺。
Input
第一行包含一个整数nn,表示秋实大哥的餐馆内现在有nn道菜。
接下来一行包含nn个整数,分别表示每一道菜的CIDCID。
接下来一行包含一个整数mm,表示接下来发生了mm件事。
接下来的mm行,每一行为以下两种事件之一:
0 c : 表示秋实大哥最新研制出一道标号为c的菜
1 p : 表示来了一位标号为p的客人,请你在已有的菜中找出一道他最喜爱的菜
1≤n,m≤1000001≤n,m≤100000,0≤PID,CID≤10000000≤PID,CID≤1000000。
Output
对于每一个11 pp事件输出一个整数,表示该客人最喜欢的菜的标号。
Sample input and output
| Sample Input | Sample Output |
|---|---|
1 |
1 |
既然是求异或值,就把CID转换成二进制加入字典树,在把PID每一位取反转换成二进制在字典树里跑一遍就可以了
#pragma GCC diagnostic error "-std=c++11"
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector> using namespace std; struct Tire{
struct Tire *next[];
Tire() {next[] = next[] = NULL; }
}; Tire *root; void Insert(int x){
Tire *p = root;
for(int i = ; i >= ; i--){
int c = (x >> i) & ;
if(p -> next[c] == NULL)
p -> next[c] = new Tire;
p = p -> next[c];
}
} int Query(int x){
x = ~x;
Tire *p = root;
int ans = ;
for(int i = ; i >= ; i--){
int c = (x >> i) & ;
ans <<= ;
if( c ){
if(p -> next[]){
p = p -> next[];
ans++;
}else p = p -> next[];
}else{
if(p -> next[]) p = p -> next[];
else{
p = p -> next[];
ans++;
}
}
}
return ans;
}
int main(){
int n, x, m, c;
root = new Tire;
scanf("%d", &n);
for(int i = ; i<= n; i++){
scanf("%d", &x);
Insert( x );
}
scanf("%d", &m);
for(int i = ; i <= m; i++){
scanf("%d %d", &c, &x);
if(c == ) Insert( x );
else printf("%d\n", Query(x));
}
}
D - 秋实大哥与快餐店的更多相关文章
- UESTC_秋实大哥与快餐店 2015 UESTC Training for Data Structures<Problem C>
C - 秋实大哥与快餐店 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Sub ...
- 2015 UESTC 数据结构专题C题 秋实大哥与快餐店 字典树
C - 秋实大哥与快餐店 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 ...
- CDOJ 1060 秋实大哥与快餐店 字典树 水题
题目链接 B - 秋实大哥与快餐店 Time Limit:1000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu Sub ...
- UESTC_秋实大哥与连锁快餐店 2015 UESTC Training for Graph Theory<Problem A>
A - 秋实大哥与连锁快餐店 Time Limit: 9000/3000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) S ...
- CDOJ 1146 A - 秋实大哥与连锁快餐店 最小生成树 Prim算法 稠密图
题目链接 A - 秋实大哥与连锁快餐店 Time Limit:3000MS Memory Limit:65535KB 64bit IO Format:%lld & %llu S ...
- UESTC_秋实大哥与时空漫游 2015 UESTC Training for Graph Theory<Problem C>
C - 秋实大哥与时空漫游 Time Limit: 4500/1500MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Su ...
- uestc 1073 秋实大哥与线段树 Label:线段树
秋实大哥与线段树 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) “学习本无底, ...
- UESTC 1074 秋实大哥搞算数 栈模拟
秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit S ...
- UESTC_秋实大哥带我飞 2015 UESTC Training for Graph Theory<Problem B>
B - 秋实大哥带我飞 Time Limit: 300/100MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
随机推荐
- 【BZOJ3261】最大异或和(可持久化Trie)
题意: 思路:可持久化Trie板子题,支持序列插入和询问 #include<bits/stdc++.h> using namespace std; typedef long long ll ...
- vue-cli的基础构造
1,项目目录 2, bulid 下文件及目录 3,config下文件及目录 接下来说说vue-cli项目中页面相关的主要文件^o^ 首先是index.html: 说明:一般只定义一个空的根节点,在ma ...
- php的switch函数
PHP Switch 语句 PHP If...Else PHP While 循环 switch 语句用于基于不同条件执行不同动作. Switch 语句 如果您希望有选择地执行若干代码块之一,请使用 S ...
- linux输出与查看的几种方式
输出的几种方式:echo/ tee echo "postgres install Failed !!!!!!" | tee -a "$Install_log"# ...
- Concurrent包里的其他东西:ArrayBlockingQueue、CountDownLatch等等。
1:本例介绍一个特殊的队列:BlockingQueue,如果BlockingQueue是空的,从BlockingQueue取东西的操作将会被阻断进入等待状态,直到BlockingQueue进了东西才会 ...
- js判断某个字符串是否包含另一个字符串
1.indexOf():推荐,可返回某个指定的字符串值在字符串中首次出现的位置.如果要检索的字符串值没有出现,则该方法返回 -1. var str = "123" console. ...
- 在win7下,将QT集成到vs2010上
在网上查了很多,自己先是下载了一个5.2.0版本的,但在我的电脑上运行时老报错,一怒之下决定不再使用5.2.0版本的QT,而先择了更低版本的4.8.5版本,然后.....然后就成功了.谢天谢地,在这我 ...
- wls12C启用Gzip
https://community.oracle.com/message/14109820 https://docs.oracle.com/middleware/1221/wls/NOTES/what ...
- Dubbo Monitor Simple 监控中心
下载项目源码(其中的 dubbo-registry-simple 代表简单的注册中心,用于开发测试,生产环境一般用zookeeper) https://github.com/apache/incuba ...
- TNS:could not resolve the connect identifier specified解决办法
添加环境变量解决:TNS_ADMIN ->> D:\OracleDB\product\11.2.0\dbhome_1\NETWORK\ADMIN