CF1418G Three Occurrences
统计满足某些性质的区间个数。
我们考虑移动 \(r\) 指针。
然后考虑把不能选的区间 \(ban\)掉。
具体看下细节吧。
#include<iostream>
#include<cstdio>
#define ll long long
#define N 500005
int n,c[N],u[N],pre[N];
struct P{
int tag,sum;
}T[N << 2];
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define t(x) T[x].tag
#define s(x) T[x].sum
#define mid ((l + r) >> 1)
inline void build(int u,int l,int r){
t(u) = 0;
s(u) = r - l + 1;
if(l == r)
return ;
build(ls(u),l,mid);
build(rs(u),mid + 1,r);
}
ll ans;
#define root 1,1,n
ll L;
inline void up(int x,int l,int r){if(t(u))s(u) = 0;else if(l == r) s(u) = 1;else s(u) = s(ls(u)) + s(rs(u));}
inline void change(int u,int l,int r,int tl,int tr,int p){
if(L >= l && R <= r)t(u) += p,up(x,l,r);
else{
if(mid >= tl)
change(ls(u),l,mid,tl,tr,p);
if(mid < tr)
change(rs(u),mid + 1,r,tl,tr,p);
}
up(x,l,r);
}
inline ll find(int u,int l,int r,int tl,int tr){
if(t(u))return 0;
if(tl <= l && r <= tr)
return s(u);
ll ans = 0;
if(tl <= mid)
ans = ans + find(ls(u),l,mid,tl,tr);
if(tr > mid)
ans = ans + find(rs(u),mid + 1,r,tl,tr);
return ans;
}
int main(){
scanf("%d",&n);
for(int i = 1;i <= n;++i)
scanf("%d",&u[i]),pre[i] = c[u[i]],c[u[i]] = i;
for(int i = 1;i <= n;++i){
if(!pre[i])change(root,1,i,1);
if(!pre[pre[i]])change(root,1,pre[i],-1),change(root,1,i,1);
if(!pre[pre[pre[i]]])change(root,1,pre[i],-1),change(root,pre[pre[i]] + 1,i,1);
else{
change(root,pre[pre[pre[i]]] + 1,pre[i],-1);
change(1,pre[pre[i]] + 1,i,1);
}
L = std::max(L,pre[pre[pre[i]]] + 1);
ans += find(root,L,i);
}
std::cout<<ans<<std::endl;
}
CF1418G Three Occurrences的更多相关文章
- 题解-CF1418G Three Occurrences
题面 CF1418G Three Occurrences 给一个 \(n\) 个数的序列 \(a_i\),求每个出现过的数出现次数为 \(3\) 的子序列个数. 数据范围:\(1\le n\le 5\ ...
- [Java Web]Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors
手机客户端向服务器提交Http请求时,Tomcat抛出错误: 十二月 31, 2014 2:32:45 下午 org.apache.coyote.http11.AbstractHttp11Proces ...
- eclipse使用tips-Toggle Mark Occurrences 颜色更改
Toggle Mark Occurrences这个功能非常好用,能把选中的方法/变量在本类中全部出现的地方高亮显示,是一个非常实用的功能.但是默认颜色是灰色,非常毁眼.可以通过下面的设置更改为自己喜欢 ...
- [geeksforgeeks] Count the number of occurrences in a sorted array
Count the number of occurrences in a sorted array Given a sorted array arr[] and a number x, write a ...
- WordLight: highlights all occurrences of a selected text for VS2008
https://visualstudiogallery.msdn.microsoft.com/ad686131-47d4-4c13-ada2-5b1a9019fb6f About This is a ...
- org.apache.jasper.JasperException: - Page directive must not have multiple occurrences of pageencoding
最近写jsp遇到一系列的低级错误,记录下来权当前车之鉴吧. 错误提示: SEVERE: Servlet.service() for servlet jsp threw exceptionorg.apa ...
- further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误
今天进行项目测试的时候出现了further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误,查了半 ...
- jsp include 报错:illegal to have multiple occurrences of contentType with different values (old: text/html; charset=UTF-8, new: text/html; carset=UTF-8)
严重: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: /jsp.jsp(1, ...
- Segment Occurrences(string find函数)
Description You are given two strings s and t, both consisting only of lowercase Latin letters.The s ...
随机推荐
- change or reset WSL password
change or reset WSL password To change or reset your password, open the Linux distribution and enter ...
- ubuntu修改软件源的方法
最快方法--替换法 刚安装好的ubutun,打开source.list后,用vim替换的方法将所有的us提付出替换为 cn,然后保存退出,更新即可. # vim /etc/apt/source.lis ...
- 单机CentOS 安装 TiDB
目录 一.官网教程 二.安装步骤 1.下载并安装 TiUP: 2.声明一下环境变量,否则会找不到 tiup 命令 3.安装 TiUP 的 cluster 组件: 4.官方教程说,由于模拟多机部署,需要 ...
- 航胥:北航教务助手——Alpha阶段发布声明
本软件项目为北京航空航天大学2020年"软件工程"课程项目 v1.0.5版本下载地址:https://bhpan.buaa.edu.cn:443/#/link/D10B71B69E ...
- Manjaro / ArchLinux 安装网易云音乐解决搜索不能输入中文方法
0. 安装网易云音乐 yay -S netease-cloud-music 1.先安装qcef这个软件包. sudo yay -S qcef 2.编辑/opt/netease/netease-clou ...
- OO_JAVA_JML系列第三次作业__架构之谈
OO_JAVA_JML系列第三次作业 ## ----架构之谈 目录 OO_JAVA_JML系列第三次作业 出发点 操作的可分离性 操作本身的多样性 实现手段:表驱动编程 储存 注册 出发点 操作的可分 ...
- Noip模拟84 2021.10.27
以后估计都是用\(markdown\)来写了,可能风格会有变化 T1 宝藏 这两天老是会的题打不对,还是要细心... 考场上打的是维护\(set\)的做法,但是是最后才想出来的,没有维护对于是没有交. ...
- mbps和MB/s是怎么换算的
Mbps即"传输速率",也叫"带宽".去营业厅开网线的时候会问开几兆的宽带,这里说的"几兆的宽带"就是指多少Mbps,但是Mbps和MB/s ...
- Verdi Transaction Debug Mode 简单使用
转载:Verdi Transaction Debug Mode 简单使用_Holden_Liu的博客-CSDN博客 文档与源码: User Guide: Verdi_Transaction_and_P ...
- 第一个只出现一次字符的位置 牛客网 剑指Offer
第一个只出现一次字符的位置 牛客网 剑指Offer 题目描述 在一个字符串(0<=字符串长度<=10000,全部由字母组成)中找到第一个只出现一次的字符,并返回它的位置, 如果没有则返回 ...