# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
730664 |
2023-04-26T08:59:24 Z |
vjudge1 |
Izbori (COCI22_izbori) |
C++17 |
|
9 ms |
1108 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int NM = 1e5, SZ = 320;
int n, a[NM+5], cnt[NM+5];
bool type[NM+5];
vector <int> v;
ll ans = 0;
int pref[NM+5], bit[NM+5];
void compress(){
for (int i = 1; i <= n; i++)
v.push_back(a[i]);
sort(v.begin(), v.end());
for (int i = 1; i <= n; i++)
a[i] = lower_bound(v.begin(), v.end(), a[i])-v.begin();
}
void solve1(){
memset(cnt, 0, sizeof(cnt));
for (int i = 1; i <= n; i++){
int best = -1;
for (int j = i; j < min(i+2*SZ, n+1); j++){
if (type[a[j]] == 0) cnt[a[j]]++;
if (best == -1 || cnt[a[j]] > cnt[best]) best = a[j];
if (cnt[best]*2 > j-i+1){
ans++;
}
}
for (int j = i; j < min(i+2*SZ, n+1); j++)
if (type[a[j]] == 0) cnt[a[j]]--;
}
}
void update(int p){
while (p <= n){
bit[p]++;
p += p & (-p);
}
}
int get(int p){
int res = 0;
while (p > 0){
res += bit[p];
p -= p & (-p);
}
return res;
}
void solve2(int s){
pref[0] = 0;
for (int i = 1; i <= n; i++){
pref[i] = pref[i-1];
if (a[i] == s) pref[i]++;
}
for (int i = 1; i <= n; i++){
if (2*pref[i]-i > 0) ans++;
ans += get(2*pref[i]-i);
update(2*pref[i]-i);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
compress();
for (int i = 1; i <= n; i++)
cnt[a[i]]++;
for (int i = 0; i < n; i++)
if (cnt[i] > SZ) type[i] = 1;
solve1();
for (int i = 0; i < n; i++)
if (type[i]) solve2(i);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
7 ms |
724 KB |
Output is correct |
10 |
Correct |
8 ms |
848 KB |
Output is correct |
11 |
Correct |
9 ms |
748 KB |
Output is correct |
12 |
Correct |
8 ms |
740 KB |
Output is correct |
13 |
Correct |
8 ms |
724 KB |
Output is correct |
14 |
Correct |
8 ms |
724 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
8 ms |
744 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
724 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
724 KB |
Output is correct |
6 |
Correct |
1 ms |
724 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
1 ms |
724 KB |
Output is correct |
9 |
Correct |
7 ms |
724 KB |
Output is correct |
10 |
Correct |
8 ms |
848 KB |
Output is correct |
11 |
Correct |
9 ms |
748 KB |
Output is correct |
12 |
Correct |
8 ms |
740 KB |
Output is correct |
13 |
Correct |
8 ms |
724 KB |
Output is correct |
14 |
Correct |
8 ms |
724 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
8 ms |
744 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Incorrect |
5 ms |
1108 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |