Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]
1 second
256 megabytes
standard input
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:
- + 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.
- - 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.
- ? s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0stands 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 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
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.
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.
- 12
+ 1
+ 241
? 1
+ 361
- 241
? 0101
+ 101
? 101
- 101
? 101
+ 4000
? 0
- 2
1
2
1
1
- 4
+ 200
+ 200
- 200
? 0
- 1
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 and 241.
- 361.
- 101 and 361.
- 361.
- 4000.
题意:插入删除数字 查询模式
一开始想了一个好像很厉害的做法,位向量树,实在调试不出来了
然后突然发现,数字是按十进制不是二进制
并且,数字和模式高位的0补位其实没什么影响,就是没有值,就是没有
所有把数字和模式都变成十进制或二进制01串然后用map或一个数组(2^18=262144)加减就行了
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <map>
- using namespace std;
- typedef long long ll;
- const int N=;
- inline ll read(){
- ll x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- ll t,a;
- char c[],s[];
- //map<ll,int> mp;
- int mp[N];
- int main(int argc, const char * argv[]) {
- t=read();
- while(t--){
- scanf("%s",c);a=read();
- ll b=,k=;
- while(a){
- b+=a%*k;
- a/=;
- k*=;
- }
- if(c[]=='+') mp[b]++;
- if(c[]=='-') mp[b]--;
- if(c[]=='?') printf("%d\n",mp[b]);
- }
- return ;
- }
Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]的更多相关文章
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...
- 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 m ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries
题目链接 分析:01trie树,很容易就看出来了,也没什么好说的.WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0.我没有晚上爬起来打,白天发现过的人极多. /******** ...
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend
C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- 递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries
题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...
- Codeforces Round #371 (Div. 2) 转换数字
C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- asp.net+nopi生成Excel遇到设置单元格值null问题
Npoi 生成excel报表功能很不错,功能也不用给大家介绍了.首先看遇到的问题吧! FileStream file = new FileStream(Server.MapPath("Tem ...
- html5音频和视频标签
在html5之前的版本中如果想要在网页中插入音频和视频必须要安装插件才可以,比如最常见的flash插件.很多人在刚安装一款浏览器的时候都会遇到浏览器建议安装flash插件,在移动端也是如此.如果想要在 ...
- Web前端开发工具总结
前端开发工具: web前端开发乃及其它的相关开发, 推荐sublime text, webstorm(jetbrains公司系列产品)这两个的原因在于,有个技术叫emmet, http://docs. ...
- 规划SharePoint2010的管理员密码更改
规划自动密码更改 (SharePoint Server 2010) 为了简化密码管理,自动密码更改功能允许您更新和部署密码,而不必在多个帐户.服务和 Web 应用程序之间执行手动密码更新任务.您可以配 ...
- 深入.net(多态一)
代码优化技术: 当您在 编写一个类时,如果您发现你需要编写的“属性”和“方法”曾经在已有的类中实现,则,您可以将其共用的“属性”和“方法”剪切到一个新的“类”中,然后,让两个类共同继承这个“新类”.( ...
- 【代码笔记】iOS-首页3张图片变化
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 深入理解Objective-C Runtime
一.简介 主要特点: 在OC语言中,函数的调用是属于动态调用的,编译阶段并不确定要调用的函数,在真正的运行时才会根据函数名查找要调用哪个函数. 而在C语言中,函数的调用是在编译阶段就已经确定要调用哪个 ...
- mac os下可能是最好的豆瓣电台——diumoo
由于我一直用豆瓣fm听音乐,在网上找了下豆瓣的相关应用,都感觉不是太好, 最后发现一个mac版的app--diumoo! 这个软件看着非常舒服,一点也不占桌面空间,它一直默默在桌面右上角,鼠标划上去会 ...
- 16、总经理要阅读的书籍 - IT软件人员书籍系列文章
总经理是公司的一个领导角色.他主要负责公司级别的比如规划,战略等等内容.有些公司的总经理,比如软件公司的总经理,往往是一个大的业务员,将更多的大型的软件项目投取过来,让公司能够有钱赚,让公司员工能够跟 ...
- JMS(Java消息服务)入门教程
什么是Java消息服务 Java消息服务指的是两个应用程序之间进行异步通信的API,它为标准消息协议和消息服务提供了一组通用接口,包括创建.发送.读取消息等,用于支持JAVA应用程序开发.在J2EE中 ...