当前位置:网站首页>Codeforces 771-div2 C (trouble, permutation is not very good)
Codeforces 771-div2 C (trouble, permutation is not very good)
2022-07-02 12:01:00 【Find a derivative first】
subject
The question : Given a length of n Of permutation, It is stipulated that for the two tuples with reverse order relationship (i,j), One side . How many connected blocks are there in the graph .(n<=2e5)
Ideas : Used a tree array + Union checking set , also T 了 , Delete the tree array and search the set .
The solution only maintains a maximum , Finish my practice . Let's think about how to form a connected block , There will be no future in this position < Number of maximum values , As a connecting block, I can't claim an edge from the next connecting block , It's one of its own .
say concretely , For the first i A place , If the maximum value of maintenance is just ==i, There is no way to extend the border , Number of connected blocks ++.
Time complexity : O(n)
Code :
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<complex>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<list>
#include<set>
#include<queue>
#include<stack>
#define OldTomato ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define fir(i,a,b) for(int i=a;i<=b;++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define p_ priority_queue
// round() rounding ceil() Rounding up floor() Rounding down
// lower_bound(a.begin(),a.end(),tmp,greater<ll>()) First less than or equal to
// #define int long long //QAQ
using namespace std;
typedef complex<double> CP;
typedef pair<int,int> PII;
typedef long long ll;
// typedef __int128 it;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll inf = 1e18;
const int N = 2e5+10;
const int M = 1e6+10;
const int mod = 1e9+7;
const double eps = 1e-6;
inline int lowbit(int x){
return x&(-x);}
template<typename T>void write(T x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
{
write(x/10);
}
putchar(x%10+'0');
}
template<typename T> void read(T &x)
{
x = 0;char ch = getchar();ll f = 1;
while(!isdigit(ch)){
if(ch == '-')f*=-1;ch=getchar();}
while(isdigit(ch)){
x = x*10+ch-48;ch=getchar();}x*=f;
}
int n,m,k,T;
void solve()
{
read(n);
int ans = 0;
int mx = 0;
for(int x,i=1;i<=n;++i)
{
read(x);
mx = max(mx,x);
ans += mx==i;
}
write(ans); puts("");
}
signed main(void)
{
// T = 1;
// OldTomato; cin>>T;
read(T);
while(T--)
{
solve();
}
return 0;
}
边栏推荐
- Depth filter of SvO2 series
- 多文件程序X32dbg动态调试
- B high and beautiful code snippet sharing image generation
- BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
- How to Add P-Values onto Horizontal GGPLOTS
- Fabric.js 3个api设置画布宽高
- Power Spectral Density Estimates Using FFT---MATLAB
- GGPlot Examples Best Reference
- The position of the first underline selected by the vant tabs component is abnormal
- (C语言)八进制转换十进制
猜你喜欢

Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)

Deep understanding of NN in pytorch Embedding

Cluster Analysis in R Simplified and Enhanced

深入理解PyTorch中的nn.Embedding

Data analysis - Matplotlib sample code

How to Add P-Values onto Horizontal GGPLOTS

Flesh-dect (media 2021) -- a viewpoint of material decomposition

机械臂速成小指南(七):机械臂位姿的描述方法

How to Visualize Missing Data in R using a Heatmap

2022年遭“挤爆”的三款透明LED显示屏
随机推荐
ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
How to Easily Create Barplots with Error Bars in R
Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)
Some problems encountered in introducing lvgl into esp32 Arduino
ESP32 Arduino 引入LVGL 碰到的一些问题
Filtre de profondeur de la série svo2
Depth filter of SvO2 series
多文件程序X32dbg动态调试
Visualization of chip SEQ data by deeptools
Natural language processing series (II) -- building character level language model using RNN
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
B high and beautiful code snippet sharing image generation
Analyse de l'industrie
输入一个三位的数字,输出它的个位数,十位数、百位数。
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
vant tabs组件选中第一个下划线位置异常
行業的分析
自然语言处理系列(三)——LSTM
Uniapp uni list item @click, uniapp uni list item jump with parameters