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 ...
随机推荐
- Springboot 使用JdbcTemplate
Springboot 使用JdbcTemplate book package com.draymonder.book.jdbc; public class Book { private Integer ...
- UOJ #455 [UER #8]雪灾与外卖 (贪心、模拟费用流)
题目链接 http://uoj.ac/contest/47/problem/455 题解 模拟费用流,一个非常神奇的东西. 本题即为WC2019 laofu的讲课中的Problem 8,经典的老鼠进洞 ...
- 使用keil生成bin文件
相关文件 下载http://pan.baidu.com/share/link?shareid=478269&uk=1107426113 使用kei自带的工具的话是 打开Options f ...
- C++入门经典-例6.5-连接字符串
1:运行代码如下: // 6.5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> usin ...
- C++入门经典-例3.5-判断某一年是否是闰年之嵌套判断
1:代码如下: // 3.5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...
- Kotlin学习入门笔记
参考资料 官网:https://kotlinlang.org/ 官方文档:https://kotlinlang.org/docs/reference/ Kotlin 源码:https://github ...
- laravel中事件的监听和订阅
一.前言 更新员工部门主管的时候,需要重新更新一下缓存,这个会比较耗时.所以计划放到队列中来执行.后来想了想,其实用一下事件监听也能实现.人家都说好,然是我也没感觉到有什么好的. 二.正文 1. 在p ...
- jenkins部署java项目
#########################################jenkins部署#################################3 一.jenkins是什么? J ...
- 异步上传&预览图片-压缩图片
移动端普及的时代,流量是用户最关心的,手机拍出来的照片基本上都在1~2M以上,这样上传会非常耗流量,影响用户体验,此例能在保证清晰度的情况下,将4.5M的图片压缩为30K <!DOCTYPE h ...
- Spring配置多个数据源,并实现数据源的动态切换转载)
1.首先在config.properties文件中配置两个数据库连接的基本数据.这个省略了 2.在spring配置文件中配置这两个数据源: 数据源1 <!-- initialSize初始化时建立 ...