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. 02--Java TCP Socket编程

    一.基础知识 1. TCP状态转换知识,可参考: http://www.cnblogs.com/qlee/archive/2011/07/12/2104089.html 2. TCP/IP五层模型   ...

  2. js---DOM元素节点

    创建新的 HTML 元素如需向 HTML DOM 添加新元素,您必须首先创建该元素(元素节点),然后向一个已存在的元素追加该元素. 实例1: <!DOCTYPE html> <htm ...

  3. [妙味JS基础]第十二课:数组随机、数组去重

    知识点总结 json var json={'name':'abc'} 属性加分号为安全的写法 json: 只能用for in 数组:for和for in 都可以使用 json没有length和下标 数 ...

  4. mog使用指南

    mog使用指南 mgo简介 mgo(音mango)是MongoDB的Go语言驱动,它用基于Go语法的简单API实现了丰富的特性,并经过良好测试. 官方网站:http://labix.org/mgo. ...

  5. javascript基础(三)运算

    原文http://pij.robinqu.me/ 递增递减操作符(包括前置和后置).一元正负符号操作符 这些操作符适用于任何数据类型的值,针对不同类型的值,该操作符遵循以下规则(经过对比发现,其规则与 ...

  6. CABasicAnimation 几种停止的回调

    一.编写一个简单的动画,使一个UIview从屏幕的左上角移动到左下角,间隔时间3S // // ViewController.m // CAAnimationTest // // Created by ...

  7. IOS真机Profile时调用树中的对象只是显示地址,没有显示symbol name

    解决问题的办法: 1.确认工程设置中的Scheme,profile选项对应的是debug版本还是release版本 2.确认工程设置中debug版本或者release版本是否生成了符号表 " ...

  8. html5 读写sqlite数据库

    var db = openDatabase('MyData','','My Database',102400); //首先它创建一个数据库表,里面有3个字段 db.transaction(functi ...

  9. iOS之网络编程

    发送HTTP请求的方法 在HTTP/1.1协议中,定义了8种发送http请求的方法 GET.POST.OPTIONS.HEAD.PUT.DELETE.TRACE.CONNECT.PATCH 根据HTT ...

  10. 将数组写入plist文件

    data 加载plist [NSBundle mainBundle] [arr writeToURL:<#(NSURL *)#> atomically:<#(BOOL)#>]