# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
730690 |
2023-04-26T09:17:05 Z |
vjudge1 |
Izbori (COCI22_izbori) |
C++17 |
|
1785 ms |
5320 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int NM = 2e5, SZ = 600;
int n, a[NM+5], cnt[NM+5];
bool type[NM+5];
vector <int> v;
ll ans = 0;
int pref[NM+5];
int bit[2*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 <= 2*n+1){
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]++;
}
memset(bit, 0, sizeof(bit));
update(n+1);
for (int i = 1; i <= n; i++){
ans += get(2*pref[i]-i+n);
update(2*pref[i]-i+n+1);
}
}
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 |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
4 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
13 ms |
1136 KB |
Output is correct |
10 |
Correct |
12 ms |
1108 KB |
Output is correct |
11 |
Correct |
12 ms |
1116 KB |
Output is correct |
12 |
Correct |
13 ms |
1160 KB |
Output is correct |
13 |
Correct |
8 ms |
1108 KB |
Output is correct |
14 |
Correct |
12 ms |
1164 KB |
Output is correct |
15 |
Correct |
9 ms |
1108 KB |
Output is correct |
16 |
Correct |
12 ms |
1116 KB |
Output is correct |
17 |
Correct |
6 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
4476 KB |
Output is correct |
2 |
Correct |
481 ms |
4912 KB |
Output is correct |
3 |
Correct |
280 ms |
4104 KB |
Output is correct |
4 |
Correct |
502 ms |
4980 KB |
Output is correct |
5 |
Correct |
497 ms |
5040 KB |
Output is correct |
6 |
Correct |
552 ms |
5188 KB |
Output is correct |
7 |
Correct |
529 ms |
5240 KB |
Output is correct |
8 |
Correct |
565 ms |
5188 KB |
Output is correct |
9 |
Correct |
569 ms |
5240 KB |
Output is correct |
10 |
Correct |
587 ms |
5112 KB |
Output is correct |
11 |
Correct |
568 ms |
5116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
2 ms |
1104 KB |
Output is correct |
3 |
Correct |
1 ms |
1104 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
2 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
4 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
13 ms |
1136 KB |
Output is correct |
10 |
Correct |
12 ms |
1108 KB |
Output is correct |
11 |
Correct |
12 ms |
1116 KB |
Output is correct |
12 |
Correct |
13 ms |
1160 KB |
Output is correct |
13 |
Correct |
8 ms |
1108 KB |
Output is correct |
14 |
Correct |
12 ms |
1164 KB |
Output is correct |
15 |
Correct |
9 ms |
1108 KB |
Output is correct |
16 |
Correct |
12 ms |
1116 KB |
Output is correct |
17 |
Correct |
6 ms |
2644 KB |
Output is correct |
18 |
Correct |
409 ms |
4476 KB |
Output is correct |
19 |
Correct |
481 ms |
4912 KB |
Output is correct |
20 |
Correct |
280 ms |
4104 KB |
Output is correct |
21 |
Correct |
502 ms |
4980 KB |
Output is correct |
22 |
Correct |
497 ms |
5040 KB |
Output is correct |
23 |
Correct |
552 ms |
5188 KB |
Output is correct |
24 |
Correct |
529 ms |
5240 KB |
Output is correct |
25 |
Correct |
565 ms |
5188 KB |
Output is correct |
26 |
Correct |
569 ms |
5240 KB |
Output is correct |
27 |
Correct |
587 ms |
5112 KB |
Output is correct |
28 |
Correct |
568 ms |
5116 KB |
Output is correct |
29 |
Correct |
539 ms |
5192 KB |
Output is correct |
30 |
Correct |
307 ms |
1496 KB |
Output is correct |
31 |
Correct |
634 ms |
1748 KB |
Output is correct |
32 |
Correct |
1654 ms |
2596 KB |
Output is correct |
33 |
Correct |
695 ms |
1876 KB |
Output is correct |
34 |
Correct |
706 ms |
1784 KB |
Output is correct |
35 |
Correct |
472 ms |
1696 KB |
Output is correct |
36 |
Correct |
292 ms |
1496 KB |
Output is correct |
37 |
Correct |
316 ms |
1496 KB |
Output is correct |
38 |
Correct |
541 ms |
5124 KB |
Output is correct |
39 |
Correct |
643 ms |
5124 KB |
Output is correct |
40 |
Correct |
642 ms |
5192 KB |
Output is correct |
41 |
Correct |
536 ms |
5128 KB |
Output is correct |
42 |
Correct |
612 ms |
5124 KB |
Output is correct |
43 |
Correct |
593 ms |
5064 KB |
Output is correct |
44 |
Correct |
612 ms |
5152 KB |
Output is correct |
45 |
Correct |
605 ms |
5148 KB |
Output is correct |
46 |
Correct |
600 ms |
5156 KB |
Output is correct |
47 |
Correct |
606 ms |
5152 KB |
Output is correct |
48 |
Correct |
1782 ms |
5320 KB |
Output is correct |
49 |
Correct |
1785 ms |
5296 KB |
Output is correct |
50 |
Correct |
1016 ms |
5300 KB |
Output is correct |
51 |
Correct |
1035 ms |
5304 KB |
Output is correct |
52 |
Correct |
1493 ms |
2768 KB |
Output is correct |
53 |
Correct |
1532 ms |
2760 KB |
Output is correct |
54 |
Correct |
1765 ms |
5304 KB |
Output is correct |