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;
vector < int > occ[maxn];
int val[maxn], pref[maxn];
int sequence(int N, vector<int> A)
{
A.insert(A.begin(), 0);
for (int i = 1; i <= N; i ++)
occ[A[i]].push_back(i);
int ans = 0;
for (int x = 1; x <= N; x ++)
{
for (int i = 1; i <= N; i ++)
{
if (A[i] < x)
val[i] = -1;
else
if (A[i] == x)
val[i] = 0;
else
val[i] = 1;
pref[i] = pref[i - 1] + val[i];
}
for (int i = 0; i < occ[x].size(); i ++)
{
for (int j = i; j < occ[x].size(); j ++)
{
//cout << "-----------" << endl;
//cout << x << " " << i << " " << j << " " << ans << endl;
///cout << pref[r] << endl;
int l = occ[x][i], r = occ[x][j];
int min_lf = 1e9, max_lf = -1e9;
int min_rf = 1e9, max_rf = -1e9;
int d = 0;
for (int p = l - 1; p >= 0; p --)
{
if (A[p] == i)
d ++;
min_lf = min(min_lf, pref[p] - d);
max_lf = max(max_lf, pref[p] + d);
}
d = 0;
for (int p = r; p <= N; p ++)
{
if (A[p] == i && p != r)
d ++;
min_rf = min(min_rf, pref[p] - d);
max_rf = max(max_rf, pref[p] + d);
}
max_rf += (j - i + 1);
min_rf -= (j - i + 1);
//cout << min_lf << " " << max_lf << " " << min_rf << " " << max_rf << endl;
if (max(min_rf, min_lf) <= min(max_rf, max_lf))
{
///cout << x << " " << i << " " << j << endl;
ans = max(ans, j - i + 1);
}
}
}
}
return ans;
}
Compilation message (stderr)
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < occ[x].size(); i ++)
| ~~^~~~~~~~~~~~~~~
sequence.cpp:33:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int j = i; j < occ[x].size(); j ++)
| ~~^~~~~~~~~~~~~~~
# | 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... |