Codeforces Round #371 (Div. 2) C. Sonya and Queries
分析:01trie树,很容易就看出来了,也没什么好说的。WA了一发是因为没有看见如果数字位数大于01序列的时候01序列也要补全0。我没有晚上爬起来打,白天发现过的人极多。
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define offcin ios::sync_with_stdio(false)
#define sigma_size 26
#define lson l,m,v<<1
#define rson m+1,r,v<<1|1
#define slch v<<1
#define srch v<<1|1
#define sgetmid int m = (l+r)>>1
#define LL long long
#define ull unsigned long long
#define mem(x,v) memset(x,v,sizeof(x))
#define lowbit(x) (x&-x)
#define bits(a) __builtin_popcount(a)
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const int INF = 0x3f3f3f3f;
const LL INFF = 1e18;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const LL mod = 1e9+7;
const int maxmat = 10;
const ull BASE = 31;
/*****************************************************/
const int maxn = 3e5 + 5;
int ch[maxn][2];
int sz = 1;
LL val[maxn];
void addnode(LL x) {
LL base = 1;
int u = 0;
for (int i = 0; i < 18; i ++) {
int c = (x / base) % 10;
c %= 2;
if (!ch[u][c]) {
ch[u][c] = sz ++;
mem(ch[sz], 0);
val[sz] = 0;
}
u = ch[u][c];
base *= 10LL;
}
val[u] ++;
}
void deletenode(LL x) {
LL base = 1;
int u = 0;
for (int i = 0; i < 18; i ++) {
int c = (x / base) % 10;
c %= 2;
u = ch[u][c];
base *= 10LL;
}
val[u] --;
}
int searchnode(char *s) {
int len = strlen(s);
LL ans = 0;
int u = 0, c;
for (int i = 0; i < 18; i ++) {
if (i < len) c = s[len - 1 - i] - '0';
else c = 0;
u = ch[u][c];
ans += val[u];
}
return ans;
}
int main(int argc, char const *argv[]) {
int N;
cin>>N;
char op[2];
char s[20];
LL x;
for (int i = 0; i < N; i ++) {
scanf("%s", op);
if (op[0] == '+') {
cin>>x;
addnode(x);
}
else if (op[0] == '-') {
cin>>x;
deletenode(x);
}
else {
scanf("%s", s);
cout<<searchnode(s)<<endl;
}
}
return 0;
}
Codeforces Round #371 (Div. 2) C. Sonya and Queries的更多相关文章
- 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 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 Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...
- Codeforces Round #371 (Div. 1) C - Sonya and Problem Wihtout a Legend
C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- 递推 Codeforces Round #186 (Div. 2) B. Ilya and Queries
题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...
- Codeforces Round #371 (Div. 2) 转换数字
C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- HTTP下载文件名称编码说明
HTTP下载保存文件名 下载文件需要保存的名称 在响应报文头中 Content-Disposition 响应报文头域中指定, 例如 Content-Disposition: attachment; f ...
- ACM Coder [T1002] 一直wrong answer,不知道为什么。上代码!就对就对!
忘了改了什么,后来居然对了!做打不死的菜鸟! #include <stdio.h> #include <stdbool.h> #define arrayLength 20 #d ...
- ligerui_ligerTree_007_ligerTree动态加载节点
ligerui:ligerTree:动态加载节点: 源码地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图: 代码:json.txt ...
- jqgrid定义多选操作
先定义: var SelectRowIndx; 然后加入以下属性: multiselect: true, onSelectRow: function () { SelectRowIndx = G ...
- Main.C时钟设定
void Main(void) 时钟设定:400M 100M 50M 得到 1:4:8 进而需要得到 hdivn=2 : pdivn=1: i = 2 ; //用于选择CUP核的频率 ...
- 关于input内容监听(change)
js的话利用input的onchange事件 而jquery的话利用change()函数,代码如下: <!DOCTYPE html> <html> <head> & ...
- GAT2.0使用文档(单接口开发)
3 开始写用例 3.1接口用例开发 1) 准备工作 l 第一步从github(https://github.com/GeneralAutomationTesting/GAT2.0 ...
- 一个用php写的人民币数字转人民币大写的函数
function num2rmb ($num) { $c1 = "零壹贰叁肆伍陆柒捌玖"; $c2 = "分角元拾佰仟万拾佰仟亿"; ...
- MYSQL #1064错误
你的给出的代码里option为MYSQL关键字,不能直接写,需要用`包括起来(它为数字键1左边的键上的字符),为: `option` varchar(50) NOT NULL default ''
- java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
在更新项目之后,做了一定的改动后发现竟然报错了,刚才还好好的. java.sql.SQLException: Access denied for user 'root'@'localhost' (us ...