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<bits/stdc++.h>
using namespace std;
int N;
int MOD = 1e9 + 7;
vector<int> tastes;
int main(){
cin >> N;
tastes = vector<int>(N);
unordered_map<int, int> frequency;
frequency.reserve(N);
for(int i = 0; i < N; ++i) {
cin >> tastes[i];
frequency[tastes[i]] = 0;
}
long long int ans = 0;
int previousWinner = -1;
for(int i = 0; i < N; ++i){
previousWinner = tastes[i];
ans++;
frequency[tastes[i]]++;
for(int j = i+1; j < N; ++j){
frequency[tastes[j]]++;
if(frequency[tastes[j]] > frequency[previousWinner])previousWinner = tastes[j];
int dist = j - i +1;
if(2*frequency[previousWinner] > dist) ans++;
}
for(int i = 0; i < N; ++i) frequency[tastes[i]] = 0;
ans = ans%MOD;
}
cout << ans << endl;
return 0;
}
# | 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... |