当前位置:网站首页>(prefix and / thinking) codeforces round 806 (Div. 4) F Yet Another Problem About Pairs Satisfying an Inequality
(prefix and / thinking) codeforces round 806 (Div. 4) F Yet Another Problem About Pairs Satisfying an Inequality
2022-07-27 02:19:00 【ZaneBobo】

One . The question
Give you an array , You are required to find out the satisfaction in the array ai<i<aj<j Number to number .
Two . Ideas
First limit Every number in the number pair must satisfy ai<i, Then you only need to establish one i<aj The relationship between .
We use the idea of prefixes and sum[i] representative i Before that includes i All satisfied ai<i The number of , that sum[a[j]-1] Is all satisfaction i<a[j] Of and satisfied with ai<i The number of . Then add a qualification when enumerating a[j]<j Just do it .
3、 ... and . Code
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N = 2e5+10;
int a[N];
map<int,int> sum;
typedef long long LL;
void solve()
{
int n;
cin>>n;
sum.clear();
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum[i]+=sum[i-1]+(a[i]<i);// limit a[i]<i
}
LL res=0;
for(int i=1;i<=n;i++)
{
if(i>a[i])res+=sum[a[i]-1];
//if Condition limit a[j]<j sum[a[i]-1] Is limited i<a[j] So all qualified logarithms
}
cout<<res<<endl;
}
int main()
{
int T;
cin>>T;
while(T--)
{
solve();
}
}边栏推荐
- MySQL课程2.表的各种查询
- First knowledge of C language (2)
- Experiment exercise of two-layer packaging technology (HDLC, ppp--pap\chap, GRE)
- Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)
- 静态综合实验(静态路由、环回接口、缺省路由、空接口、浮动静态的综合练习)
- (史上最详细)Codeforces Round #805 (Div. 3)E. Split Into Two Sets
- 定时器中断实验
- Is index reproduction text generation image is score quantitative experiment whole process reproduction inception score quantitative evaluation experiment step on the pit and avoid the pit process
- [explain C language in detail] takes you to play with loop structure (for_while_do while)
- RISC-V工具链编译笔记
猜你喜欢

OSPF在MGRE环境下的实验

OSPF在MGRE环境下配置及LSA的优化---减少LSA更新量(汇总、特殊区域)

OSPF协议知识汇总

2022 latest live broadcast monitoring 24-hour monitoring (III) analysis of barrage in live broadcast room

STM32入门教程第二讲

Static comprehensive experiment (comprehensive exercise of static route, loopback interface, default route, empty interface, floating static)

C语言实现小游戏【三子棋】注释详细 逻辑清晰 快来看看吧!!

HCIA(网络初级综合实验练习)

ESP8266Wi-Fi数据通讯

Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)
随机推荐
TCP的三次握手与四次断开
定时器中断实验
Tcp的三次握手与四次挥手
NB-IOT联网通信
关于编程的自我介绍和规划
Lesson 5 - key control LED
Solution: various error reporting and pit stepping and pit avoiding records encountered in the alchemist cultivation plan pytoch+deeplearning (III)
Influence of pre frequency division value and automatic reload value on interrupt frequency
初识C语言(1)
Ogeek meetup phase I, together with cubefs, is hot
Text to image intensive reading df-gan:a simple and effective baseline for text to image synthesis
Golang bufio Reader 源码详解
HCIA基础知识(1)
7.8 Ruijie online written examination
First knowledge of Web Design
Golang - sync包的使用 (WaitGroup, Once, Mutex, RWMutex, Cond, Pool, Map)
Educational Codeforces Round 132 (Rated for Div. 2), problem: (D) Rorororobot
初识C语言(2)
CF 1333C Eugene and an array
[explain C language in detail] this article takes you to know C language and makes you impressed