이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 ++)
{
int j = i + ans;
if (j >= occ[x].size())
break;
int l = occ[x][i], r = occ[x][j];
int min_lf = 1e9, max_lf = -1e9;
int min_rf = 1e9, max_rf = -1e9;
for (int p = 0; p < l; p ++)
{
min_lf = min(min_lf, pref[p]);
max_lf = max(max_lf, pref[p]);
}
for (int p = r; p <= N; p ++)
{
min_rf = min(min_rf, pref[p]);
max_rf = max(max_rf, pref[p]);
}
max_rf += (j - i + 1);
min_rf -= (j - i + 1);
if (max(min_rf, min_lf) <= min(max_rf, max_lf))
{
ans ++;
i --;
}
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < occ[x].size(); i ++)
| ~~^~~~~~~~~~~~~~~
sequence.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if (j >= occ[x].size())
| ~~^~~~~~~~~~~~~~~~
# | 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... |