CodeForces - 875D High Cry
直接考虑每个位置成为最右边的最大值的位置,统计不合法区间,补集转化一下就好啦。
复杂度O(N * 30)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=200005; unordered_map<int,int> mmp;
int n,a[N],L[N],ex[35],ci[35];
ll ans=0; int main(){
ci[0]=1;
for(int i=1;i<=30;i++) ci[i]=ci[i-1]<<1; scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",a+i);
for(int j=0;j<=30;j++)
if(!(a[i]&ci[j])) L[i]=max(L[i],ex[j]);
else ex[j]=i;
} fill(ex,ex+33,n+1); for(int i=n,R;i;i--){
R=n+1;
for(int j=0;j<=30;j++)
if(!(a[i]&ci[j])) R=min(R,ex[j]);
else ex[j]=i;
if(mmp.count(a[i])) R=min(R,mmp[a[i]]); ans+=(R-i)*(ll)(i-L[i]);
mmp[a[i]]=i;
} printf("%lld\n",(n*(ll)(n+1)>>1)-ans);
return 0; }
CodeForces - 875D High Cry的更多相关文章
- Codeforces Round #441(Div.2) F - High Cry
F - High Cry 题目大意:给你n个数,让你找区间里面所有数或 起来大于区间里面最大数的区间个数. 思路:反向思维,找出不符合的区间然后用总数减去.我们找出每个数掌控的最左端 和最右端,一个数 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) F. High Cry(思维 统计)
F. High Cry time limit per test 1 second memory limit per test 512 megabytes input standard input ou ...
- codeforces 876 F. High Cry(思维)
题目链接:http://codeforces.com/contest/876/problem/F 题解:一道简单的思维题,知道最多一共有n*(n+1)/2种组合,不用直接找答案直接用总的组合数减去不符 ...
- CodeForces 875 D High Cry
High Cry 题解: 把思路转换成总-非法方案数. 对于第i个点来说 找到L[i], R[i] 然后 对于所有的在[ L[i], R[i] ] 的值都 < a[i], 然后对于第i个点来说 ...
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...
- codeforces 586B/C
题目链接:http://codeforces.com/contest/586/problem/B B. Laurenty and Shop time limit per test 1 second m ...
- Codeforces刷题计划
Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- Codeforces 651E Table Compression【并查集】
题目链接: http://codeforces.com/problemset/problem/650/C 题意: 给定n*m的矩阵,要求用最小的数表示每个元素,其中各行各列的大小关系保持不变. 分析: ...
随机推荐
- Windows Phone 8.1基础教程(1) 页面导航、弹出框
1. 跳转到其他页面 Frame.Navigate(typeof(页面),参数); 2. 后退回历史页面 Frame.GoBack(); 3. 回跳时判断 if(e.NavigationMode == ...
- Creating a new dynamic form project, business modeling.
The domain logic is like there are a bunch of objects, as well as a lot of configurations, according ...
- hdu 1556(线段树之扫描线)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 Color the ball Time Limit: 9000/3000 MS (Java/Ot ...
- linux中字符串转换函数 simple_strtoul【转】
转自:http://blog.csdn.net/tommy_wxie/article/details/7480087 Linux内核中提供的一些字符串转换函数: lib/vsprintf.c [htm ...
- 访问dubbo没有权限,通过ip进行跳转服务器,并通过有权限服务器代理访问
#启动ip跳转 echo 1 > /proc/sys/net/ipv4/ip_forward vi /etc/sysctl.conf net.ipv4.ip_forward =1 sysctl ...
- [How to]简单易用的拷贝Mac文件路径方法
效果: 在你想拷贝路径的文件夹或者文件上右键会出现 copy path 选项! 实现: 1.打开finder的的Automator组件 2.选择[服务]选项,点击[选取]按钮 3.搜索操作项目中[拷贝 ...
- JS页面之间传值
父页面与子页面之间有多种传值的方式: 第一种,通过window.open的方法打开一个新的页面,在新的页面里面通过window.opener来获取对象,以下为实例 父页面: function open ...
- leetcode 之Partition List(16)
思路就是定义两个链表,一个放大的,一个放小的,最后将两个连起来,注意细节问题. ListNode *partionList(ListNode *head, int value) { ListNode ...
- redis使用教程
一.redis 的安装 官方就是个坑:只说make一下即可用,确实可以用,我以为装好了,结果好多问题: 安装步骤:make => make test => make install 1 ...
- 辨析各类web服务器:Apache/Tomcat/Jboss/Nginx/等,还有Nodejs
先说一下各类服务器能干啥,特点是啥,然后在区分他们的类别. (1)Apache: Apache是指Apache软件基金会的Apache HTTP Server, 它能够接收http请求,然后返回各类资 ...