이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |