#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define inf ((int)1e9)
using namespace std;
void solve1(int n) {
vector <int> arr(n);
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
auto compress = [&](vector <int> &a) {
vector <pair<int, int> > v(a.size());
for(int i = 0; i < n; i++) {
v[i] = {a[i], i};
}
sort(v.begin(), v.end());
for(int i = 0, ind = 0; i < n; i++) {
if(i and v[i].first != v[i - 1].first) ind++;
a[v[i].second] = ind;
}
};
compress(arr);
int ans = 0;
for(int l = 0; l < n; l++) {
vector <int> cnt(n);
int mx = 0;
for(int r = l; r < n; r++) {
cnt[arr[r]]++;
mx = max(mx, cnt[arr[r]]);
if(mx > (r - l + 1) / 2) ans++;
}
}
cout << ans << "\n";
}
bitset <200000> st;
void solve2(int n) {
for(int i = 0; i < n; i++) {
int in;
cin >> in;
st[i] = in - 1;
}
int ans = 0;
for(int l = 0; l < n; l++) {
int cnt[2] = {0};
for(int r = l; r < n; r++) {
cnt[st[r]]++;
ans += cnt[0] != cnt[1];
}
}
cout << ans << "\n";
}
int32_t main(){
fast
int n;
cin >> n;
if(n <= 2000) solve1(n);
else solve2(n);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
480 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
484 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
8 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3024 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
348 KB |
Output is correct |
11 |
Correct |
3 ms |
480 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
3 ms |
344 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
484 KB |
Output is correct |
16 |
Correct |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
8 ms |
348 KB |
Output is correct |
18 |
Execution timed out |
3024 ms |
344 KB |
Time limit exceeded |
19 |
Halted |
0 ms |
0 KB |
- |