Submission #1082934

# Submission time Handle Problem Language Result Execution time Memory
1082934 2024-09-02T07:03:29 Z vjudge1 Izbori (COCI22_izbori) C++17
10 / 110
227 ms 9556 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

typedef long long ll;
const int MAX = 2e5 + 2;
const int s = 447;
int a[MAX], p[MAX], cnt[MAX], cnt1[MAX], n;
ll res;
map<int, int> mp;

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    int m = 0;
    for (auto i : mp) {
        mp[i.first] = ++m;
    }
    for (int i = 1; i <= n; i++) {
        a[i] = mp[a[i]];
        cnt1[a[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        int mx = 0;
        for (int j = i; j <= min(n, i + 2 * s - 1); j++) {
            if (cnt1[a[j]] <= s) {
                cnt[a[j]]++;
                mx = max(mx, cnt[a[j]]);
                if (mx > (j - i + 1 - mx)) res++;
            }
        }
        for (int j = i; j <= min(n, i + 2 * s - 1); j++) {
            if (cnt1[a[j]] <= s) cnt[a[j]]--;
        }
    }
    for (int i = 1; i <= m; i++) {
        if (cnt1[i] <= s) continue;
        for (int j = 1; j <= n; j++) p[j] = p[j - 1] + (a[j] == i ? 1 : -1);
        ordered_set st;
        st.insert({0, 0});
        for (int j = 1; j <= n; j++) {
            res += st.order_of_key({p[i], 0});
            st.insert({p[i], j});
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 4 ms 484 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 4 ms 480 KB Output is correct
17 Incorrect 2 ms 604 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 227 ms 9556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 348 KB Output is correct
10 Correct 4 ms 484 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 4 ms 348 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 4 ms 480 KB Output is correct
17 Incorrect 2 ms 604 KB Output isn't correct
18 Halted 0 ms 0 KB -