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 <iostream>
#include <cstring>
#include <map>
using namespace std;
#define ll long long
int n;
ll ways = 0;
int arr[200005];
int total[200005];
int highest = 0;
int main(){
cin >> n;
for(int i = 0; i < n; i++) cin >> arr[i];
for(int l = 0; l < n; l++){
memset(total, 0, sizeof(total));
total[0] = n;
highest = 0;
map<int, int> m;
for(int r = l; r < n; r++){
total[m[arr[r]]]--;
m[arr[r]]++;
total[m[arr[r]]]++;
if(highest < m[arr[r]]){
highest = m[arr[r]];
if(highest + highest > r - l + 1) ways++;
}
else if(total[highest] == 0){
highest--;
}
else if(total[highest] == 1){
if(highest + highest > r - l + 1) ways++;
}
}
}
cout << ways;
}
# | 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... |