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

  1. [LeetCode] Partition Equal Subset Sum 相同子集和分割

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  2. [LeetCode] Largest Divisible Subset 最大可整除的子集合

    Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...

  3. 洛谷 P1466 集合 Subset Sums Label:DP

    题目描述 对于从1到N (1 <= N <= 39) 的连续整数集合,能划分成两个子集合,且保证每个集合的数字和是相等的.举个例子,如果N=3,对于{1,2,3}能划分成两个子集合,每个子 ...

  4. LeetCode "Largest Divisible Subset" !

    Very nice DP problem. The key fact of a mutual-divisible subset: if a new number n, is divisible wit ...

  5. 【USACO 2.2】Subset Sums (DP)

    N (1 <= N <= 39),问有多少种把1到N划分为两个集合的方法使得两个集合的和相等. 如果总和为奇数,那么就是0种划分方案.否则用dp做. dp[i][j]表示前 i 个数划分到 ...

  6. Leetcode 416. Partition Equal Subset Sum

    Given a non-empty array containing only positive integers, find if the array can be partitioned into ...

  7. Leetcode 368. Largest Divisible Subset

    Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...

  8. ArcGIS制图之Subset工具点抽稀

    制图工作中,大量密集点显示是最常遇到的问题.其特点是分布可能不均匀.数据点比较密集,容易造成空间上的重叠,影响制图美观.那么,如果美观而详细的显示制图呢? Subset Features(子集要素)工 ...

  9. Largest Divisible Subset

    Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of ...

  10. Subset sum problem

    https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...

随机推荐

  1. C#格式化数字

    var t1 = Profiler.GetMonoHeapSize()/div; var t2 = Profiler.GetMonoUsedSize() / div; var t3 = Profile ...

  2. 用API处理位图

    procedure TForm1.Button1Click(Sender: TObject); var dc : hdc; MemDc : hdc; MemBitmap : hBitmap; OldM ...

  3. ArcGIS中各种合并要素(Union、Merge、Append、Dissolve)的异同点分析 转载

    标签: arcgis 杂谈 分类: GISArcGIS中将两个要素类合并成一个要素有Union.Dissolve.Append.Merge等,在Arctoolbox中均有相应工具,但功能上有所不同:U ...

  4. $in 操作符

    [$in 操作符] The $in operator selects the documents where the value of a field equals any value in the ...

  5. LevelDB 的缺憾

    [LevelDB 的缺憾] 1.Snapshots 只能通过 DB::GetSnapshot() 创建,意即只能创建当下的 Snapshot. 2.

  6. Bourne Shell:控制语句、条件判断、文本处理、常用命令

    条件判断是一个程序获得智能的基础,而Bourne Shell脚本则通过命令 [ 来模拟大多数编程语言中的条件表达式. shell中支持的控制结构有: (1) if then else fi (2) f ...

  7. mac下yii安装

    下载https://github.com/yiisoft/yii2-app-advanced/releases,里边没index.php文件 1.http://www.yiichina.com/que ...

  8. Linux主流发行版本

    一.简介 而工欲善其事,必先利其器,Linux的世界相當廣大,除了最著名的Ubuntu以外還有不少發行版.然文人相輕,自古皆然,了解不同發行版的優勢不只嘴上攻防用的上,也是學Linux一個有趣的地方! ...

  9. libevent 简单学习

    //NetworkManager.h #ifndef _NET_WORK_MANAGER_ #define _NET_WORK_MANAGER_ #include "event2/util. ...

  10. [IIS] 测试的产品登陆之后有个引用外部站点js的请求半天都无法返回,导致网页一直在打转,Selenium的driver也无法对页面进行下一步的操作

    测试的产品登陆之后有个引用外部站点js的请求半天都无法返回: https://cdn.heapanalytics.com/js/heap-3497400264.js 这个js如果是在美国的机器上就可以 ...