codeforces 713A A. Sonya and Queries(状态压缩)
题目链接:
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,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 with0-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 题意: + 就是在集合里面加这个数,- 就是减去这个数,?就是问集合里面有多少符合这个串的数; 思路: 一开始写了个trie树,wa了,不想改,后来发现可以状态压缩搞一搞;病了几天感觉差爆了; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=(1<<20)+10;
const int maxn=1e6+110;
const double eps=1e-12; int n,num[maxn];
char s[10],str[20];
int solve()
{
int len=strlen(str),s=0;
for(int i=0;i<len;i++)
{
int x=str[i]-'0';
s*=2;
if(x&1)s=s+1;
}
return s;
}
int main()
{
read(n);
while(n--)
{
scanf("%s%s",s,str);
int t=solve();
if(s[0]=='+')num[t]++;
else if(s[0]=='-')num[t]--;
else printf("%d\n",num[t]);
}
return 0;
}
codeforces 713A A. Sonya and Queries(状态压缩)的更多相关文章
- 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 C. A Simple Task(状态压缩dp)
题目描述: A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- codeforces 425B Sereja and Table(状态压缩,也可以数组模拟)
题目 给出一个n*m的01矩阵, 让你最多改变k个里面的值(0变1,1变0), 使得0.1的连通分量是矩阵.输出最少步数 1 ≤ n, m ≤ 100; 1 ≤ k ≤ 10 题解: 如果01连通分量 ...
- Codeforces #454 div1 C party(状态压缩bfs)
题意: 给你N个点的一幅图,初始图中有M条边,每次操作可以使得一个点连接的所有点变成一个团,问你最少多少次操作可以使得整个图变成一个团. 解法: 因为N很小 所以我们可以二进制压缩来表示一个点与其他点 ...
- Codeforces 903F Clear The Matrix(状态压缩DP)
题目链接 Clear The Matrix 题意 给定一个$4 * n$的矩形,里面的元素为$'.'$或$'*'$.现在有$4$种正方形可以覆盖掉$'*'$,正方形的边长分别为$1,2,3,4$. 求 ...
- Codeforces Gym 100015F Fighting for Triangles 状态压缩DP
F Fighting for Triangles Description Andy and Ralph are playing a two-player game on a triangular bo ...
- Codeforces 714C. Sonya and Queries Tire树
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...
- 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 B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
随机推荐
- Docker源码编译
官方建议docker源码编译在docker容器内进行,因为官方提供的容器内已经继承了编译需要的环境,如果非要自己搭建编译环境也不是不可以,就是稍微有些繁琐.以下以1.8.2版本为例. 1.pull d ...
- poolboy的坑
poolboy是Erlang中运用非常广泛的进程池库,它有很多优点,使用简单,在很多项目中都能看到它的身影.不过,它也有一些坑,使用时候需要注意.(本文对poolboy的分析基于1.5.1版本) wo ...
- Java中的继承
我们在以前的学习中,我们会了C#中的继承,今天我们来了解了解Java中的继承,其实都大同小异啦! 1.语法 修饰符 SubClass extends SuperClass(){ //类定义部分 } e ...
- 基于UML项目的分析与设计
1,概述 项目中需求和设计的文档是必然的,UML工具可以帮助指导我们从不同的角度去看待一个新的系统,并把这个系统分解剖析出来.本篇文章主要讲述的是如何将UML应用到项目的开发工作中,关于如何学习UML ...
- Microsoft Dynamics CRM 2013 安装过程 图解
在安装前,先持一下SQL配置管理,将相关的服务打开.(由于在虚拟机里,许多服务需要时才会打开,像Reporting Services需要处理报表时才打开) 注:Analysis Services 登录 ...
- 实验12:Problem I: 成绩排序
Home Web Board ProblemSet Standing Status Statistics Problem I: 成绩排序 Problem I: 成绩排序 Time Limit: 1 ...
- 用Qt开发第一个Hello World程序
配置好Qt的环境变量之后,我们才可以进行下面的通过终端来使用Qt开发这个第一个程序 因为Qt的文件路径不能有中文否则会报错,所以一般都把工程文件都建立在根目录 我们创建的Qt程序包含两个部分:1.GU ...
- 敏捷软件开发:原则、模式与实践——第10章 LSP:Liskov替换原则
第10章 LSP:Liskov替换原则 Liskov替换原则:子类型(subtype)必须能够替换掉它们的基类型(base type). 10.1 违反LSP的情形 10.1.1 简单例子 对L ...
- apt-get
更新版本: apt-get --reinstall install apache2 卸载: apt-get remove apache2 只删除软件包 apt-get autorem ...
- Memcache笔记03-php操作Memcached
通过php程序操作Memcached服务几种形式 Memcache 扩展 Memcached 扩展 Socket套接字操作 memcached-client.php(函数) 对于php扩展来说,dan ...