当前位置:网站首页>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;
}
边栏推荐
- [untitled] how to mount a hard disk in armbian
- BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
- Seriation in R: How to Optimally Order Objects in a Data Matrice
- PHP query distance according to longitude and latitude
- Cmake cross compilation
- b格高且好看的代码片段分享图片生成
- HR wonderful dividing line
- Deep understanding of NN in pytorch Embedding
- How to Add P-Values onto Horizontal GGPLOTS
- 基于Arduino和ESP8266的连接手机热点实验(成功)
猜你喜欢

HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R

Some problems encountered in introducing lvgl into esp32 Arduino

YYGH-BUG-04

How to Visualize Missing Data in R using a Heatmap

HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R

SVO2系列之深度濾波DepthFilter

R HISTOGRAM EXAMPLE QUICK REFERENCE

自然语言处理系列(三)——LSTM

HR wonderful dividing line

The position of the first underline selected by the vant tabs component is abnormal
随机推荐
Seriation in R: How to Optimally Order Objects in a Data Matrice
时间格式化显示
[geek challenge 2019] upload
Some problems encountered in introducing lvgl into esp32 Arduino
b格高且好看的代码片段分享图片生成
Implementation of address book (file version)
Filtre de profondeur de la série svo2
[multithreading] the main thread waits for the sub thread to finish executing, and records the way to execute and obtain the execution result (with annotated code and no pit)
【2022 ACTF-wp】
进入前六!博云在中国云管理软件市场销量排行持续上升
深入理解PyTorch中的nn.Embedding
CMake交叉编译
How to Visualize Missing Data in R using a Heatmap
to_ Bytes and from_ Bytes simple example
From scratch, develop a web office suite (3): mouse events
机械臂速成小指南(七):机械臂位姿的描述方法
How to Add P-Values onto Horizontal GGPLOTS
自然语言处理系列(二)——使用RNN搭建字符级语言模型
Applet link generation
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE