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;
using pii = pair<int, int>;
const int MAX_N = 5e5 + 5;
int n;
int a[MAX_N];
vector<pii> ranges[MAX_N];
void precomp() {
int i = 1;
while (i != n + 1) {
int j = i;
while (j < n && a[j + 1] == a[i]) j++;
ranges[a[i]].push_back({i, j});
i = j + 1;
}
}
int sequence(int tmp_n, vector<int> tmp_a) {
n = tmp_n;
for (int i = 0; i < n; i++) a[i + 1] = tmp_a[i];
precomp();
int ans = 0;
for (int i = 1; i <= n; i++) {
if (ranges[i].empty()) continue;
for (pii x : ranges[i]) ans = max(ans, x.second - x.first + 1);
if (ranges[i].size() == 1) continue;
assert(ranges[i].size() == 2);
int range_size = 0;
for (pii x : ranges[i]) range_size += x.second - x.first + 1;
int in_size = ranges[i][1].first - ranges[i][0].second + 1;
int out_size = ranges[i][0].first - 1 + n - ranges[i][1].second;
if (out_size >= in_size - range_size) ans = max(ans, range_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... |