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>
using namespace std;
const int maxn = 5e5 + 10;
int occ[maxn];
int sequence(int N, vector<int> A)
{
multiset < int > lf, rf;
int ans = 1;
for (int i = 0; i < N; i ++)
{
for (int j = 0; j <= N; j ++)
occ[j] = 0;
lf.clear();
rf.clear();
lf.insert(A[i]);
occ[A[i]] ++;
for (int j = i + 1; j < N; j ++)
{
occ[A[j]] ++;
if (A[j] > *lf.rbegin())
rf.insert(A[j]);
else
lf.insert(A[j]);
while(lf.size() > rf.size() + 1)
{
int x = *lf.rbegin();
lf.erase(lf.find(x));
rf.insert(x);
}
while(rf.size() > lf.size())
{
int x = *rf.begin();
rf.erase(rf.find(x));
lf.insert(x);
}
if ((j - i + 1) % 2 == 0)
{
ans = max(ans, occ[*lf.rbegin()]);
ans = max(ans, occ[*rf.begin()]);
}
else
{
ans = max(ans, occ[*lf.rbegin()]);
}
}
}
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... |