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,然后与问的 ...
随机推荐
- 知方可补不足~SQL数据库用户的克隆,SQL集群的用户同步问题
我们知道在为sqlserver建立功能数据库时,通过会为库再建立一个登陆名,而这个登陆名时,只用来管理这个数据库,这是安全的,正确的.
- fastjson把对象转化成json避免$ref
转自http://blog.csdn.net/wxwzy738/article/details/30244993 DisableCircularReferenceDetect来禁止循环引用检测: JS ...
- NSTimer运行机制和线程问题
A.首先要理解NSTimer运行机制和Runloop之间的关系: 1.IOS的Run Loops机制 Run Loops是线程的基础部份,任何线程,包括主结程,都包含了一个run loop对象,Coc ...
- jquery 延迟加载代码
<!--引入以下两个js文件--> <script type="text/javascript" src="./js/jquery.min.js&quo ...
- SAP ABAP 处理字符串串串串串串串串(详细)
关于ABAP中处理字符串的方法,非常详细,学习过程中总结一下分享给大家,,, ABAP/4 提供多个处理类型 C 即字符串 的数据对象的关键字. 处理字符串 的方法有: 1.拆分字符串split 2. ...
- JQuery.Ajax之错误调试帮助信息介绍
下面是Jquery中AJAX参数详细列表: timeout Number 设置请求超时时间(毫秒).此设置将覆盖全局设置. async Boolean (默认: true) 默认设置下,所有请求均为异 ...
- hiberante中get和load方法的区别
1.从返回结果上对比: load方式检索不到的话会抛出org.hibernate.ObjectNotFoundException异常 get方法检索不到的话会返回null 2.从检索执行机制上对比: ...
- 在与SQL Server建立连接时出现与网络相关的或特定于实例的错误
向往前一样.学习牛腩新闻公布系统的视频,写程序,打开数据库.出现一个框框,具体内容例如以下: 数据库连接不上.全部的工作都要歇班,捣鼓了会儿,简单总结一下解决该问题的方法. 首先:第一步,程序--SQ ...
- Cookie API
Cookie API All cookies created by the Nova framework are encrypted and signed with an authentication ...
- eclipse git插件配置
一.Eclipse上安装GIT插件EGit Eclipse的版本eclipse-java-helios-SR2-win32.zip(在Eclipse3.3版本找不到对应的 EGit插件,无法安装) E ...