C. Sonya and Queries
time limit/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 following:
Three input forms are given:
1. ' + ' Add a number to the array
2. '-' remove a number from the array
3. '? ' Gives 01 strings, representing the characteristics of the number of queries (corresponding to the parity of digits, metaphor 250 corresponds to 010,233 011), the number of queries that conform to the number of string characteristics, and if the length is not enough, make up 0 in front of the string.
Ideas for solving problems:
Each number is converted to 01, and then the 01 strings are considered as binary numbers, then converted into decimal numbers, and then the number of characteristic numbers is actually stored. When searching, it also converts 01 strings into decimal numbers and retrieves them.
AC Code:
#include <stdio.h>
const int MAXN = 1000005;
int QDU[MAXN];
int main ()
{
int loop;
scanf ("%d", &loop);
while (loop--)
{
char tmp1;
Long long tmp2;
scanf ("%c%lld", &TMP1,&TMP2);
int sum = 0;
int k = 1;
while (TMP2)
{
sum + = k* (tmp2%2);
TMP2/=;
K <<= 1;
}
if (Tmp1 = = ' + ') qdu[sum]++;
else if (tmp1 = = '-') qdu[sum]--;
else if (tmp1 = = '? ') printf ("%d\n", Qdu[sum])
;
return 0;
}