Codeforces-713A Sonya and Queries

题目大意:

+ x表示向一个mutiset里增加一个数x

- x表示向一个mutiset里面减少一个数x

? x表示询问这个mutiset里面能够与x匹配的数的个数,匹配规则是x只由01组成,0表示偶数,1表示奇数。当x比要匹配的数长度短的时候,在x前面补0,当x比要匹配的数长度长的时候,在待匹配的数前面补0

解题思路:

乍一看觉得应该用字典树写。其实不然。

直接设一个长度为2^18的数组a,a[i]的意思是,能与状态i匹配的数字的个数。

代码:

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;

#define mp make_pair
#define pb push_back
#define lson (rt << 1)
#define rson (rt << 1 | 1)

typedef long long LL;
typedef pair<int, int> pi;

const int maxn = (1 << 18) + 10;

int cas;
int st[maxn];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> cas;
	while (cas--) {
		char op; 
		LL num, tmp, los = 0;
		cin >> op >> num;
		int status = 0;
		while (num) {
			tmp = num % 10;
			num /= 10;
			if (tmp & 1) status |= (1 << los);
			++los;
		}
		//cout << status << endl;
		if (op == '+') st[status] += 1;
		else if (op == '-') st[status] -= 1;
		else cout << st[status] << endl;
	}
	//system("pause");
	return 0;
}</span>


原文地址:https://www.cnblogs.com/wiklvrain/p/8179350.html