当前位置:网站首页>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;
}
边栏推荐
- Innovation training (XII) project summary
- C language structure
- Title: Yanghui triangle
- 1001:Hello,World
- Cocoapods的相关知识点
- 【刷题篇】抽牌获胜的概率
- import torch_ Geometric loads some common datasets
- Install MySQL database independently on Debian 10
- Time processing in C language (conversion between string and timestamp)
- JVM runtime parameters
猜你喜欢
![[WUSTCTF2020]颜值成绩查询-1](/img/dc/47626011333a0e853be87e492d8528.png)
[WUSTCTF2020]颜值成绩查询-1

Resume NFT platform trustrecruit joined Octopus network as a candidate application chain

The goods are full. You must take this knowledge

Summary of question brushing in leetcode sliding window

import torch_geometric 的Data 查看

IC chip scheme fs4062b for lithium battery charging with 5V boost to 12.6V

403 you don't have permission to access this resource

5V升压到12.6V的锂电池充电IC芯片方案FS4062B

Application of list and Dict

多源BFS问题 模板(附题)
随机推荐
JVM 运行时参数
1004: character triangle
JVM runtime parameters
当字节跳动在美国输出中国式 996
颜色编码格式介绍
Resume NFT platform trustrecruit joined Octopus network as a candidate application chain
Deploy opengauss database based on Huawei cloud Kunpeng elastic ECS [Gauss is not a mathematician this time]
2061: [example 1.2] trapezoidal area
import torch_geometric 的Data 查看
import torch_ Data view of geometric
Octopus network progress monthly report | may 1-May 31, 2022
How to balance multiple losses in deep learning?
字节序数据读写
多源BFS问题 模板(附题)
1003: align output
2064: [example 2.1] exchange value
数据类型转换和条件控制语句
Time processing in C language (conversion between string and timestamp)
Hudi key generation
创新实训(十一)开发过程中的一些bug汇总