| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1335474 | killerzaluu | Sequence (APIO23_sequence) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
int n, i, j;
cin >> n;
int a[n + 1];
for(i = 1; i <= n; i++) cin >> a[i];
int ans = 0;
for(i = 1; i <= n; i++) {
ordered_set<pair<int,int>> sad;
int freq[n + 1];
for(int k = 1; k <= n; k++) freq[k] = 0;
for(j = i; j <= n; j++) {
sad.insert({a[j], j});
freq[a[j]]++;
int len = j - i + 1;
auto L = *sad.find_by_order((len - 1) / 2);
auto R = *sad.find_by_order(len / 2);
int x = L.first;
int y = R.first;
ans = max(ans, max(freq[x], freq[y]));
}
}
cout << ans << endl;
}