Topic Link: Http://codeforces.com/contest/714/problem/C
————————————-.
C. Sonya and Queries
Time limit per test1 second
Memory limit per test256 megabytes
Inputstandard input
Outputstandard output
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has a 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, this she has a multiset, thus there may is many occurrences of the same integer.
-Ai-delete A single occurrence of non-negative integer AI from the multiset. It ' s guaranteed, that there was at least one AI in the multiset.
S-count the number of integers in the multiset (with repetitions), 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 to the pattern. If the is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the the integer is shorter than the pattern its decimal notation are supplemented with the 0-s to the left.
For example, if it is S = 010, than integers, 2212, X and 414 match the pattern, while integers 3, 110, 1030 does not.
Input
The ' The ' input contains an integer t (1≤t≤100)-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 spaces and an integer AI (0≤ai < 1018) given without leading zero ES (unless it ' s 0). If ci equals '? ' then it's followed by a spaces and a sequence of zeroes and onse, giving the pattern of length no more tha n 18.
It's guaranteed that there would be in least one query of type '? '.
It's guaranteed that any time some an integer is removed from the multiset, there'll be at least one occurrence of this int Eger 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.
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 type. Queries are numbered in the order they appear in the input.
1 and 241.
361.
361.
361.
4000.
———————————–.
The main idea: (understand the topic of my Tears Fall ~ ~ ~ ~)
Is that there is a multiset such a container
There are three kinds of operations
+ A add a to Multiset
-A To delete a multiset
。 S-Find S is a <=18 bit that omits a leading 0 binary number, and then the number of numbers equal to s in the current multiset after each bit%2
Ideas for solving problems:
is to maintain a map
The number of mapped things in this state
And then it can be solved in the O (18n) complexity.
Attached to the code
—————————-.
#include <bits/stdc++.h>
using namespace std;
#define LL Long int
#define INF 0x1f1f1f1f
#define PB push_back
#define Lalal puts ("*******");
/*************************************/
const int MOD = 1E9+7;
const int M = 1E5+10;
map<ll,int>b;
int main ()
{
Ios::sync_with_stdio (false);
int t;
while (cin>>t)
{
b.clear ();
LL tem, x,a,bit;
char c;
for (int i=0; i<t; i++)
{
cin>>c>>a;
TEM = A,x = 0,bit=0;
while (TEM)
{
if (tem%10%2) x |= (1<<bit);
tem/=10;
bit++;
}
if (c== ' + ') b[x]++;
if (c== '-') b[x]--;
if (c== '? ') cout<<b[x]<<endl;
}
}
return 0;
}