This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
int par[N], n;
bool mark[N];
ii a[N];
int anc(int u)
{
return par[u] == u ? u : par[u] = anc(par[u]);
}
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i].F, a[i].S = i, par[i] = i;
sort(a + 1, a + 1 + n, greater<ii>());
int cnt = 0, res = 0;
for(int i = 1; i <= n; i++)
{
cnt++;
int pos = a[i].S;
mark[pos] = 1;
if(mark[pos - 1])
{
cnt--;
par[pos] = anc(pos - 1);
}
if(mark[pos + 1])
{
cnt--;
par[pos] = anc(pos + 1);
}
if(i < n && a[i].F != a[i + 1].F)
res = max(res, cnt);
}
cout << res;
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while(t--) solve();
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... |