题面在这里!

直接考虑每个位置成为最右边的最大值的位置,统计不合法区间,补集转化一下就好啦。

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

  1. Codeforces Round #441(Div.2) F - High Cry

    F - High Cry 题目大意:给你n个数,让你找区间里面所有数或 起来大于区间里面最大数的区间个数. 思路:反向思维,找出不符合的区间然后用总数减去.我们找出每个数掌控的最左端 和最右端,一个数 ...

  2. 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 ...

  3. codeforces 876 F. High Cry(思维)

    题目链接:http://codeforces.com/contest/876/problem/F 题解:一道简单的思维题,知道最多一共有n*(n+1)/2种组合,不用直接找答案直接用总的组合数减去不符 ...

  4. CodeForces 875 D High Cry

    High Cry 题解: 把思路转换成总-非法方案数. 对于第i个点来说 找到L[i], R[i] 然后 对于所有的在[ L[i], R[i] ]  的值都 < a[i], 然后对于第i个点来说 ...

  5. 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 ...

  6. codeforces 586B/C

    题目链接:http://codeforces.com/contest/586/problem/B B. Laurenty and Shop time limit per test 1 second m ...

  7. Codeforces刷题计划

    Codeforces刷题计划 已完成:-- / -- [Codeforces370E]370E - Summer Reading:构造:(给定某些数,在空白处填数,要求不下降,并且相邻差值<=1 ...

  8. Codeforces Round #441 (Div. 2)

    Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...

  9. Codeforces 651E Table Compression【并查集】

    题目链接: http://codeforces.com/problemset/problem/650/C 题意: 给定n*m的矩阵,要求用最小的数表示每个元素,其中各行各列的大小关系保持不变. 分析: ...

随机推荐

  1. UIPikerView的属性---iOS-Apple苹果官方文档翻译

    本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址  //转载请注明出处--本文永久链接:http://www.cnblogs.com/C ...

  2. hadoop+spark 集群的安装

    1.安装连接 https://www.cnblogs.com/zengxiaoliang/p/6478859.html

  3. base--AuditResult

    //参考base-4.0.2.jar public class AuditResult implements TimeReferable, Serializable //参考api-1.0.0.jar ...

  4. 某p2p存在通用上传漏洞

    google链接查找: inurl:shouyi.asp inurl:itemlist_xq.asp?id= 很多存在Fckeditor上传链接: FCKeditor/editor/filemanag ...

  5. url编码模块

    use LWP::SImple; use URI::Escape; encoded_string = uri_escape(raw_string); get(encoded_string);

  6. python基础===self的理解

    self是类的实例 self有点类似java中的this,无实际意义.但是约定俗成的都是用self表示类的实例 class A: def func(self): print(self) #指向的是类的 ...

  7. 重写Alert

    var isIE = navigator.appName.indexOf("Internet Explorer") != -1;var oldAlert = window.aler ...

  8. ajax之深入解析(1)

    AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML).AJAX 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. AJ ...

  9. 基于UDP套接字编程实例

    data.h #ifndef DATA_H #define DATA_H #include <stdio.h> #include <string.h> #include < ...

  10. vue 数组和对象不能直接赋值情况和解决方法

    Vue 不能检测以下变动的数组: 当你利用索引直接设置一个项时,例如:vm.items[indexOfItem] = newValue 当你修改数组的长度时,例如:vm.items.length = ...