题目链接

分析:01trie树,很容易就看出来了,也没什么好说的。WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0。我没有晚上爬起来打,白天发现过的人极多。

/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define offcin ios::sync_with_stdio(false)
#define sigma_size 26
#define lson l,m,v<<1
#define rson m+1,r,v<<1|1
#define slch v<<1
#define srch v<<1|1
#define sgetmid int m = (l+r)>>1
#define LL long long
#define ull unsigned long long
#define mem(x,v) memset(x,v,sizeof(x))
#define lowbit(x) (x&-x)
#define bits(a) __builtin_popcount(a)
#define mk make_pair
#define pb push_back
#define fi first
#define se second const int INF = 0x3f3f3f3f;
const LL INFF = 1e18;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const LL mod = 1e9+7;
const int maxmat = 10;
const ull BASE = 31; /*****************************************************/ const int maxn = 3e5 + 5;
int ch[maxn][2];
int sz = 1;
LL val[maxn];
void addnode(LL x) {
LL base = 1;
int u = 0;
for (int i = 0; i < 18; i ++) {
int c = (x / base) % 10;
c %= 2;
if (!ch[u][c]) {
ch[u][c] = sz ++;
mem(ch[sz], 0);
val[sz] = 0;
}
u = ch[u][c];
base *= 10LL;
}
val[u] ++;
}
void deletenode(LL x) {
LL base = 1;
int u = 0;
for (int i = 0; i < 18; i ++) {
int c = (x / base) % 10;
c %= 2;
u = ch[u][c];
base *= 10LL;
}
val[u] --;
}
int searchnode(char *s) {
int len = strlen(s);
LL ans = 0;
int u = 0, c;
for (int i = 0; i < 18; i ++) {
if (i < len) c = s[len - 1 - i] - '0';
else c = 0;
u = ch[u][c];
ans += val[u];
}
return ans;
}
int main(int argc, char const *argv[]) {
int N;
cin>>N;
char op[2];
char s[20];
LL x;
for (int i = 0; i < N; i ++) {
scanf("%s", op);
if (op[0] == '+') {
cin>>x;
addnode(x);
}
else if (op[0] == '-') {
cin>>x;
deletenode(x);
}
else {
scanf("%s", s);
cout<<searchnode(s)<<endl;
}
}
return 0;
}

Codeforces Round #371 (Div. 2) C. Sonya and Queries的更多相关文章

  1. Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题

    C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...

  2. Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

    题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...

  3. Codeforces Round #371 (Div. 2) C. Sonya and Queries[Map|二进制]

    C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心

    C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...

  5. Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]

    E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...

  6. Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend

    C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...

  7. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  8. 递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries

    题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...

  9. Codeforces Round #371 (Div. 2) 转换数字

    C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. c#:排序

    http://www.cnblogs.com/end/archive/2011/10/22/2220940.html 选择排序 冒泡排序 快速排序 插入排序 希尔排序 归并排序 基数排序 计数排序 小 ...

  2. Struts(八):动态方法调用

    动态方法调用:通过url动态调用action中的方法. 默认情况下,Struts的动态方法调用处于禁用状态. 测试定义一个action类: package com.dx.actions; public ...

  3. 在Unity中如何取得一个Box的Bounds

    private BoxCollider mCollider; // Use this for initialization void Start () { mCollider = GetCompone ...

  4. MVC 的各个部分都有那些技术来实现?如何实现?

    MVC 的各个部分都有那些技术来实现?如何实现? MVC 是 Model-View-Controller 的简写 "Model" 代表的是应用的业务逻辑(通过JavaBean,EJ ...

  5. Redis linux 下安装 及扩展配置

    1.首先在/usr/local/ 创建文件夹 reids Cd /usr/local/ mkdir redis 2.把redis安装包放在redis目录下面进行解压phpredis-2.2.4.tar ...

  6. sql 表分区使用

    如果你的数据库中某一个表中的数据满足以下几个条件,那么你就要考虑创建分区表了. 1.数据库中某个表中的数据很多.很多是什么概念?一万条?两万条?还是十万条.一百万条?这个,我觉得是仁者见仁.智者见智的 ...

  7. Swift数据类型简介(二)

    整数 整数就是没有小数部分的数字,比如42和-23.整数可以是有符号(正.负.零)或者无符号(正.零). Swift 提供了8,16,32和64位的有符号和无符号整数类型.这些整数类型和 C 语言的命 ...

  8. reqiurejs学习

    RequireJS 优化 Web 应用: http://www.ibm.com/developerworks/cn/web/1209_shiwei_requirejs/ 1.模块之间的依赖关系 2.如 ...

  9. Linux内核链表深度分析【转】

    本文转载自:http://blog.csdn.net/coding__madman/article/details/51325646 链表简介: 链表是一种常用的数据结构,它通过指针将一系列数据节点连 ...

  10. Application.DoEvents():概念

    When you run a Windows Form, it creates the new form, which then waits for events to handle. Each ti ...