Submission #751266

# Submission time Handle Problem Language Result Execution time Memory
751266 2023-05-31T10:11:29 Z stevancv Izbori (COCI22_izbori) C++14
10 / 110
1008 ms 9708 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 4e5 + 5;
const int S = 400;
const int inf = 1e9;
int n;
struct Fenwick {
    int bit[N];
    void Reset() {
        for (int i = 1; i < N; i++) bit[i] = 0;
    }
    void Add(int x) {
        x += n + 1;
        for (; x < N; x += x & (-x)) bit[x] += 1;
    }
    int Get(int x) {
        int ans = 0; x += n;
        for (; x > 0; x -= x & (-x)) ans += bit[x];
        return ans;
    }
}f;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    map<int, int> hsh;
    int z = 0;
    vector<int> a(n);
    vector<vector<int>> pos(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (hsh.find(a[i]) == hsh.end()) hsh[a[i]] = z++;
        a[i] = hsh[a[i]];
        pos[a[i]].push_back(i);
    }
    vector<int> big(n);
    for (int i = 0; i < n; i++) if (pos[i].size() >= S) big[i] = 1;
    ll ans = 0;
    vector<int> cnt(n);
    for (int i = 0; i < n; i++) {
        int mx = a[i];
        for (int j = i; j >= max(0, i - 2 * S); j--) {
            cnt[a[j]] += 1;
            if (cnt[a[j]] > cnt[mx]) mx = a[j];
            if (2 * cnt[mx] > i - j + 1 && big[mx] == 0) ans += 1;
        }
        for (int j = i; j >= max(0, i - 2 * S); j--) cnt[a[j]] = 0;
    }
    for (int p = 0; p < n; p++) {
        if (big[p] == 0) continue;
        vector<int> pref(n);
        f.Reset();
        f.Add(0);
        for (int i = 0; i < n; i++) {
            if (a[i] == p) pref[i] += 1;
            else pref[i] -= 1;
            if (i > 0) pref[i] += pref[i - 1];
            ans += f.Get(pref[i]);
            f.Add(pref[i]);
            cout << p << sp << i << endl;
        }
    }
    cout << ans << en;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 9 ms 428 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 10 ms 340 KB Output is correct
12 Correct 9 ms 420 KB Output is correct
13 Correct 9 ms 424 KB Output is correct
14 Correct 9 ms 428 KB Output is correct
15 Correct 9 ms 424 KB Output is correct
16 Correct 9 ms 420 KB Output is correct
17 Incorrect 13 ms 1956 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1008 ms 9708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 9 ms 428 KB Output is correct
10 Correct 6 ms 340 KB Output is correct
11 Correct 10 ms 340 KB Output is correct
12 Correct 9 ms 420 KB Output is correct
13 Correct 9 ms 424 KB Output is correct
14 Correct 9 ms 428 KB Output is correct
15 Correct 9 ms 424 KB Output is correct
16 Correct 9 ms 420 KB Output is correct
17 Incorrect 13 ms 1956 KB Output isn't correct
18 Halted 0 ms 0 KB -