http://codeforces.com/contest/714/problem/C

看到这题目,想想,肯定不能暴力啊,如果用map,如何快速找到满足要求的数目,然后,长度18,我想,这不是熟悉的trie树么,还犹豫什么,把所有的输入都处理成长度为18的字符串,处理就行了,然后调试了一会,就交了,然后tle了,我就怀疑了,难道不是这样的套路么?!然后就开始查答案,一看官方题解,恍然大悟,这道题目有个很好的性质,就是插入11和插入33的效果是一样的,删除11和删除33的效果是一致的,同一种模型,我们不必具体的区分该位具体是什么,比如奇数(1,3,5,7,9)都可以简单用1来表示,偶数(0,2,4,6,8)都可以用0表示,这样题目就化简很多,还要trie树做什么,同一种模式可以归为一类,总共1 << 18种方式,然后单独统计,单独输出,就ok!就完了,感觉还是太笨了!也没仔细去分析。

 #include<bits/stdc++.h>
#define pb push_back
#define FOR(i, n) for (int i = 0; i < (int)n; ++i)
#define dbg(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl
typedef long long ll;
using namespace std;
typedef pair<int, int> pii;
const int maxn = << ;
int a[maxn];
int n;
char ch[];
ll x;
ll d[];
void solve() {
d[] = ;
for (int i = ; i < ; i++) d[i] = d[i - ] * ;
scanf("%d", &n);
while(n--) {
scanf("%s", ch);
//cout << ch << endl;
if(ch[] == '?') {
scanf("%s", ch);
int l = strlen(ch);
int t = ;
for (int i = ; i < l; i++) {
if(ch[i] == '')
t |= ( << (l - i - ));
}
//cout << "ask " << t << endl;
printf("%d\n", a[t]);
} else {
scanf("%I64d", &x);
int t = ;
for (int i = ; i >= ; i--) {
int td = x / d[i];
x %= d[i];
if(td & ) t |= ( << i);
}
//cout << "test "<< t << endl;
if(ch[] == '+')
a[t]++;
else a[t]--;
}
}
}
int main() { //freopen("test.in", "r", stdin);
//freopen("test.out", "w", stdout);
solve();
return ;
}

C. Sonya and Queries的更多相关文章

  1. 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 ...

  2. Codeforces 714C. Sonya and Queries Tire树

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

  3. codeforces 713A A. Sonya and Queries(状态压缩)

    题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input st ...

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

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

  5. 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 ...

  6. Codeforces 713A. Sonya and Queries

    题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类 ...

  7. Codeforces Round #371 (Div. 2) C. Sonya and Queries

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

  8. [Codeforces_713A]Sonya and Queries

    题目链接 http://codeforces.com/problemset/problem/713/A 题意 三种操作: +  ai 集合里加一个整数ai,相同数记为多个.  -  ai 集合里减一个 ...

  9. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

随机推荐

  1. 在ubuntu上面配置nginx实现反向代理

    1.下载nginx    官网:http://nginx.org/en/download.html    直接在服务器上下载 wget http://nginx.org/download/nginx- ...

  2. CocoaPods使用命令

    5.需要在工程中创建一个Podfile文件, 使用命令: $cd /Users/shiyunlei/Desktop/CocoapodsSample(进入工程目录,cd后面的是工程的路径) $ touc ...

  3. Android 百度地图API 定位 导航

    看看这个利用百度地图定位并实现目的地导航的Demo. 首先看实现效果:                          进 入后首先会得到当前位置,在地图上显示出来.在输入框中输入目的地后,就会在地 ...

  4. 手把手教你Android来去电通话自动录音的方法

    我们在使用Android手机打电话时,有时可能会需要对来去电通话自动录音,本文就详细讲解实现Android来去电通话自动录音的方法,大家按照文中的方法编写程序就可以完成此功能. 来去电自动录音的关键在 ...

  5. 在javascript中关于submit和button提交表单区别

    submit是button的一个特例,也是button的一种,它把提交这个动作自动集成了,submit和button,二者都以按钮的形式展现,看起来都是按钮,所不同的是type属性和处发响应的事件上. ...

  6. error “base class has incomplete type”

    error "base class has incomplete type" 如果base.h是你的基类,那么在子类derive中,写成如下形式: class base; clas ...

  7. js数组定义和获取其长度

    1.只有值组成的数组,必须先定义数组对象. 定义 var arrs=new array()或 var arrs=[]; 赋值: arrs[]="he";arrs[]="c ...

  8. html5刮刮卡

    通过Canvas实现的可刮涂层效果. 修改img.src时涂层也会自动适应新图片的尺寸. 修改layer函数可更改涂层样式. 涂层: 可刮效果: 以下是HTML源代码(已增加移动设备支持): 1 2 ...

  9. 导入MyEclipse项目乱码

    1.右键项目属性→text file encoding →修改为UTF-8,即可自动变成正常的.

  10. objc_msgSend消息传递学习笔记 – 对象方法消息传递流程

    在Effective Objective-C 2.0 – 52 Specific Ways to Improve Your iOS and OS X Programs一书中,tip 11主要讲述了Ob ...