当前位置:网站首页>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;
}
边栏推荐
- PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
- Time format display
- MSI announced that its motherboard products will cancel all paper accessories
- Orb-slam2 data sharing and transmission between different threads
- MySql存储过程游标遍历结果集
- Cluster Analysis in R Simplified and Enhanced
- Bedtools tutorial
- CMake交叉编译
- HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R
- How does Premiere (PR) import the preset mogrt template?
猜你喜欢

Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator

Research on and off the Oracle chain

6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用

vant tabs组件选中第一个下划线位置异常

【2022 ACTF-wp】

Seriation in R: How to Optimally Order Objects in a Data Matrice

HOW TO CREATE A BEAUTIFUL INTERACTIVE HEATMAP IN R

xss-labs-master靶场环境搭建与1-6关解题思路

6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application

ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)
随机推荐
Cmake cross compilation
HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
MySql存储过程游标遍历结果集
YYGH-BUG-05
MSI announced that its motherboard products will cancel all paper accessories
ESP32 Arduino 引入LVGL 碰到的一些问题
Take you ten days to easily finish the finale of go micro services (distributed transactions)
Seriation in R: How to Optimally Order Objects in a Data Matrice
Flesh-dect (media 2021) -- a viewpoint of material decomposition
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
This article takes you to understand the operation of vim
HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
Log4j2
PyTorch中repeat、tile与repeat_interleave的区别
基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)
Power Spectral Density Estimates Using FFT---MATLAB
Mish-撼动深度学习ReLU激活函数的新继任者
PHP query distance according to longitude and latitude
A sharp tool for exposing data inconsistencies -- a real-time verification system
PyTorch nn.RNN 参数全解析