Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K
题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作,问所有的值有多少种?
分析:
假设现在想要求解区间$[1,i]$内的答案,那么需要先处理出$[1,i-1],[2,i-1],[3,i-1]......[i-1,i-1]$。然后将这些答案暴力与$a_i$取$|$。
代码:
#include<bits/stdc++.h>
using namespace std;
# define ll long long
const int maxn = 2e5+;
int a[maxn];
int main(){
int T;scanf("%d",&T);
while(T--){
int n;scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
set<int>ans;set<int>st;set<int>tmp;
for(int j=;j<=n;j++){
tmp.clear();tmp.insert(a[j]);
for(auto i : st) tmp.insert(i|a[j]);
st=tmp;
for(auto i: tmp) ans.insert(i);
}
printf("%d\n",ans.size());
}
return ;
}
Codeforces gym102152 K.Subarrays OR的更多相关文章
- K - Subarrays OR Gym - 102152K (思维)
题目链接: K - Subarrays OR Gym - 102152K 题目大意:T组测试样例,然后n个数,让你求每一个l,r中有多少个不同的异或值. 具体思路: 对于(1,i)这个区间, 我们当前 ...
- codeforces 1133E K Balanced Teams
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
- Codeforces 665E. Beautiful Subarrays (字典树)
题目链接:http://codeforces.com/problemset/problem/665/E (http://www.fjutacm.com/Problem.jsp?pid=2255) 题意 ...
- Codeforces 655E Beautiful Subarrays【01trie树】
题目链接: http://codeforces.com/contest/665/problem/E 题意: 求异或值大于给定K的区间个数. 分析: 首先我们可以得到区间前缀的异或值. 这样我们将这个前 ...
- Codeforces 1133E - K Balanced Teams - [DP]
题目链接:https://codeforces.com/contest/1133/problem/C 题意: 给出 $n$ 个数,选取其中若干个数分别组成 $k$ 组,要求每组内最大值与最小值的差值不 ...
- codeforces 1269E K Integers (二分+树状数组)
链接:https://codeforces.com/contest/1269/problem/E 题意:给一个序列P1,P2,P3,P4....Pi,每次可以交换两个相邻的元素,执行最小次数的交换移动 ...
- codeforces 1282B2. K for the Price of One (Hard Version) (dp)
链接 https://codeforces.com/contest/1282/problem/B2 题意: 商店买东西,商店有n个物品,每个物品有自己的价格,商店有个优惠活动,当你买恰好k个东西时可以 ...
- codeforces 665E Beautiful Subarrays
题目链接 给一个数列, 让你找出异或结果大于等于k的子序列的个数. 因为任意一段序列的异或值都可以用前缀异或和来表示, 所以我们先求出前缀异或和. 我们考虑字典树, 对于每一个前缀sum, 我们先查询 ...
- Codeforces 544E K Balanced Teams (DP)
题目: You are a coach at your local university. There are nn students under your supervision, the prog ...
随机推荐
- python 爬虫启航
1. 使用excel(简单使用) 数据- 自网站-导入 2.you-get python爬虫入门 1.环境配置 python,request,lxml 2.原理 爬虫的框架如下: 1.挑选种子URL: ...
- Rabbitmq 与springboot 结合
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...
- Rabbitmq(4) 订阅模式
p;发送者 x: 交换机 消息队列 c: 接收者 ------------------------------------------------------------------------ 发送 ...
- input 选择框改变背景小技巧
最近在项目中遇到一个问题,想要改变input选择框的背景,然而,令我没有想到的是,竟然无法直接改变背景的颜色 通常情况下:我们都可以通过改变元素的 background-color 的值来改变元素的背 ...
- 【395】yield 和 yield from
yield:生成器 yield from:将生成器 yield 的内容相当于逐一在 yield 一般 参考:Python 3: Using "yield from" in Gene ...
- MFC---关于string.h相关函数
1.在VS2005中使用strcpy.strcat.sprintf出现如:mfc中'strcpy' was declared deprecated警告 这是因为VS2005中认为CRT中的一组函数如果 ...
- linux 下将tomcat注册成服务并开机启动
一.将startup.sh和shutdown.sh新建软连接到/usr/bin ln -s /usr/local/apache-tomcat-8.5.38/bin/startup.sh /usr/bi ...
- Django 表关系
1.自定义主键字段的创建 AutoFiled(pirmary_key=True) # 一般不会自定义2.order_by asc desc 1. 表关系的创建- OneToOne student = ...
- python 函数编程
def test1(): print('in the test1') def test2(): print('in the test2') return 1 def test3(): print('i ...
- Spring 框架XML文件的配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns:xsi="http://www ...