#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
stack<pair<ll,ll>> st;
int main(){
	ll n;
	scanf("%lld",&n);
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        ll cnt=1;
        if(!st.empty()&&st.top().first==x) cnt=st.top().second+1;
        st.push(make_pair(x,cnt));
        if(cnt==x) for(ll j=0;j<x;j++) st.pop();
        cout<<st.size()<<'\n';
    }
    return 0;
}

4 条评论

  • @ 2026-10-28 11:37:57

    你的讨论简介就不能让我们复制吗

    • @ 2026-10-27 19:32:29
      #include <bits/stdc++.h> 
      using namespace std; 
      typedef long long ll; 
      stack<pair<ll,ll>> st; 
      int main(){ 
          ll n; 
          scanf("%lld",&n); 
          for(ll i=1;i<=n;i++){ 
              ll x; 
              cin>>x; 
              ll cnt=1;
              if(!st.empty()&&st.top().first==x) cnt=st.top().second+1; 
              st.push(make_pair(x,cnt)); 
              if(cnt==x) for(ll j=0;j<x;j++) st.pop(); 
              cout<<st.size()<<'\n'; 
          } 
          return 0; 
      }
      
      • @ 2026-10-27 7:40:46

        .....

        • @ 2026-10-26 17:09:46

          dcx的代码

        • 1