统计满足某些性质的区间个数。

我们考虑移动 \(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的更多相关文章

  1. 题解-CF1418G Three Occurrences

    题面 CF1418G Three Occurrences 给一个 \(n\) 个数的序列 \(a_i\),求每个出现过的数出现次数为 \(3\) 的子序列个数. 数据范围:\(1\le n\le 5\ ...

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

  3. eclipse使用tips-Toggle Mark Occurrences 颜色更改

    Toggle Mark Occurrences这个功能非常好用,能把选中的方法/变量在本类中全部出现的地方高亮显示,是一个非常实用的功能.但是默认颜色是灰色,非常毁眼.可以通过下面的设置更改为自己喜欢 ...

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

  5. WordLight: highlights all occurrences of a selected text for VS2008

    https://visualstudiogallery.msdn.microsoft.com/ad686131-47d4-4c13-ada2-5b1a9019fb6f About This is a ...

  6. org.apache.jasper.JasperException: - Page directive must not have multiple occurrences of pageencoding

    最近写jsp遇到一系列的低级错误,记录下来权当前车之鉴吧. 错误提示: SEVERE: Servlet.service() for servlet jsp threw exceptionorg.apa ...

  7. 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.错误,查了半 ...

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

  9. Segment Occurrences(string find函数)

    Description You are given two strings s and t, both consisting only of lowercase Latin letters.The s ...

随机推荐

  1. 掌握BeanShell,轻松处理jmeter中的数据

    作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15424558.html 博客主页:https://www.cnblogs.com/testero ...

  2. Visual Studio CMake 项目和 WSL

    Visual Studio CMake 项目和 WSL https://devblogs.microsoft.com/cppblog/c-with-visual-studio-2019-and-win ...

  3. Sequence Model-week2编程题2-Emoji表情生成器

    1. Emoji表情生成器 下面,我们要使用词向量(word vector)来构建一个表情生成器. 你将实现一个模型:输入一句话 (如 "Let's go see the baseball ...

  4. .net 5.0 ref文件夹的作用

    ref目录里的dll是一个名为参考组件的东西,微软MSDN给的解释是 参考组件是一种特殊类型的程序集,仅包含表示库的公共API面所需的最小元数据数量.它们包括用于在构建工具中引用程序集时重要的所有成员 ...

  5. SpringCloud+RocketMQ实现分布式事务

    随着互联网公司的微服务越来越多,分布式事务已经成为了我们的经常使用的.所以我们来一步一步的实现基于RocketMQ的分布式事务.接下来,我们将要做的主题写出来. RocketMQ的分布式事务结构和说明 ...

  6. 【Azure Redis 缓存】Windows版创建 Redis Cluster 实验 (精简版)

    简介 学习Redis Cluster的第一步,即本地搭建Redis Cluster.但是在Redis的官方文档中,是介绍在Linux系统中搭建Redis Cluster.本文主要介绍在Windows系 ...

  7. Photoshop cc 绿色版 最新版 下载

    Photoshop cc 绿色版 下载 Photoshop cc 绿色版 最新版下载百度网盘下载 Photoshop 下载提取码: dh6z 作为一个程序员, 不懂点基本的作图都不配"新时代 ...

  8. 加法运算替代 牛客网 程序员面试金典 C++ Python

    加法运算替代 牛客网 程序员面试金典 题目描述 请编写一个方法,实现整数的乘法.减法和除法运算(这里的除指整除).只允许使用加号. 给定两个正整数int a,int b,同时给定一个int type代 ...

  9. POJ 2446 Chessboard(二分图最大匹配)

    题意: M*N的棋盘,规定其中有K个格子不能放任何东西.(即不能被覆盖) 每一张牌的形状都是1*2,问这个棋盘能否被牌完全覆盖(K个格子除外) 思路: M.N很小,把每一个可以覆盖的格子都离散成一个个 ...

  10. DeWeb第1个通用化模块:登录模块,仅需要修改一个配置文件即可实现登录功能

    演示: https://delphibbs.com/login.dw 开发环境和源代码 https://gitee.com/xamh/dewebsdk 效果图: 配置方法: 在Runtime目录中放一 ...