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

题目大意:有t个询问,每个询问有三种操作

①加入一个数值为a[i]的数字

②消除一个数值为a[i]的数字

③给一个字符串s,s中分别表示0和1,0表示目前该位为偶数,1表示目前该位为奇数。然后询问目前数组中和s每一位能匹配的个数。如果数组中目前的该数字比s的len要短,那么我们就在s的左边一直加0。如果数组中的目前的数字比s的len长,那么就在该数组的左边一直加0就好了。问能和s匹配的有几个,并输出

思路:我是用map来标记奇偶的,因为有前导0,所以我们把0的val都改成2,首先dfs出所有的情况,并每次给他标上一个ID,然后每次询问的时候找ID就好了。

貌似看到别人用的是trie树来做。。。

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha; printf("haha\n");
const int maxn = 1e6 + ;
int dfsclock;
map<LL, int> ID;
LL cnt[maxn], cnt2[maxn]; LL cal(LL x, int n){
LL res = ;
while (n){
if (n & ) res = res * x;
x = x * x;
n >>= ;
}
return res;
} void dfs(LL val, int cell){
if (cell == ) return ;
LL add = cal(10LL, cell);
for (LL i = ; i <= ; i++){
ID[val + add * i] = ++dfsclock;
dfs(val + add * i, cell + );
}
}
///1~18位,变成0~17位
int main(){
dfs(0LL, );
ID[] = ++dfsclock;
int t; cin >> t;
char ch[];
for (int i = ; i < t; i++){
char s[]; scanf("%s %s", s, ch);
int len = strlen(ch);
LL val = ;
if (s[] == '+') {
for (int j = len - ; j >= ; j--){
ch[j] -= '';
if (ch[j] % == ) {
val += * cal(10LL, len - - j);
}
else {
val += * cal(10LL, len - - j);
}
cnt[ID[val]]++;
}
for (int i = len; i <= ; i++){///扩张到18位的
val += * cal(10LL, i);
cnt[ID[val]]++;
}
}
else if (s[] == '-'){
for (int j = len - ; j >= ; j--){
ch[j] -= '';
if (ch[j] % == ) {
val += * cal(10LL, len - - j);
}
else {
val += * cal(10LL, len - - j);
}
cnt[ID[val]]--;
}
for (int i = len; i <= ; i++){
val += * cal(10LL, i);
cnt[ID[val]]--;
}
}
else if (s[] == '?'){
LL ans = ;
int pos = ;
for (int i = ; i <= len - ; i++){
if (ch[i] != '') {
pos = i; break;
}
}
for (int i = len - ; i >= ; i--){
if (ch[i] == '') val += * cal(10LL, len - - i);
else val += * cal(10LL, len - - i);
}
ans += cnt[ID[val]];
for (int i = len; i <= ; i++){
LL tmp = * cal(10LL, i);
ans += cnt[ID[val + tmp]] - cnt[ID[val]];///每次增加的匹配数一定是在前一个集合里面没有出现过的
val += tmp;
}
printf("%I64d\n", ans);
}
}
return ;
}

Codeforces Round #371 (Div. 2) C 大模拟的更多相关文章

  1. Codeforces Round #371 (Div. 1)

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

  2. Codeforces Round #398 (Div. 2) A. Snacktower 模拟

    A. Snacktower 题目连接: http://codeforces.com/contest/767/problem/A Description According to an old lege ...

  3. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  4. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. Codeforces Round #543 (Div. 2) D 双指针 + 模拟

    https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...

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

  8. Codeforces Round #371 (Div. 2)B. Filya and Homework

    题目链接:http://codeforces.com/problemset/problem/714/B 题目大意: 第一行输入一个n,第二行输入n个数,求是否能找出一个数x,使得n个数中的部分数加上x ...

  9. Codeforces Round #371 (Div. 2) - B

    题目链接:http://codeforces.com/contest/714/problem/B 题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最 ...

随机推荐

  1. Xcode-之项目重命名

    一.前言 在iOS开发过程中,对于以前的项目或者想改一下项目的名字,都会遇到比较麻烦的事情.直接改项目名,然而它会牵扯一大堆问题,并且不能把所有的名字都能改过来.有些文件改了项目名后,引导路径错误,导 ...

  2. Intent的几种Flag的不同

    冬天有点冷,不想写博客. 研究下Intent的几种Flag的不同: 1,FLAG_ACTIVITY_CLEAR_TOP:会清理掉目标activity栈上面所有的activity Intent inte ...

  3. GreenPlum学习之(Share-nothing)架构

    当今世界是一个信息化的世界,我们的生活中无论是生活.工作.学习都离不开信息系统的支撑.而信息系统的背后用于保存和处理最终结果的地方就是数据库.因此数据库系统就变得尤为重要,这意味着如果数据库如果面临问 ...

  4. 2016 JetBrains 开发者日遇见开发神器的创造者

    JetBrains团队首次落地中国北京!2016 JetBrains开发者日将于2016年11月26日星期六10:00-16:30在中国北京举办! 这一次,我们将与社区演讲者一起谈论现代软件开发语言. ...

  5. JavaScript的内置对象(Date日期+string字符串)基础语法总结

    1.Date日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 1)定义一个时间对象 : var Udate=new Date(); //注意:使用关键字new,Date()的首 ...

  6. 彻底解决tap“点透”,提升移动端点击响应速度

    申明!!!最后发现判断有误,各位读读就好,正在研究中.....尼玛水太深了 前言 近期使用tap事件为老夫带来了这样那样的问题,其中一个问题是解决了点透还需要将原来一个个click变为tap,这样的话 ...

  7. scale相关设置—手动设置

    在ggplot2 中,可以进行手动设置的函数有: scale_colour_manual(..., values).scale_fill_manual(..., values). scale_size ...

  8. vs2012常用快捷键总结

    ctrl+k+c  注释 ctrl+k+u 取消注释 ctrl+m+t 折叠代码 ctrl+t 取消折叠 ctrl+k+d 调节代码 ctrl+f 查找 ctrl+g  跳转行(一般调试的时候显示哪行 ...

  9. OpenGL多视口

    #include <gl/glew.h> #include <gl/freeglut.h> #include <iostream> ; ; float rtri = ...

  10. Linux(power服务器)中kettle(2)

    Hadoop集群硬件环境 4台机器 ip地址 172.16.1.131 172.16.1.132 172.16.1.133 172.16.1.134 每台内存16G 8核cpu 直接使用报错: