Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

题目链接:http://codeforces.com/contest/714/problem/C


C. Sonya and Queries
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:

  1.  +  ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
  2.  -  ai — delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
  3. ? s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.

For example, if the pattern is s = 010, than integers 92221250 and 414 match the pattern, while integers 311025 and 1030 do not.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform.

Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 ≤ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.

It's guaranteed that there will be at least one query of type '?'.

It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.

Output

For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.

Examples
input
12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
output
2
1
2
1
1
input
4
+ 200
+ 200
- 200
? 0
output
1
Note

Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.

  1. 1 and 241.
  2. 361.
  3. 101 and 361.
  4. 361.
  5. 4000.



题解: 

由于查询模式中只有01串(代表奇偶),所以输入的数字只需用01记录每一位奇偶性。故可以用二进制对数字进行压缩归类。由于1<<18=26214, 范围不是很大,所以可以用数组记录每个二进制数出现的个数,之后就可以直接修改,查询了。



代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 300000using namespace std;LL p[maxn];
char ch, s[50];int main()
{int n,bin;scanf("%d",&n);for(int i = 0; i<n; i++){getchar();scanf("%c%s",&ch,s);bin = 0;for(int j = 0,len = strlen(s); j<len; j++){bin <<= 1;if((s[j]-'0')&1)bin++;}if(ch=='+')p[bin]++;else if(ch=='-')p[bin]--;elseprintf("%lld\n",p[bin]);}
}


转载于:https://www.cnblogs.com/DOLFAMINGO/p/7538740.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/468926.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一张倾斜图片进行矫正 c++_专业性文章:10分钟矫正骨盆前倾

如今&#xff0c;骨盆前倾(又称“下交叉综合征”)非常多&#xff0c;大部分是由于以下两个原因而变得越来越突出&#xff1a;经常久坐不良的运动习惯后面我们讲到纠正骨盆前倾的四个基本步骤&#xff0c;让你快速解决&#xff0c;提高生活质量知识型和系统型的内容&#xff0c;…

vue.js源码学习分享(五)

//配置项var config {/*** Option merge strategies (used in core/util/options)//选项合并策略*/optionMergeStrategies: Object.create(null),/*** Whether to suppress warnings.//是否抑制警告*/silent: false,/*** Show production mode//生产模式 tip message on boot?…

TypeError: can‘t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory

项目场景&#xff1a; 运行程序&#xff0c;出现报错信息 TypeError: cant convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.。 Traceback (most recent call last):File "tools/demo.py", line 97, in <module>vi…

Secure CRT 自动记录日志

配置自动log操作如下&#xff1a; 1.options ---> Global Options 2、General->Default Session->Edit Default Settings 3、Terminal->Log File 设置如图上所示 点击 日志 &#xff0c;在选项框中 Log file name中填入路径和命名参数&#xff1a; E:\Log\%Y_%M_…

java 异步调用方法_乐字节Java编程之方法、调用、重载、递归

一、概述方法是指人们在实践过程中为达到一定目的和效果所采取的办法、手段和解决方案。所谓方法&#xff0c;就是解决一类问题的代码的有序组合&#xff0c;是一个功能模块。编程语言中的方法是组合在一起来执行操作语句的集合。例如&#xff0c;System.out.println 方法&…

git clone 从GitHub上下载项目到服务器上运行+创建虚拟环境

1. 基础的Linux命令 可先进入需要放置文件的路径之下 pwd # 可看当前路径 cd …/ #返回上一层目录 cd ./xx/ #进入当前路径下的下一个文件2. GitHub项目clone到服务器上运行 # 复制GitHub页面的链接&#xff0c;在服务器后台输入git clone 命令即可 git clone https://githu…

[笔记] FireDAC DataSet 导入及导出 JSON

刚好需要将 FireDAC DataSet (TFDDataSet, TFDQuery...) 转成 JSON&#xff0c;网上找了一圈&#xff0c;原来从 XE6 开始就支持这个功能了&#xff1a; 储存&#xff1a; DataSet1.SaveToFile(d:\Data.json, TFDStorageFormat.sfJSON); 载入&#xff1a; DataSet1.LoadFromFil…

recovery相关的FAQ总结

一、[FAQ12481]Recovery mode在cache/recovery目录下新建一支文件&#xff0c;重启后&#xff0c;新建文件消失了 [DESCRIPTION] 1、在recovery.cpp文件的最后新建一支文件 /cache/recovery/wetest&#xff1b;并写入内容&#xff1a;welcome to recovery mode&#xff01; 2、…

AttributeError: module ‘torch.jit‘ has no attribute ‘_script_if_tracing‘

项目场景&#xff1a; torvh使用提示 AttributeError: module torch.jit has no attribute _script_if_tracing 原因分析&#xff1a; 解决办法&#xff1a;原因是torch与torchvision版本不匹配导致的&#xff0c;重新安装torchvision即可 解决方案&#xff1a; pip install…

java 调用python_Java平台如何调用Python平台?

1. 问题描述Java平台要调用Pyhon平台已有的算法&#xff0c;为了减少耦合度&#xff0c;采用Pyhon平台提供Restful 接口&#xff0c;Java平台负责来调用&#xff0c;采用HttpJson格式交互。2. 解决方案2.1 JAVA平台侧2.1.1 项目代码public static String invokeAlgorithm(Strin…

C 实现 删除字符串空白符的函数 strtrim

说在前面的话 字符串操作在很多C语言比赛里面都有涉及&#xff0c;最近公众号里面的C语言比赛&#xff0c;都是两个关于字符串操作的题目&#xff0c;希望大家认真看题目。 直接上代码 /*************************************************************************> Fil…

小工具:批量替换文件夹下所有文件内容中的指定词

问题描述&#xff1a; 数据集中的xml信息所标注的文件后缀写错了&#xff0c;应该为jpg&#xff0c;因此需要将所有xml文件的.png修改为.jpg 解决代码&#xff1a; 函数作用&#xff1a;找出某文件夹下的包含指定关键词文件列表&#xff0c;并将关键字修改为目标字并将新内容…

jvm性能监控工具

jvm可能存在的问题&#xff1a; OutOfMemoryError&#xff1a;内存不足 内存泄露 线程死锁 锁竞争(Lock Contention) Java消耗过多的CPU一、jps(java virtual machine process status tool)监控jvm进程转台信息jps [options] [hostid] -m&#xff1a;输出传入…

javascript犀牛书_犀牛书作者:最该忘记的JavaScript特性

作者&#xff1a; 李松峰转发链接&#xff1a;https://mp.weixin.qq.com/s/guAN1Cz2gYfKdBhmUpLyVA前言JavaScript这门语言的第一个演示版差不多就在25年前诞生。没记错的话&#xff0c;25年前的今天&#xff0c;1995年5月10日&#xff0c;星期三&#xff0c;我刚刚过了创造Jav…

RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel

项目场景&#xff1a; 提示&#xff1a;新版python在pytorch中张量与原始数据的除法计算问题。 问题描述 报错 RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future release div will perform true division as in Python 3…

Weblogic(4)—— Linux环境Weblogic12c配置节点管理(nodemanage.properties)来开启应用服务器(server)及线程池配置...

Linux环境搭建weblogic12c服务器&#xff0c;用来进行weblogic服务器项目部署&#xff0c;刚创建weblogic服务器会默认存在AdminServer管理服务器。但是项目应用一般是不能挂在这个服务器上的&#xff0c;需要自己单独创建应用服务器。 使用root权限登录 服务器&#xff1a; 输…

添加python的系统路径_如何将项目路径添加到系统路径永久地?

我正在使用visualstudio代码构建一个python项目。这是我第一次用编辑器构建一个项目(过去使用Pycharm)。在随着项目越来越大&#xff0c;我想导入一些我在其他目录中编写的类(在同一个项目中)。首先&#xff0c;我在要导入的目录中添加了__init__.py。但是&#xff0c;它没有起…

IDEA与Maven安装+IDEA中利用maven自动下载第三方Jar包

Maven详细安装教程_慕之寒的博客-CSDN博客_maven安装一、安装apache官网下载需要的版本&#xff0c;然后解压缩&#xff0c;解压路径尽量不要有空格和中文Maven – Download Apache Mavenhttps://maven.apache.org/download.cgi二、配置环境变量新建 系统变量变量名&#xff1a…

Unicode 和 UTF-8 有什么区别?

作者&#xff1a;uuspider 链接&#xff1a;https://www.zhihu.com/question/23374078/answer/65352538 来源&#xff1a;知乎 著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处。 举一个例子&#xff1a;Its 知乎日报 你看到的unicode字符集…