Submission #928858

# Submission time Handle Problem Language Result Execution time Memory
928858 2024-02-17T07:06:45 Z a_l_i_r_e_z_a Izbori (COCI22_izbori) C++17
110 / 110
1996 ms 23980 KB
// In the name of God
// Hope is last to die

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
// #define int long long    
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

const int maxn = 2e5 + 5;
const int inf = 1e9 + 7;
int n, a[maxn];
set<int> st;
map<int, int> dp;

ll dac(int l, int r){
    if(l >= r) return 0;
    if(l == r - 1) return 1;
    int mid = (l + r) / 2;
    st.clear();
    dp.clear();
    for(int i = mid - 1; i >= l; i--){
        dp[a[i]]++;
        if(dp[a[i]] * 2 > mid - i) st.insert(a[i]);
    }
    dp.clear();
    for(int i = mid; i < r; i++){
        dp[a[i]]++;
        if(dp[a[i]] * 2 > i - mid + 1) st.insert(a[i]);
    }
    ll ans = 0;
    for(auto v: st){
        dp.clear();
        int prs = 0;
        dp[prs]++;
        for(int i = l; i < mid - 1; i++){
            prs += (a[i] == v ? 1 : -1);
            dp[prs]++;
        }
        int sz = r - l;
        for(int i = -sz; i <= sz; i++) dp[i] += dp[i - 1];
        prs += (a[mid - 1] == v ? 1 : -1);
        for(int i = mid; i < r; i++){
            prs += (a[i] == v ? 1 : -1);
            ans += dp[prs - 1];
        }
    }
    return ans + dac(l, mid) + dac(mid, r);
}

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n; 
    for(int i = 0; i < n; i++) cin >> a[i];
    cout << dac(0, n) << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 496 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 496 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 10 ms 680 KB Output is correct
10 Correct 9 ms 600 KB Output is correct
11 Correct 9 ms 604 KB Output is correct
12 Correct 9 ms 600 KB Output is correct
13 Correct 9 ms 684 KB Output is correct
14 Correct 9 ms 684 KB Output is correct
15 Correct 10 ms 856 KB Output is correct
16 Correct 9 ms 604 KB Output is correct
17 Correct 6 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 946 ms 13684 KB Output is correct
2 Correct 1299 ms 17800 KB Output is correct
3 Correct 709 ms 10580 KB Output is correct
4 Correct 1374 ms 18604 KB Output is correct
5 Correct 1457 ms 19276 KB Output is correct
6 Correct 1524 ms 20404 KB Output is correct
7 Correct 1527 ms 20404 KB Output is correct
8 Correct 1518 ms 20304 KB Output is correct
9 Correct 1527 ms 20400 KB Output is correct
10 Correct 1522 ms 20396 KB Output is correct
11 Correct 949 ms 20404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 496 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 10 ms 680 KB Output is correct
10 Correct 9 ms 600 KB Output is correct
11 Correct 9 ms 604 KB Output is correct
12 Correct 9 ms 600 KB Output is correct
13 Correct 9 ms 684 KB Output is correct
14 Correct 9 ms 684 KB Output is correct
15 Correct 10 ms 856 KB Output is correct
16 Correct 9 ms 604 KB Output is correct
17 Correct 6 ms 688 KB Output is correct
18 Correct 946 ms 13684 KB Output is correct
19 Correct 1299 ms 17800 KB Output is correct
20 Correct 709 ms 10580 KB Output is correct
21 Correct 1374 ms 18604 KB Output is correct
22 Correct 1457 ms 19276 KB Output is correct
23 Correct 1524 ms 20404 KB Output is correct
24 Correct 1527 ms 20404 KB Output is correct
25 Correct 1518 ms 20304 KB Output is correct
26 Correct 1527 ms 20400 KB Output is correct
27 Correct 1522 ms 20396 KB Output is correct
28 Correct 949 ms 20404 KB Output is correct
29 Correct 958 ms 22376 KB Output is correct
30 Correct 303 ms 4404 KB Output is correct
31 Correct 720 ms 8432 KB Output is correct
32 Correct 1996 ms 20088 KB Output is correct
33 Correct 757 ms 9172 KB Output is correct
34 Correct 799 ms 9544 KB Output is correct
35 Correct 466 ms 6164 KB Output is correct
36 Correct 257 ms 3896 KB Output is correct
37 Correct 332 ms 4696 KB Output is correct
38 Correct 1814 ms 20448 KB Output is correct
39 Correct 1769 ms 20404 KB Output is correct
40 Correct 1856 ms 22196 KB Output is correct
41 Correct 1671 ms 20400 KB Output is correct
42 Correct 1825 ms 20408 KB Output is correct
43 Correct 1665 ms 21988 KB Output is correct
44 Correct 1805 ms 22208 KB Output is correct
45 Correct 1797 ms 23980 KB Output is correct
46 Correct 1761 ms 21984 KB Output is correct
47 Correct 1742 ms 21988 KB Output is correct
48 Correct 1861 ms 20816 KB Output is correct
49 Correct 1871 ms 20960 KB Output is correct
50 Correct 1787 ms 22372 KB Output is correct
51 Correct 1823 ms 20576 KB Output is correct
52 Correct 1744 ms 20744 KB Output is correct
53 Correct 1740 ms 20748 KB Output is correct
54 Correct 1703 ms 20696 KB Output is correct