Description:

有一天Polycarp决定重看他最喜爱的电视剧《Tufurama》。当他搜索“在线全高清免费观看Tufurama第3季第7集”却只得到第7季第3集的结果时,他很惊讶。这让Polycarp感到疑惑——如果有天他决定重看整个系列却无法找到正确的剧集观看,那该怎么办呢?Polycarp现在想统计一下他被迫用不同方案搜索同一剧集的次数。

电视连续剧有\(n\) 季(从\(1\) 到\(n\) 编号),第\(i\) 季有\(a_i\) 集(从\(1\) 到\(a_i\) 编号)。Polycarp认为如果有一对\(x\) 和\(y\) (\(x\<y\) ),使第\(x\) 季第\(y\) 集、第\(y\) 季第\(x\) 集存在,那么其中一个搜索就会包含错误的内容。请帮助Polycarp统计这样的数对的数量吧!

Hint:

主席树SB题,随便搞个前缀和,离散化都不用

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mxn=2e5+5;
int n,m,tot,cnt,hd[mxn]; inline int read() {
char c=getchar(); int x=0,f=1;
while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
while(c<='9'&&c>='0') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
return x*f;
}
inline void chkmax(int &x,int y) {if(x<y) x=y;}
inline void chkmin(int &x,int y) {if(x>y) x=y;} struct ed {
int to,nxt;
}t[mxn<<1]; inline void add(int u,int v) {
t[++cnt]=(ed) {v,hd[u]}; hd[u]=cnt;
} int a[mxn],rt[mxn<<6],ls[mxn<<6],rs[mxn<<6],sz[mxn<<6];
ll ans; void update(int las,int &p,int l,int r,int pos) {
if(!p) p=++tot; sz[p]=sz[las]+1;
if(l==r) return ; int mid=(l+r)>>1;
if(pos<=mid) update(ls[las],ls[p],l,mid,pos),rs[p]=rs[las];
else update(rs[las],rs[p],mid+1,r,pos),ls[p]=ls[las];
} int query(int p,int l,int r,int pos) {
if(l==r) return sz[p];
int mid=(l+r)>>1;
if(pos<=mid) return sz[rs[p]]+query(ls[p],l,mid,pos);
else return query(rs[p],mid+1,r,pos);
} int main()
{
n=read();
for(int i=1;i<=n;++i) {
a[i]=read();
update(rt[i-1],rt[i],1,n,a[i]);
ans+=query(rt[min(i-1,a[i])],1,n,i);
}
printf("%lld",ans);
return 0;
}

[CF961E] Tufurama的更多相关文章

  1. CF961E Tufurama【主席树】

    CF961E Tufurama 题意翻译 题目描述 有一天Polycarp决定重看他最喜爱的电视剧<Tufurama>.当他搜索“在线全高清免费观看Tufurama第3季第7集”却只得到第 ...

  2. CF961E Tufurama 树状数组

    E. Tufurama One day Polycarp decided to rewatch his absolute favourite episode of well-known TV seri ...

  3. 【树状数组】CF961E Tufurama

    挺巧妙的数据结构题(不过据说这是一种套路? E. Tufurama One day Polycarp decided to rewatch his absolute favourite episode ...

  4. CF961E Tufurama 主席树

    对原问题进行转化 考虑对每个$i$,询问在$j \in [i + 1, a[i]]$中满足$a[j] \geqslant i$的个数 这样子可以做到不重不漏 个数满足差分的性质,使用主席树来维护即可 ...

  5. Codeforces 961E - Tufurama

    961E - Tufurama 思路: 线段树或者分块 遍历 1 - n - 1,求 区间[i + 1, min(a[i], n)]大于等于 i 的个数,累加起来 线段树: #include<b ...

  6. Tufurama CodeForces - 961E

    Tufurama CodeForces - 961E 题意:有一部电视剧有n季,每一季有ai集.问有多少对i,j存在第i季第j集也同时存在第j季第i集. 思路:核心问题还是统计对于第i季,你要统计第i ...

  7. Codeforces 961 E Tufurama

    Discription One day Polycarp decided to rewatch his absolute favourite episode of well-known TV seri ...

  8. Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)

    Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...

  9. Tufurama CodeForces - 961E (cdq分治)

    题面 One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series " ...

随机推荐

  1. AI学习吧

    一:AI学习吧 项目描述 系统使用前后端分离的模式,前端使用vue框架,后端使用restframework实现. 项目需求 公司开发AI学习吧,由于公司需要一款线上学习平台,要开发具有线上视频学习.支 ...

  2. IDEA中tomcat的部署

    创建一个项目就要部署tomcat

  3. jdbc问题:Access denied for user ''@'localhost''是因为没输入账户和密码

    Access denied for user ''@'localhost' to database 'bjpowernode'

  4. [转] history.back()和history.go()的区别

    Javascript:history.go()和history.back()的用法和区别 go(-1): 返回上一页,原页面表单中的内容会丢失:history.go(-1):后退+刷新:history ...

  5. lojround3

    A.绯色 IOI(开端) 首先注意到是完全图,数据范围又很大,肯定要观察一些性质 我们化简一下式子 发现其实是要求simga(xixj)最大 那么结论就很好想了 最大的和次大的第三大的连一起...然后 ...

  6. python之requests urllib3 连接池

    0.目录 1.参考 2. pool_connections 默认值为10,一个站点主机host对应一个pool (4)分析 host A>>host B>>host A pag ...

  7. net core体系-API-1Ocelot-(3)简单项目实战

    首先,让我们简单了解下什么是API网关? API网关是一个服务器,是系统的唯一入口.从面向对象设计的角度看,它与外观模式类似.API网关封装了系统内部架构,为每个客户端提供一个定制的API.它可能还具 ...

  8. Python--os的常见方法

    1.os.getcwd()+'/filename'------>相当于在当前运行文件的目录下创建一个以filename命名的文件 2.os.path.realpath(__file__)---- ...

  9. 51Nod1675 序列变换 数论 莫比乌斯反演

    原文http://www.cnblogs.com/zhouzhendong/p/8665675.html 题目传送门 - 51Nod1675 题意 给定序列$a,b$,让你求满足$\gcd(x,y)= ...

  10. 020100——00002_OS库

    OS 库中文文档:https://yiyibooks.cn/xx/python_352/library/os.html OS 库英文文档:https://docs.python.org/3/libra ...