当前位置:网站首页>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;
}
边栏推荐
- Take you ten days to easily finish the finale of go micro services (distributed transactions)
- ESP32音频框架 ESP-ADF 添加按键外设流程代码跟踪
- Cluster Analysis in R Simplified and Enhanced
- easyExcel和lombok注解以及swagger常用注解
- 电脑无缘无故黑屏,无法调节亮度。
- 进入前六!博云在中国云管理软件市场销量排行持续上升
- Yygh-10-wechat payment
- 【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
- 行业的分析
- PX4 Position_Control RC_Remoter引入
猜你喜欢
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
PyTorch搭建LSTM实现服装分类(FashionMNIST)
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
[QT] Qt development environment installation (QT version 5.14.2 | QT download | QT installation)
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
The position of the first underline selected by the vant tabs component is abnormal
基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)
How to Easily Create Barplots with Error Bars in R
Dynamic memory (advanced 4)
随机推荐
史上最易懂的f-string教程,收藏這一篇就够了
深入理解PyTorch中的nn.Embedding
C # method of obtaining a unique identification number (ID) based on the current time
Take you ten days to easily finish the finale of go micro services (distributed transactions)
时间格式化显示
How to Easily Create Barplots with Error Bars in R
HR wonderful dividing line
Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
HOW TO ADD P-VALUES TO GGPLOT FACETS
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
YYGH-BUG-04
How to Create a Beautiful Plots in R with Summary Statistics Labels
Some problems encountered in introducing lvgl into esp32 Arduino
Analyse de l'industrie
MySQL stored procedure cursor traversal result set
行业的分析
How to Create a Nice Box and Whisker Plot in R
qt 仪表自定义控件
H5,为页面添加遮罩层,实现类似于点击右上角在浏览器中打开
How to Add P-Values onto Horizontal GGPLOTS