Codeforces Round #371 (Div. 2) C. Sonya and Queries

时间:2023-01-31 07:41:28

题目链接

分析: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的更多相关文章

  1. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; C&period; Sonya and Queries 水题

    C. Sonya and Queries 题目连接: http://codeforces.com/contest/714/problem/C Description Today Sonya learn ...

  2. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; C&period; Sonya and Queries —— 二进制压缩

    题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...

  3. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; C&period; Sonya and Queries&lbrack;Map|二进制&rsqb;

    C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round &num;371 &lpar;Div&period; 1&rpar; C&period; Sonya and Problem Wihtout a Legend 贪心

    C. Sonya and Problem Wihtout a Legend 题目连接: http://codeforces.com/contest/713/problem/C Description ...

  5. Codeforces Round &num;371 &lpar;Div&period; 2&rpar;E&period; Sonya and Problem Wihtout a Legend&lbrack;DP 离散化 LIS相关&rsqb;

    E. Sonya and Problem Wihtout a Legend time limit per test 5 seconds memory limit per test 256 megaby ...

  6. Codeforces Round &num;371 &lpar;Div&period; 1&rpar; C - Sonya and Problem Wihtout a Legend

    C - Sonya and Problem Wihtout a Legend 思路:感觉没有做过这种套路题完全不会啊.. 把严格单调递增转换成非严格单调递增,所有可能出现的数字就变成了原数组出现过的数 ...

  7. Codeforces Round &num;371 &lpar;Div&period; 1&rpar;

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

  8. 递推 Codeforces Round &num;186 &lpar;Div&period; 2&rpar; B&period; Ilya and Queries

    题目传送门 /* 递推:用cnt记录前缀值,查询区间时,两个区间相减 */ #include <cstdio> #include <algorithm> #include &l ...

  9. Codeforces Round &num;371 &lpar;Div&period; 2&rpar; 转换数字

    C. Sonya and Queries time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. C&sol;C&plus;&plus;&colon; C&plus;&plus;可调用对象详解

    C++中有几种可调用对象:函数,函数指针,lambda表达式,bind创建的对象,以及重载了函数调用符的类. 1. 函数 函数偏基础的东西,在这里不再叙述.重点讲下C++11的某些重要特性和函数指针. ...

  2. malloc杀内存于无形

    C语言中的malloc函数是分配内存用的,函数内部生命的变量也会分配内存,但是当函数释放的时候内存也就释放了,这样就不会占用内存了,但是malloc函数不同, 如下 typedef struct No ...

  3. HTML DOM(学习笔记一)

    嗯,工作也有一段时间了,对编程的认识也深入了一些,以前认为HTML/CSS/JAVASCRIPT是比较简单的,看网上的教程就可以了,W3C是我学习这些知识常去的一个网站,非常感谢她让我学习到了更多的一 ...

  4. hdu-5587 Array&lpar;回溯&rpar;

    题目链接: Array Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) P ...

  5. C&sol;C&plus;&plus;之Exercise

    一.C/C++之初学Demo---C++调用C.h文件使用实例: 工程结构: exercise.h code: #ifndef _EXERCISE_H_ #define _EXERCISE_H_ #i ...

  6. jsoneditor显示Json data

    Git开源地址:https://github.com/josdejong/jsoneditor/blob/master/docs/api.md 1.引用JS文件 <!-- jsoneditor ...

  7. 80-th Level Archeology

    80-th Level Archeology time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  8. C&plus;&plus;位运算

    移位运算 要点 1 它们都是双目运算符,两个运算分量都是整形,结果也是整形.     2 " < <" 左移:右边空出的位上补0,左边的位将从字头挤掉,其值相当于乘2. ...

  9. Java虚拟机(五):JVM调优命令

    运用jvm自带的命令可以方便的在生产监控和打印堆栈的日志信息帮忙我们来定位问题!虽然jvm调优成熟的工具已经有很多:jconsole.大名鼎鼎的VisualVM,IBM的Memory Analyzer ...

  10. c语言----&lt&semi;项目&gt&semi;&lowbar;小游戏&lt&semi;2048&gt&semi;

    2048 小游戏 主要是针对逻辑思维的一个训练. 主要学习方面:1.随机数产生的概率.2.行与列在进行移动的时候几种情况.3.MessageBox的使用 #include <iostream&g ...