提交时间:2025-03-02 15:03:33

运行 ID: 37066

#include<bits/stdc++.h> #define int long long using namespace std; void read(int &x){x=0;char c=getchar();bool neg=0;while(!isdigit(c)){if(c=='-')neg=1;c=getchar();}while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();if(neg)x=-x;} #define read2(a,b) read(a),read(b) #define read3(a,b,c) read(a),read(b),read(c) #define read4(a,b,c,d) read(a),read(b),read(c),read(d) #define read5(a,b,c,d,e) read(a),read(b),read(c),read(d),read(e) #define read6(a,b,c,d,e,f) read(a),read(b),read(c),read(d),read(e),read(f) int id,n,m,a[200005],top; vector<int>e[200005]; void bfs(){ queue<int>q; q.push(1); top=2; while(!q.empty()){ int u=q.front();q.pop(); e[u].push_back(a[top]); if(top<=n) top++; while(a[top]>a[top-1]&&top<=n)e[u].push_back(a[top]),q.push(a[top++]); } } int dp[200005]; void dfs(int p,int f){ for(int x:e[p]){ if(x==f)continue; dp[x]=dp[p]+1; dfs(x,p); } } void slv(){ read3(id,n,m); for(int i=1;i<=n;i++)read(a[i]); bfs(); dfs(1,0); int ans=0; for(int i=1;i<=n;i++)ans=max(ans,dp[i]); cout<<ans<<endl; } signed main(){ // int T;read(T);while(T--) slv(); return 0; } //