SUBSET
DESCRIPTION:
一开始你有一个空集,集合可以出现重复元素,然后有Q 个操作
1. add s
在集合中加入数字s。
2. del s
在集合中删除数字s。保证s 存在
3. cnt s
查询满足a&s = a 条件的a 的个数
INPUT:
第一行一个整数Q 接下来Q 行,每一行都是3 个操作中的一个
OUTPUT:
对于每个cnt 操作输出答案
SAMPLE INPUT:
7
add 11
cnt 15
add 4
add 0
cnt 6
del 4
cnt 15
SAMPLE OUTPUT:
1
2
2
数据范围:
30%:1<=n<=1000
100%:1<=n<=200000, 0<=s<=2^16
#include<cstdio>
using namespace std;
int main()
{
freopen("subset.in","r",stdin);
freopen("subset.out","w",stdout);
int q(),s(),suffix(),preffix(),cnt();
static int ms[][];
char buf[];
scanf("%d",&q);
while(q)
{
q--;
scanf("%s%d",buf,&s);
switch(buf[])
{
case'a':
preffix=s>>;
s=s&;
for(suffix=s;suffix<=;suffix++)
if((s&suffix)==s)
ms[preffix][suffix]++;
break;
case'c':
suffix=s&;
s=s>>;
cnt=;
for(preffix=s;preffix>=;preffix--)
if((preffix&s)==preffix)
cnt+=ms[preffix][suffix];
printf("%d\n",cnt);
break;
case'd':
preffix=s>>;
s=s&;
for(suffix=s;suffix<=;suffix++)
if((s&suffix)==s)
ms[preffix][suffix]--;
break;
}
}
return ;
}
SUBSET的更多相关文章
- [LeetCode] Partition Equal Subset Sum 相同子集和分割
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- [LeetCode] Largest Divisible Subset 最大可整除的子集合
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...
- 洛谷 P1466 集合 Subset Sums Label:DP
题目描述 对于从1到N (1 <= N <= 39) 的连续整数集合,能划分成两个子集合,且保证每个集合的数字和是相等的.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,每个子 ...
- LeetCode "Largest Divisible Subset" !
Very nice DP problem. The key fact of a mutual-divisible subset: if a new number n, is divisible wit ...
- 【USACO 2.2】Subset Sums (DP)
N (1 <= N <= 39),问有多少种把1到N划分为两个集合的方法使得两个集合的和相等. 如果总和为奇数,那么就是0种划分方案.否则用dp做. dp[i][j]表示前 i 个数划分到 ...
- Leetcode 416. Partition Equal Subset Sum
Given a non-empty array containing only positive integers, find if the array can be partitioned into ...
- Leetcode 368. Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...
- ArcGIS制图之Subset工具点抽稀
制图工作中,大量密集点显示是最常遇到的问题.其特点是分布可能不均匀.数据点比较密集,容易造成空间上的重叠,影响制图美观.那么,如果美观而详细的显示制图呢? Subset Features(子集要素)工 ...
- Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...
- Subset sum problem
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...
随机推荐
- Spring cloud config-client 爬坑
配置文件 找不到属性 Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'from' in st ...
- OpenLayers3 学习-1
OpenLayers3 学习-1-简介 OpenLayers3(OL3)对OL2进行了重新设计和实现,支持多种格式的商业和免费的地图数据源.未来的版本将包括显示3D地图或利用WebGL进行大规模矢量数 ...
- centos禁止 You have new mail in /var/spool/mail/root提示
在/etc/profile 增加unset MAILCHECK
- k8s 1.10 关于rbac的坑
apiserver 启动加上--authorization-mode=RBAC 开启rbac 会生成默认role,最高权限位cluster-admin的cluster role 再关闭rbac(不加 ...
- varchar和Nvarchar区别(转)
Unicode字符集就是为了解决字符集这种不兼容的问题而产生的,它所有的字符都用两个字节表示,即英文字符也是用两个字节表示 如果还为了这个纠结,就直接看看后面的解说,做决定吧. 一般如果用到中文或者其 ...
- 链表求和12 · Add Two Numbers
反向存储,从左往右加 [抄题]: 你有两个用链表代表的整数,其中每个节点包含一个数字.数字存储按照在原来整数中相反的顺序,使得第一个数字位于链表的开头.写出一个函数将两个整数相加,用链表形式返回和.给 ...
- 马婕 2014MBA专硕考试 报刊选读 7 美国的欧洲时刻(转)
http://blog.sina.com.cn/s/blog_3e66af46010170ma.html America's European moment美国的欧洲时刻 The troubling ...
- 莫队算法详解和c实现
解析和实现 摘要: 莫队算法是一个对于区间.树或其他结构离线(在线)维护的算法,此算法基于一些基本算法,例如暴力维护,树状数组,分块,最小曼哈顿距离生成树,对其进行揉合从而产生的一个简单 ...
- html 中的<script>标签
https://www.w3.org/TR/html51/semantics-scripting.html#the-script-element 一. <script type='text/ja ...
- vue 使用axios 数据请求第三方插件的使用
axios 基于http客户端的promise,面向浏览器和nodejs 特色 浏览器端发起XMLHttpRequests请求 node端发起http请求 支持Promise API 监听请求和返回 ...