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 "sequence.h"
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 5e5 + 5;
vector<int> pos[maxn];
int sequence(int N, vector<int> A) {
for(int i = 0;i < N;i++) pos[A[i]].pb(i);
int X = 0;
for(int i = 1;i < N;i++)
if(A[i] > A[X]) X = i;
int l = 0, ans = 0;
for(int i = 1;i <= N;i++) {
if(pos[i].size() == 0) continue;
int lo = pos[i][0], hi = pos[i].back();
if(hi < X || lo > X) ans = max(ans, (int)pos[i].size());
else {
int e = (int)pos[i].size();
int g = N - e - l;
if(l < g - e) {
int x = 0, y = 0;
for(int j : pos[i])
if(j < X) x++;
else y++;
ans = max(ans, max(x, y));
} else ans = max(ans, e);
}
l += (int)pos[i].size();
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |