#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <functional>
#include <complex>
#include <climits>
#include <random>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
using namespace std;
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define speed ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
const int mod = (int) 1e9 + 7;
const int N = (int) 2e5 + 100, bruh = 500;
ll a[N], n, k;
map<int, int> cnt;
signed main(){
speed;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
cnt[a[i]]++;
}
ll ans = 0;
for(auto [x, sz] : cnt){
if(sz > bruh){
map <ll, ll> mp;
ll cur = 0, act = 0;
ans = (1LL * (n * (n + 1))) / 2LL;
for(ll i = 1; i <= n; i++){
if(a[i] == x) cur--;
else cur++;
mp[cur]++;
}
cur = 0;
for(ll i = 1; i <= n; i++){
ans -= mp[act];
if(a[i] == x){
cur--;
act--;
}
else{
cur++;
act++;
}
mp[cur]--;
}
}
}
for(int i = 1; i <= n; i++){
map<int, int> cnt1;
int lst = -1, lstA = -1;
for(int j = i; j <= n; j++){
if((j - i + 1) > 2 * bruh) break;
if(a[j] == lstA) lst++;
++cnt1[a[j]];
int sz = (j - i) + 1;
if(lst > (sz / 2) && cnt[lstA] <= bruh) ans++;
else if(cnt1[a[j]] > (sz / 2) && cnt[a[j]] <= bruh){
ans++;
lst = cnt1[a[j]];
lstA = a[j];
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
59 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
452 KB |
Output is correct |
10 |
Correct |
34 ms |
476 KB |
Output is correct |
11 |
Correct |
33 ms |
348 KB |
Output is correct |
12 |
Correct |
32 ms |
480 KB |
Output is correct |
13 |
Correct |
33 ms |
472 KB |
Output is correct |
14 |
Correct |
32 ms |
348 KB |
Output is correct |
15 |
Correct |
33 ms |
348 KB |
Output is correct |
16 |
Correct |
34 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1307 ms |
1776 KB |
Output is correct |
2 |
Correct |
1720 ms |
1852 KB |
Output is correct |
3 |
Correct |
995 ms |
1340 KB |
Output is correct |
4 |
Correct |
1915 ms |
2128 KB |
Output is correct |
5 |
Correct |
1981 ms |
1956 KB |
Output is correct |
6 |
Correct |
2102 ms |
2076 KB |
Output is correct |
7 |
Correct |
2097 ms |
1884 KB |
Output is correct |
8 |
Correct |
1968 ms |
2068 KB |
Output is correct |
9 |
Correct |
2005 ms |
2048 KB |
Output is correct |
10 |
Correct |
2092 ms |
2128 KB |
Output is correct |
11 |
Correct |
1372 ms |
14528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
59 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
33 ms |
452 KB |
Output is correct |
10 |
Correct |
34 ms |
476 KB |
Output is correct |
11 |
Correct |
33 ms |
348 KB |
Output is correct |
12 |
Correct |
32 ms |
480 KB |
Output is correct |
13 |
Correct |
33 ms |
472 KB |
Output is correct |
14 |
Correct |
32 ms |
348 KB |
Output is correct |
15 |
Correct |
33 ms |
348 KB |
Output is correct |
16 |
Correct |
34 ms |
344 KB |
Output is correct |
17 |
Correct |
11 ms |
600 KB |
Output is correct |
18 |
Correct |
1307 ms |
1776 KB |
Output is correct |
19 |
Correct |
1720 ms |
1852 KB |
Output is correct |
20 |
Correct |
995 ms |
1340 KB |
Output is correct |
21 |
Correct |
1915 ms |
2128 KB |
Output is correct |
22 |
Correct |
1981 ms |
1956 KB |
Output is correct |
23 |
Correct |
2102 ms |
2076 KB |
Output is correct |
24 |
Correct |
2097 ms |
1884 KB |
Output is correct |
25 |
Correct |
1968 ms |
2068 KB |
Output is correct |
26 |
Correct |
2005 ms |
2048 KB |
Output is correct |
27 |
Correct |
2092 ms |
2128 KB |
Output is correct |
28 |
Correct |
1372 ms |
14528 KB |
Output is correct |
29 |
Correct |
1422 ms |
14524 KB |
Output is correct |
30 |
Execution timed out |
3051 ms |
2396 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |