当前位置:网站首页>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;
}
边栏推荐
- Deploy opengauss database based on Huawei cloud Kunpeng elastic ECS [Gauss is not a mathematician this time]
- Tinyxml Usage Summary
- torch_ geometric message passing network
- Does jupyternotebook have a Chinese character database. Can you recognize handwritten Chinese in deep learning
- go-zero 微服务实战系列(二、服务拆分)
- Redis消息队列重复消费问题
- C language structure
- 达梦数据库DM8 windows环境安装
- Application of short circuit expression (||) in C language
- Software construction 03 regular expression
猜你喜欢

leetcode 47. Permutations II full permutations II (medium)

高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法

Octopus network progress monthly report | may 1-May 31, 2022
颜色编码格式介绍

C#DBHelper_FactoryDB_GetConn

安装MySQL时出错,照着下面这个链接,做到cmd就不行了

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

How to solve the problem of data table query error when SQLite writes the registration function?
![[Title brushing] Super washing machine](/img/f9/0c69afafa8b32afc5df5e91d6af172.png)
[Title brushing] Super washing machine

torch_ About the geometric Mini batch
随机推荐
2065: [example 2.2] sum of integers
Summary of question brushing in leetcode sliding window
Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
【云原生 | Kubernetes篇】Kubernetes 网络策略(NetworkPolicy)
Experience and learning path of introductory deep learning and machine learning
Tinyxml Usage Summary
xcode 调试openGLES
D1 Nezha Development Board understands the basic startup and loading process
手把手教你IDEA创建SSM项目结构
C#DBHelper_ FactoryDB_ GetConn
当字节跳动在美国输出中国式 996
5V升压到12.6V的锂电池充电IC芯片方案FS4062B
Debug code to quickly locate the error location
多源BFS问题 模板(附题)
高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法
上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人
1004: character triangle
创新实训(十一)开发过程中的一些bug汇总
Successfully rated Tencent t3-2, 10000 word parsing
成功定级腾讯T3-2,万字解析