C. Sonya and Queries
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的更多相关文章
- 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 ...
- Codeforces 714C. Sonya and Queries Tire树
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...
- codeforces 713A A. Sonya and Queries(状态压缩)
题目链接: A. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries 水题
C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...
- 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 ...
- Codeforces 713A. Sonya and Queries
题目链接:http://codeforces.com/problemset/problem/713/A 题意: Sonya 有一个可放置重复元素的集合 multiset, 初始状态为空, 现给予三种类 ...
- Codeforces Round #371 (Div. 2) C. Sonya and Queries
题目链接 分析:01trie树,很容易就看出来了,也没什么好说的.WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0.我没有晚上爬起来打,白天发现过的人极多. /******** ...
- [Codeforces_713A]Sonya and Queries
题目链接 http://codeforces.com/problemset/problem/713/A 题意 三种操作: + ai 集合里加一个整数ai,相同数记为多个. - ai 集合里减一个 ...
- CF #371 (Div. 2) C、map标记
1.CF #371 (Div. 2) C. Sonya and Queries map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...
随机推荐
- 多路径配置vlome group共享存储,VG的更新。
1. PV的概念: a) 一块物理磁盘一块物理硬盘在被LVM管理时被称为“物理卷”. b) 在LVM能对其进行管理之前需要在硬盘上产生一些特殊的数据结构,这个过程就是建立 ...
- 常用SQL代码段
代码使用时须测试. --聚合函数 use pubs go select avg(distinct price) --算平均数 from titles where type='business' go ...
- Postfix上的反垃圾邮件的四个方法
在介绍如何配置Postfix的smtp配置之前有必要首先介绍一下它的背景和特点.Postfix是一个由IBM资助下由WietseVenema 负责开发的自由软件工程的一个产物,其目的是为用户提供除se ...
- cocos2d-x 判断点击命中坐标的几种方法
转自:http://www.cnblogs.com/jiackyan/archive/2013/04/14/3019893.html //重载 virtual bool ccTouchBegan(CC ...
- struts2标签具体解释
要在jsp中使用Struts2的标志,先要指明标志的引入.通过jsp的代码的顶部增加下面的代码: <%@taglib prefix="s" uri="/struts ...
- 7Zip 来备份重要文件(夹)
body { font-family: 宋体,Georgia,Helvetica,Arial,sans-serif,宋体,serif; font-size: 10.5pt; line-height: ...
- tomcat的几种部署方法
原文:http://blog.163.com/pg_roger/blog/static/185884389201172921211937/ 1.将应用文件夹或war文件(均指编译好的文件)塞到tomc ...
- 02---CSS整理
一.概述 CSS(cascading style sheet) 层叠样式表 提供比HTML更强大的页面排版.美化工具 CSS将网页内容和显示样式进行分离,提高了显示 ...
- com.ulitis.www
package com.ulitis.www; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io ...
- Web安全测试周末公开班计划5月24、25日开课,欢迎报名参加!
Web安全测试周末公开班计划5月24.25日开课,欢迎报名参加! 课程大纲参考: http://gdtesting.com/product.php?id=107 报名咨询: 黎小姐 QQ:241448 ...