F - High Cry

题目大意:给你n个数,让你找区间里面所有数或 起来大于区间里面最大数的区间个数。

思路:反向思维,找出不符合的区间然后用总数减去。我们找出每个数掌控的最左端

和最右端,一个数的掌控区域为,这个区域里的或 为本身。

注意两个相同的数有可能掌控区域一样,记得将区域分段。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=*1e5+;
int n,a[N],l[N],r[N];
map<int,int> mp;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]),r[i]=n+;
for(int i=;i<=;i++)
{
int res=;
for(int j=;j<=n;j++)
{
if((a[j]>>i)&) res=j;
else l[j]=max(l[j],res);
}
}
for(int i=;i<=n;i++)
{
l[i]=max(l[i],mp[a[i]]);
mp[a[i]]=i;
}
for(int i=;i<=;i++)
{
int res=n+;
for(int j=n;j>=;j--)
{
if((a[j]>>i)&) res=j;
else r[j]=min(r[j],res);
}
}
ll ans=(ll) n*(n+)/;
for(int i=;i<=n;i++) ans-=(ll)(i-l[i])*(r[i]-i);
printf("%I64d\n",ans);
return ;
}

Codeforces Round #441(Div.2) F - High Cry的更多相关文章

  1. Codeforces Round #441 (Div. 2)

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

  2. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  3. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  4. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  5. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  6. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

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

  8. [日常] Codeforces Round #441 Div.2 实况

    上次打了一发 Round #440 Div.2 结果被垃圾交互器卡掉 $200$ Rating后心情复杂... 然后立了个 Round #441 要翻上蓝的flag QAQ 晚饭回来就开始搞事情, 大 ...

  9. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

随机推荐

  1. <video>标签:视频播放器动态设置src

    HTML代码 <div  id="my_div">    <video id="my_video"  width="600" ...

  2. sybench压测下模拟误truncate数据恢复

    基本环境:官方社区版MySQL 5.7.21 Row+Gtid开启sysbench压测,使用mysqldump备份数据库,执行truncate操作,恢复数据到truncate前的时间点1.切换日志,记 ...

  3. if语句与switch语句

    if语句可以替代switch语句,但是switch语句不能完全替代if语句.比如下面这种就是不对的 switch (len) { case (len <= 4): domLen = 4; bre ...

  4. undefined reference问题总结

    http://ticktick.blog.51cto.com/823160/431329 http://blog.sina.com.cn/s/blog_605f5b4f01018xeu.html ht ...

  5. Your Database is downloaded and backed up on....(腾讯云的mysql被攻击)

    今天发现自己的服务器被黑客攻击,自己的mysql服务器的库被删掉,并且新创了一个warning库,只有一个readme表.不知道原因,也许是自己再github上的项目暴漏了自己的密码,还要0.6比特币 ...

  6. js 鼠标拖拽元素

    基础知识 event.clientX.event.clientY 鼠标相对于浏览器窗口可视区域的X,Y坐标(窗口坐标),可视区域不包括工具栏和滚动条.IE事件和标准事件都定义了这2个属性 event. ...

  7. java中网络设置代理

    三种方式: 1.JVM启动时加参数设置代理 在系统启动时,使用-D项来设置代理. 例如: java -Dhttp.ProxyHost="proxyUrl" -Dhttp.Proxy ...

  8. caffe添加自己编写的Python层

    由于Python的灵活性,我们在caffe中添加自己定义的层时使用python层会更加方便,开发速速也会比C++更快,现在我就在这儿简单说一下如何在caffe中添加自定义的python层(使用的原网络 ...

  9. caffe中 softmax 函数的前向传播和反向传播

    1.前向传播: template <typename Dtype> void SoftmaxLayer<Dtype>::Forward_cpu(const vector< ...

  10. 在imagenet预训模型上进行finetune

    所谓fine tune就是用别人训练好的模型,加上我们自己的数据,来训练新的模型.fine tune相当于使用别人的模型的前几层,来提取浅层特征,然后在最后再落入我们自己的分类中. fine tune ...