# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1055736 | 2024-08-13T04:38:39 Z | manhlinh1501 | Izbori (COCI22_izbori) | C++17 | 2379 ms | 22444 KB |
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 5e5 + 5; const int BLOCK_SIZE = 475; #define ALL(a) (a).begin(), (a).end() #define LB(a, x) (lower_bound(ALL(a), x) - (a).begin() + 1) int N; int a[MAXN]; vector<int> pos[MAXN]; int prefix[MAXN]; int cnt[MAXN]; struct fenwick { int N; int tree[MAXN]; void update(int x, int v) { for(; x < MAXN; x += (x & -x)) tree[x] += v; } int calc(int x) { int res = 0; for(; x; x -= (x & -x)) res += tree[x]; return res; } } BIT; void compress() { vector<int> temp; for(int i = 1; i <= N; i++) temp.emplace_back(a[i]); sort(ALL(temp)); temp.resize(unique(ALL(temp)) - temp.begin()); for(int i = 1; i <= N; i++) a[i] = LB(temp, a[i]); } signed main() { #define TASK "baucu" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } 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++) pos[a[i]].emplace_back(i); i64 ans = 0; for(int i = 1; i <= N; i++) { int maxx = 0; for(int j = i; j <= min(N, i + 2 * BLOCK_SIZE - 1); j++) { if(pos[a[j]].size() <= BLOCK_SIZE) { cnt[a[j]]++; maxx = max(maxx, cnt[a[j]]); } if(maxx * 2 > (j - i + 1)) ans++; } for(int j = i; j <= min(N, i + 2 * BLOCK_SIZE - 1); j++) { if(pos[a[j]].size() <= BLOCK_SIZE) cnt[a[j]]--; } } BIT.update(N + 1, 1); for(int i = 1; i <= N; i++) { if(pos[i].size() > BLOCK_SIZE) { for(int j = 1; j <= N; j++) prefix[j] = -1; for(int p : pos[i]) prefix[p] = 1; for(int j = 1; j <= N; j++) prefix[j] += prefix[j - 1]; for(int j = 1; j <= N; j++) prefix[j] += (N + 1); for(int j = 1; j <= N; j++) { ans += BIT.calc(prefix[j] - 1); BIT.update(prefix[j], 1); } for(int j = 1; j <= N; j++) BIT.update(prefix[j], -1); } } cout << ans; return (0 ^ 0); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 14684 KB | Output is correct |
2 | Correct | 2 ms | 14680 KB | Output is correct |
3 | Correct | 2 ms | 14680 KB | Output is correct |
4 | Correct | 2 ms | 14684 KB | Output is correct |
5 | Correct | 2 ms | 14684 KB | Output is correct |
6 | Correct | 2 ms | 14684 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 14684 KB | Output is correct |
2 | Correct | 2 ms | 14680 KB | Output is correct |
3 | Correct | 2 ms | 14680 KB | Output is correct |
4 | Correct | 2 ms | 14684 KB | Output is correct |
5 | Correct | 2 ms | 14684 KB | Output is correct |
6 | Correct | 2 ms | 14684 KB | Output is correct |
7 | Correct | 3 ms | 14684 KB | Output is correct |
8 | Correct | 2 ms | 14684 KB | Output is correct |
9 | Correct | 5 ms | 14684 KB | Output is correct |
10 | Correct | 6 ms | 14684 KB | Output is correct |
11 | Correct | 5 ms | 14792 KB | Output is correct |
12 | Correct | 6 ms | 14684 KB | Output is correct |
13 | Correct | 6 ms | 14844 KB | Output is correct |
14 | Correct | 6 ms | 14680 KB | Output is correct |
15 | Correct | 6 ms | 14680 KB | Output is correct |
16 | Correct | 5 ms | 14684 KB | Output is correct |
17 | Correct | 5 ms | 18780 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 225 ms | 20308 KB | Output is correct |
2 | Correct | 303 ms | 20500 KB | Output is correct |
3 | Correct | 172 ms | 19768 KB | Output is correct |
4 | Correct | 330 ms | 20464 KB | Output is correct |
5 | Correct | 328 ms | 20444 KB | Output is correct |
6 | Correct | 346 ms | 20564 KB | Output is correct |
7 | Correct | 347 ms | 20400 KB | Output is correct |
8 | Correct | 337 ms | 20656 KB | Output is correct |
9 | Correct | 341 ms | 20552 KB | Output is correct |
10 | Correct | 348 ms | 20576 KB | Output is correct |
11 | Correct | 333 ms | 21112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 14684 KB | Output is correct |
2 | Correct | 2 ms | 14680 KB | Output is correct |
3 | Correct | 2 ms | 14680 KB | Output is correct |
4 | Correct | 2 ms | 14684 KB | Output is correct |
5 | Correct | 2 ms | 14684 KB | Output is correct |
6 | Correct | 2 ms | 14684 KB | Output is correct |
7 | Correct | 3 ms | 14684 KB | Output is correct |
8 | Correct | 2 ms | 14684 KB | Output is correct |
9 | Correct | 5 ms | 14684 KB | Output is correct |
10 | Correct | 6 ms | 14684 KB | Output is correct |
11 | Correct | 5 ms | 14792 KB | Output is correct |
12 | Correct | 6 ms | 14684 KB | Output is correct |
13 | Correct | 6 ms | 14844 KB | Output is correct |
14 | Correct | 6 ms | 14680 KB | Output is correct |
15 | Correct | 6 ms | 14680 KB | Output is correct |
16 | Correct | 5 ms | 14684 KB | Output is correct |
17 | Correct | 5 ms | 18780 KB | Output is correct |
18 | Correct | 225 ms | 20308 KB | Output is correct |
19 | Correct | 303 ms | 20500 KB | Output is correct |
20 | Correct | 172 ms | 19768 KB | Output is correct |
21 | Correct | 330 ms | 20464 KB | Output is correct |
22 | Correct | 328 ms | 20444 KB | Output is correct |
23 | Correct | 346 ms | 20564 KB | Output is correct |
24 | Correct | 347 ms | 20400 KB | Output is correct |
25 | Correct | 337 ms | 20656 KB | Output is correct |
26 | Correct | 341 ms | 20552 KB | Output is correct |
27 | Correct | 348 ms | 20576 KB | Output is correct |
28 | Correct | 333 ms | 21112 KB | Output is correct |
29 | Correct | 348 ms | 22444 KB | Output is correct |
30 | Correct | 112 ms | 16196 KB | Output is correct |
31 | Correct | 240 ms | 17556 KB | Output is correct |
32 | Correct | 647 ms | 20200 KB | Output is correct |
33 | Correct | 252 ms | 17552 KB | Output is correct |
34 | Correct | 266 ms | 17792 KB | Output is correct |
35 | Correct | 182 ms | 16900 KB | Output is correct |
36 | Correct | 110 ms | 16120 KB | Output is correct |
37 | Correct | 126 ms | 16192 KB | Output is correct |
38 | Correct | 361 ms | 20568 KB | Output is correct |
39 | Correct | 363 ms | 20472 KB | Output is correct |
40 | Correct | 377 ms | 20400 KB | Output is correct |
41 | Correct | 358 ms | 20656 KB | Output is correct |
42 | Correct | 375 ms | 20396 KB | Output is correct |
43 | Correct | 394 ms | 22196 KB | Output is correct |
44 | Correct | 395 ms | 22188 KB | Output is correct |
45 | Correct | 391 ms | 22088 KB | Output is correct |
46 | Correct | 425 ms | 21936 KB | Output is correct |
47 | Correct | 395 ms | 22192 KB | Output is correct |
48 | Correct | 1483 ms | 20652 KB | Output is correct |
49 | Correct | 1495 ms | 20664 KB | Output is correct |
50 | Correct | 786 ms | 20912 KB | Output is correct |
51 | Correct | 841 ms | 20928 KB | Output is correct |
52 | Correct | 386 ms | 16600 KB | Output is correct |
53 | Correct | 2379 ms | 20652 KB | Output is correct |
54 | Correct | 1428 ms | 17592 KB | Output is correct |