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 ...
随机推荐
- zookeeper无故挂掉,启动不起来的问题
一台测试的服务器重启后,运行zookeeperd的启动脚本显示启动成功: [plain] view plain copy JMX enabled by default Using config ...
- C#委托(匿名函数)的各种变形写法
static void TestDelegate() { //类C++11风格:指定初始化容量20,使用初始化列表给部分成员赋值 ) { , , , , -, , }; ; i < lst. ...
- 如何在ArcMap中监听键盘鼠标事件(转)
如何在ArcMap中监听键盘鼠标事件(转) Link: http://www.cnblogs.com/dyllove98/p/3155551.html 昨天有个朋友想要实现一个功能,就是在ArcMap ...
- jsp页面获取地址栏中的参数
- Go Flow Control
[Go Flow Control] 1.for没有(),必须有{}. 2.for的前后表达式可以为空. 3.没有while,for即是while. 4.无穷循环. 5.if没有(),必须有{}. 6. ...
- 禁止ImageCapture自动启动
[禁止ImageCapture自动启动] 打开ImageCapture,点开左下角菜单,把Connecting this iPhone opens:的内容改为以下选项即可.
- 使用rem的原理,62.5%,根据屏幕宽度等比压缩网页
一.前言 我们在编写网页时,往往需要兼顾网页在不同屏宽情况下的显示 而有时为了省事,没时间写新的页面,也为了兼容考虑,这就需要使用等比压缩了 等比压缩的核心是rem 二.正文 (一).rem的使用 ...
- Sprint boot notes
1. spring.io 官网 2. http://javainuse.com/spring/sprboot spring boot学习资源 3. spring boot websocketss视频 ...
- select_shape_proto算子的几种特征模式含义解析
select_shape_proto是一个非常有用的region筛选算子,但是由于难以理解,因此一般人使用得不是太多. 算子签名如下: select_shape_proto(Regions, Patt ...
- CentOS7防火墙firewall相关操作
1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...