当前位置:网站首页>Cdeforces 1638 C. inversion graph - simple thinking
Cdeforces 1638 C. inversion graph - simple thinking
2022-06-12 13:33:00 【Tianyi City*】
The question :
Give you a length of n Permutation ,i and j They can be connected if and only if i>j && p[i]<p[j]. How many connecting blocks are there .
Answer key :
At first glance, it is called join search , But it doesn't need to , It's more stupid to write and search the collection .
Fully understand any topic , Make good use of the conditions , Since this problem is arranged , That is to say if i Not in front i A place , Then it must be able to connect with the front .
So where is it connected ?
set up mx Before mx Location p The maximum of , If mx Not before , Then there will be no new connected block . Otherwise, a connected block will be added , Like 2 3 1 5 4.
In the first position ,mx=2, Then it means that this connected block can at least be connected to 2 Location , here we are 2 When mx by 3, That is to say, this connected block can at least be connected to 3.
here we are 4 When ,mx=3, In other words, you need to add a new connection block . Next mx=5 Can be connected to at least 5.
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
int mx=0,ans=0;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(mx>=i){
mx=max(mx,a[i]);
continue;
}
mx=a[i];
ans++;
}
printf("%d\n",ans);
}
return 0;
}
边栏推荐
- Script import CDN link prompt net:: err_ FILE_ NOT_ Found problem
- 【刷题篇】抽牌获胜的概率
- 简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链
- Encryptor and client authenticate with each other
- Install RPM package offline using yum
- C language array and pointer
- Software construction 03 regular expression
- 创新实训(十)高级界面美化
- Web3.0,「激发创造」的时代
- LeetCode滑动窗口刷题总结
猜你喜欢

成功定级腾讯T3-2,万字解析

【刷题篇】抽牌获胜的概率

go-zero 微服务实战系列(二、服务拆分)

关于#SQLite写注册功能时,数据表查询出错#的问题,如何解决?

Application of binary search -- finding the square root sqrt of a number
![[WUSTCTF2020]颜值成绩查询-1](/img/dc/47626011333a0e853be87e492d8528.png)
[WUSTCTF2020]颜值成绩查询-1

Experience and learning path of introductory deep learning and machine learning

leetcode 47. Permutations II 全排列 II(中等)

torch_geometric message passing network

VGA display color bar and picture (FPGA)
随机推荐
简历 NFT 平台 TrustRecruit 加入章鱼网络成为候选应用链
1002: output the second integer
颜色编码格式介绍
TCP的“非”可靠性
安装MySQL时出错,照着下面这个链接,做到cmd就不行了
Chaotic engineering practice of distributed kV storage in station B
苹果电脑上MySQL安装完成找不到怎么办
一种快速创建测试窗口的方法
软件构造 03 正则表达式
创新实训(十二)项目总结
【云原生 | Kubernetes篇】Ingress案例实战
Scyther工具形式化分析Woo-Lam协议
成功跳槽阿里,进阶学习
Automatic Generation of Visual-Textual Presentation Layout
Summary of question brushing in leetcode sliding window
Codeforces 1629 A. download more RAM - simple greed
2062: [example 1.3] movie tickets
1414: [17noip popularization group] score
NVIDIA Jetson Nano Developer Kit 入门
达梦数据库DM8 windows环境安装