#include "sequence.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int occ[maxn];
vector < pair < int, int > > ranges[maxn];
int sequence(int N, vector<int> A)
{
if (N > 2e3)
{
int len = 1;
for (int i = 1; i < N; i ++)
{
if (A[i] == A[i - 1])
len ++;
else
{
ranges[A[i - 1]].push_back({i - len, i - 1});
len = 1;
}
}
ranges[A[N - 1]].push_back({N - len, N - 1});
int ans = 1;
for (int i = 1; i <= N; i ++)
{
for (pair < int, int > cur : ranges[i])
ans = max(ans, cur.second - cur.first + 1);
if (ranges[i].size() == 2)
{
pair < int, int > lf, rf;
lf = ranges[i][0];
rf = ranges[i][1];
int big = rf.first - lf.second - 1;
int small = lf.first + N - rf.second - 1;
int mid = (lf.second - lf.first + 1 + rf.second - rf.first + 1);
if (big > small + mid)
continue;
///cout << i << " : " << small << " : " << big << " : " << mid << endl;
//cout << lf.first << " " << rf.second << endl;
ans = max(ans, mid);
}
}
return ans;
}
else
{
multiset < int > lf, rf;
int ans = 1;
for (int i = 0; i < N; i ++)
{
for (int j = 0; j <= N; j ++)
occ[j] = 0;
lf.clear();
rf.clear();
lf.insert(A[i]);
occ[A[i]] ++;
for (int j = i + 1; j < N; j ++)
{
occ[A[j]] ++;
if (A[j] > *lf.rbegin())
rf.insert(A[j]);
else
lf.insert(A[j]);
while(lf.size() > rf.size() + 1)
{
int x = *lf.rbegin();
lf.erase(lf.find(x));
rf.insert(x);
}
while(rf.size() > lf.size())
{
int x = *rf.begin();
rf.erase(rf.find(x));
lf.insert(x);
}
if ((j - i + 1) % 2 == 0)
{
ans = max(ans, occ[*lf.rbegin()]);
ans = max(ans, occ[*rf.begin()]);
}
else
{
ans = max(ans, occ[*lf.rbegin()]);
}
}
}
return ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12008 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12008 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
259 ms |
12116 KB |
Output is correct |
14 |
Correct |
254 ms |
12148 KB |
Output is correct |
15 |
Correct |
261 ms |
12144 KB |
Output is correct |
16 |
Correct |
266 ms |
12144 KB |
Output is correct |
17 |
Correct |
269 ms |
12140 KB |
Output is correct |
18 |
Correct |
184 ms |
12140 KB |
Output is correct |
19 |
Correct |
272 ms |
12144 KB |
Output is correct |
20 |
Correct |
304 ms |
12144 KB |
Output is correct |
21 |
Correct |
262 ms |
12144 KB |
Output is correct |
22 |
Correct |
259 ms |
12144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
62 ms |
25852 KB |
Output is correct |
3 |
Correct |
61 ms |
25796 KB |
Output is correct |
4 |
Correct |
37 ms |
15940 KB |
Output is correct |
5 |
Correct |
62 ms |
24812 KB |
Output is correct |
6 |
Correct |
60 ms |
24752 KB |
Output is correct |
7 |
Correct |
41 ms |
15948 KB |
Output is correct |
8 |
Correct |
39 ms |
15936 KB |
Output is correct |
9 |
Correct |
45 ms |
15920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
41 ms |
18592 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
96 ms |
31532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12008 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
259 ms |
12116 KB |
Output is correct |
14 |
Correct |
254 ms |
12148 KB |
Output is correct |
15 |
Correct |
261 ms |
12144 KB |
Output is correct |
16 |
Correct |
266 ms |
12144 KB |
Output is correct |
17 |
Correct |
269 ms |
12140 KB |
Output is correct |
18 |
Correct |
184 ms |
12140 KB |
Output is correct |
19 |
Correct |
272 ms |
12144 KB |
Output is correct |
20 |
Correct |
304 ms |
12144 KB |
Output is correct |
21 |
Correct |
262 ms |
12144 KB |
Output is correct |
22 |
Correct |
259 ms |
12144 KB |
Output is correct |
23 |
Incorrect |
21 ms |
14368 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
6 ms |
12008 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
6 ms |
11988 KB |
Output is correct |
11 |
Correct |
6 ms |
11988 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
259 ms |
12116 KB |
Output is correct |
14 |
Correct |
254 ms |
12148 KB |
Output is correct |
15 |
Correct |
261 ms |
12144 KB |
Output is correct |
16 |
Correct |
266 ms |
12144 KB |
Output is correct |
17 |
Correct |
269 ms |
12140 KB |
Output is correct |
18 |
Correct |
184 ms |
12140 KB |
Output is correct |
19 |
Correct |
272 ms |
12144 KB |
Output is correct |
20 |
Correct |
304 ms |
12144 KB |
Output is correct |
21 |
Correct |
262 ms |
12144 KB |
Output is correct |
22 |
Correct |
259 ms |
12144 KB |
Output is correct |
23 |
Correct |
62 ms |
25852 KB |
Output is correct |
24 |
Correct |
61 ms |
25796 KB |
Output is correct |
25 |
Correct |
37 ms |
15940 KB |
Output is correct |
26 |
Correct |
62 ms |
24812 KB |
Output is correct |
27 |
Correct |
60 ms |
24752 KB |
Output is correct |
28 |
Correct |
41 ms |
15948 KB |
Output is correct |
29 |
Correct |
39 ms |
15936 KB |
Output is correct |
30 |
Correct |
45 ms |
15920 KB |
Output is correct |
31 |
Incorrect |
41 ms |
18592 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |