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>
#include "sequence.h"
using namespace std;
int sequence(int n, vector<int> a){
int ans = 0;
if(n <= 2000){
int occ[n + 1];
for(int i = 0; i < n; i++){
memset(occ, 0, sizeof(occ));
multiset<int> l, r;
for(int j = i; j < n; j++){
occ[a[j]]++;
if(r.empty() || a[j] <= *r.begin()) l.insert(a[j]);
else r.insert(a[j]);
if(l.size() > r.size() + 1){
r.insert(*--l.end());
l.erase(--l.end());
}
if(r.size() > l.size()){
l.insert(*r.begin());
r.erase(r.begin());
}
ans = max(ans, occ[*--l.end()]);
if(l.size() == r.size()) ans = max(ans, occ[*r.begin()]);
}
}
return ans;
}
map<int, int> asc, desc;
bool flag = true;
for(int i = 0; i < n; i++){
if(flag) asc[a[i]]++;
else desc[a[i]]++;
if(i && a[i] <= a[i - 1]) flag = false;
}
for(auto p : asc){
auto p2 = lower_bound(a.begin(), a.end(), p.first) - a.begin();
if(p2 >= n / 2) ans = max(ans, p.second + desc[p.first]);
}
for(auto p : desc){
auto p2 = upper_bound(a.begin(), a.end(), p.first) - a.begin();
if(p2 >= n / 2) ans = max(ans, p.second + desc[p.first]);
}
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... |