Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- using namespace std;
- const int NMAX = 1e5;
- int N, a[NMAX + 2];
- long long sol = 1LL;
- void Solve(int L, int R)
- {
- unordered_map <int, int> fr;
- for(int i = L; i <= R; i++)
- fr[a[i]]++;
- int maxFq = 0, minFq = R - L + 2;
- for(auto it : fr)
- {
- maxFq = max(maxFq, it.second);
- minFq = min(minFq, it.second);
- }
- sol = max(sol, 1LL * maxFq * minFq);
- int l = -1;
- for(int i = L; i <= R; i++)
- if(fr[a[i]] == minFq)
- {
- if(l != -1)
- {
- Solve(l, i - 1);
- l = -1;
- }
- }
- else
- {
- if(l == -1)
- l = i;
- }
- if(l != -1)
- Solve(l, R);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> N;
- for(int i = 1; i <= N; i++)
- cin >> a[i];
- Solve(1, N);
- cout << sol << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement