題目大意:
+ 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>