# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981154 | math_rabbit_1028 | Sequence (APIO23_sequence) | C++17 | 168 ms | 33700 KiB |
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 n, m, ans = 0;
vector<int> arr;
vector<int> pos[505050];
int sequence(int N, vector<int> A) {
n = N;
arr = A;
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
m = A.size();
for (int i = 0; i < n; i++) {
arr[i] = lower_bound(A.begin(), A.end(), arr[i]) - A.begin();
}
for (int i = 0; i < n; i++) {
pos[arr[i]].push_back(i);
}
for (int i = 0; i < m; i++) {
int mn = pos[i].front(), mx = pos[i].back();
if (mx - mn + 1 == pos[i].size()) {
ans = max(ans, mx - mn + 1);
continue;
}
int ed, st; //[mn, ed] + [st, mx]
for (int j = 1; ; j++) {
assert(pos[i].size() > j);
if (pos[i][j] > pos[i][j-1] + 1) {
ed = pos[i][j-1];
st = pos[i][j];
break;
}
}
ans = max(ans, ed - mn + 1);
ans = max(ans, mx - st + 1);
if (mx - mn + 1 <= n/2 + 1) ans = max(ans, ed - mn + 1 + mx - st + 1);
}
return ans;
}
Compilation message (stderr)
# | 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... |