This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// dwuy: _,\,,,_\,__,\,,_
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK ""
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
struct DSU{
    int n;
    vector<int> e;
    vector<bool> active;
    DSU(int n=0){
        this->n = n;
        this->e.assign(n+5, -1);
        this->active.assign(n+5, 0);
    }
    int fp(int u){
        return e[u] < 0? u : e[u] = fp(e[u]);
    }
    bool unon(int u, int v){
        if(!active[u] || !active[v]) return 0;
        u = fp(u);
        v = fp(v);
        if(u == v) return 0;
        if(e[u] > e[v]) swap(u, v);
        e[u] += e[v];
        e[v] = u;
        return 1;
    }
};
const int MX = 1000005;
int n;
pii a[MX];
int gw(int N, int H[]){
    n = N;
    for(int i=1; i<=n; i++) a[i] = {H[i-1], i};
    sort(a+1, a+1+n, greater<pii>());
    DSU dsu(n);
    a[0].fi = -1;
    int ans = 0;
    int cur = 0;
    for(int i=1; i<=n; i++){
        if(a[i].fi != a[i-1].fi) ans = max(ans, cur);
        cur++;
        dsu.active[a[i].se] = 1;
        cur -= dsu.unon(a[i].se, a[i].se-1);
        cur -= dsu.unon(a[i].se, a[i].se+1);
    }
    return ans;
}
int32_t main(){
    fastIO;
    //file(TASK);
    int n;
    cin >> n;
    int h[n];
    for(int i=0; i<n; i++) cin >> h[i];
    cout << gw(n, h);
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |