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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值