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. java 方法学习

    手写随机代码 public class suiji{private static final int N = 200;private static final int LEFT = 40;privat ...

  2. Redis高可用配置(Keepalived)

    主:172.16.0.104 备:172.16.0.105 VIP:172.16.0.107 客户端直接连VIP,当master 104的redis挂掉后,105作为master.当104重启后,10 ...

  3. Windows后渗透

    My 命令行下收集主机信息 使用wmic识别安装到系统中的补丁情况: wmic qfe get description,installedOn 识别正在运行的服务: sc query type= se ...

  4. Redis持久存储-AOF&RDB

    Redis中数据存储模式有2种:cache-only,persistence;cache-only即只做为"缓存"服务,不持久数据,数据在服务终止后将消失,此模式下也将不存在&qu ...

  5. 关于c++中方法名前面的双冒号

    #include "iostream" using namespace std; template <typename T> void swap(T &a, T ...

  6. TortoiseGit - 处理冲突

    处理冲突 冲突:远程的master已经被其他人更新到 2repo add 12,但是自己当前的工作区在未pull到最新前,增加了1repo add 12的改动. 右击最新的节点,选择Merge to ...

  7. Python 之 geturl 学习

    geturl为response对象的方法,由于有时候得到的网站url并不是真正的初始url而是通过重定向获得的,所以可以通过geturl方法获取真实的url.测试代码如下: from urllib2 ...

  8. erlang ets表

    一.表遍历 通过ets:first/1获取表的第一个关键字,表中下一个关键字用ets:next/2得到,直到ets:next/2返回'$end_of_table' 当多几个进程并发访问ets表时,可以 ...

  9. 一个初学者的辛酸路程-Python基础-3

    前言 不要整天沉迷于学习-. 字典 一.我想跟你聊聊字典 1.为何要有字典? 大家有没有想过为什么要有字典?有列表不就可以了吗? 也许大家会这么认为,我给大家举个例子,大家就明白了. 比如说,我通讯录 ...

  10. 借助nginx搭建反向代理服务器小例

    1 反向代理: 反向代理(Reverse Proxy)方式是指以代理服务器接收internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接 ...