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;
int sequence(int n, vector<int> a) {
vector<vector<int>> pos(n+1);
for(int i=0; i<n; i++) pos[a[i]].push_back(i);
int ans=0;
for(int i=1; i<=n; i++) {
for(int p : pos[i]) {
int temp=0, els=0, add=0;
set<int> s; s.insert(0);
for(int l=p-1; l>=0; l--) {
if(a[l]==i) break;
else if(a[l]<i) add--;
else add++;
s.insert(add);
}
for(int r=p; r<n; r++) {
if(a[r]==i) {
temp++;
if(abs(els)<=temp) ans=max(ans, temp);
else {
auto it=s.lower_bound(-temp-els);
if(it!=s.end() && abs(els+*it)<=temp) ans=max(ans, temp);
}
} else if(a[r]<i) els--;
else els++;
}
}
}
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... |