题目大意,

就是给你几种操作,添加, 删除,查询

裸的字典树题目..

#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e6+40;
typedef long long ll;
const int  inf = 0x3fffffff;
void read(int &x) {
char ch; bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
x *= 1 - 2 * flag;
}
char temp[20],str[20];
int tot = 0;
struct Tree
{
int flag[2000000][27];
int sum[2000000];
void buildtree()
{
memset(flag[0],0,sizeof(flag[0]));
memset(sum,0,sizeof(sum));
}
void Insert(int val)
{
int fa=0;
int len = strlen(str);
for(int i=len-1;i>=0;i--)
{
int id = str[i]-'0';
id%=2;
if(!flag[fa][id])
{
flag[fa][id]=++tot;
memset(flag[tot],0,sizeof(flag[tot]));
// memset(sum[tot],0,sizeof(sum[tot]));
}
fa  = flag[fa][id];
}
sum[fa]+=val;
}
int getres()
{
int fa=0;
int len = strlen(str);
for(int i=len-1;i>=0;i--)
{
int id = str[i]-'0';
id%=2;
if(!flag[fa][id])return 0;
fa=flag[fa][id];
}
return sum[fa];
}
}tree;
int main() {
int n;
read(n);
tree.buildtree();
while(n--){
char s1;
cin>>s1>>str;
int len=strlen(str);
if(len!=18){
for(int i=0;i<18-len;i++)temp[i]='0';
for(int i=18-len;i<18;i++)temp[i]=str[i-18+len];
for(int i=0;i<18;i++)str[i]=temp[i];
}
if(s1=='+'||s1=='-')
{
if(s1=='+')
tree.Insert(1);
else tree.Insert(-1);
}
else{
cout<<tree.getres()<<endl;
}
}
return 0;
}

转载于:https://www.cnblogs.com/DreamKill/p/9369657.html

A. Sonya and Queries相关推荐

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

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

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

  3. Sonya and Queries CodeForces - 714C

    Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an i ...

  4. CodeForces 714C Sonya and Queries

    原题链接 题意 往一个多重集合 (元素有可能相同) 里添加一个数 (+ ai) 或去除一个数 (- ai); ? s 代表给出一个数每位数所遵循的奇偶性的规则: 偶数为 0, 奇数为 1. 找出多重集 ...

  5. CF #371 (Div. 2) C、map标记

    1.CF #371 (Div. 2)   C. Sonya and Queries  map应用,也可用trie 2.总结:一开始直接用数组遍历,果断T了一发 题意:t个数,奇变1,偶变0,然后与问的 ...

  6. Codeforces 371 A,B,C

    表示只会水题,A,B,C; Meeting of Old Friends 题意为:两个朋友要见一面,然而两个任都各自有一个时间段有时间,其中在K这个时间点不行,问:他俩见面的时间最长事多少?</ ...

  7. 2016区域赛前冲刺训练

    UPD 2016.10.23 shift-and (2题) Codeforces 训练 现在已经完成了: 191 [Codeforces Round #377] (6/6) Div 2 A Buy a ...

  8. CSUST 8.5 早训

    ## Problem A A - Meeting of Old Friends CodeForces - 714A 题意: 解题说明:此题其实是求两段区间的交集,注意要去除掉交集中的某个点. 题解: ...

  9. 【原】YUI压缩与CSS media queries下的bug

    大概是上个月,使用YUI压缩一个css文件后,发现只要是被压缩后的css文件有部分根本无法工作,一直都不知啥问题引起的,让我感到头疼. 今天发现了只要是在媒体查询中的样式无法起作用,于是才开始怀疑是m ...

最新文章

  1. iOS单个应用程序的最大可用内存是多少?
  2. 【人脸表情识别】不得不读的重要论文推荐(2015-2018篇)
  3. python中return返回值为函数名_Python函数返回值
  4. Java反射课程教程
  5. Chrome安装路径
  6. Docker与虚拟机技术
  7. HackerOne漏洞奖励计划扩展至开源漏洞
  8. 将当前登录用户去重显示。
  9. leetcode第一刷_Merge Intervals
  10. MPLS OPTION-B
  11. (双硬盘(SSD+HDD)/单硬盘)双系统win10+ubuntu18.04安装记录
  12. 6、微信小程序的布局
  13. 拼音加加符号编码列表
  14. 单片机内部FLASH的字节操作
  15. 中国气候分布矢量图_如何用30行代码构建气候图
  16. win10安装—手记
  17. 解决Visio中对象不能通过键盘方向键微调位置
  18. arduino电子时钟 简易版
  19. 常见的HTTP Headers有哪些?
  20. 等不到明天了,office2021专业正式版镜像来了

热门文章

  1. [容易] 最短路实例(有条件的最短路)
  2. 用JavaScript判断一个数是否是素数
  3. Android MTK Camera驱动代码分析
  4. 【数学】手写开根号(牛顿迭代法 | 二分)
  5. Adaptive Context Network for Scene Parsing
  6. vs2019创建dll以及使用
  7. python批量检索文献_快解锁新姿势,教你如何用Python搞定文献搜索和科研图片!...
  8. 【问题】vcenter7升级遇到“Exception in invoking authentication handler unidentifiable C++ exception”
  9. 网络设备配置与管理-综合实验1
  10. Altium Designer学习