Submission #1106440

# Submission time Handle Problem Language Result Execution time Memory
1106440 2024-10-30T10:46:13 Z atom Izbori (COCI22_izbori) C++17
10 / 110
256 ms 3180 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

const int N = 2e5 + 5;
const int B = 450;
int a[N];
int n;

bool sub12() {
    return (n <= 2000);
}

bool sub3() {
    for (int i = 1; i <= n; ++i)
        if (a[i] > 2) return false;
    return true;
}

template <typename T>
struct Fenwick {
    vector <int> f;
    int n;
    Fenwick(int _n) {
        f.resize(_n + 5);
        n = _n;
    }

    void upd(int x, int val) {
        for (; x <= n; x += x & -x)
            f[x] += val;
    }

    int get(int x) {
        int ans = 0;
        for (; x > 0; x -= x & -x)
            ans += f[x];
        return ans;
    }
};

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in2", "r", stdin);
    #endif

    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vector <int> vals;
    for (int i = 1; i <= n; ++i)
        vals.push_back(a[i]);

    sort(vals.begin(), vals.end());
    vals.resize(unique(vals.begin(), vals.end()) - vals.begin());

    vector <int> cnt(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        a[i] = (int) (lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin() + 1);
        cnt[a[i]]++;
    }

    vector <bool> heavy(n + 1, false);
    for (int i = 1; i <= n; ++i) {
        if (cnt[i] >= B)
            heavy[i] = true;
    }

    ll ans = 0;
    // processing light queries: all elements appear less than sqrt(n)
    cnt.assign(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        int mx = 0;
        for (int j = i; j <= n && (j - i + 1) / 2 < B; ++j) {
            if (!heavy[a[j]]) {
                cnt[a[j]]++;
                if (cnt[a[j]] > mx) mx = cnt[a[j]];
                if (mx > (j - i + 1) / 2) {
                    debug(i, j, mx);
                    ++ans;
                }
            }
        }

        for (int j = i; j <= n && (j - i + 1) / 2 < B; ++j)
            if (!heavy[a[j]]) cnt[a[j]]--;
    }

    // processing heavy queries: all elements appear at least sqrt(n)
    for (int x = 1; x <= n; ++x) {
        if (heavy[x]) {
            auto get = [&] (int _x) { debug(_x); return _x + n; };

            vector <int> f(2 * n + 5, 0);
            int sum = 0;
            int prf = 0;
            f[get(prf)]++;
            for (int i = 1; i <= n; ++i) {
                if (get(prf) > 0)
                    sum += f[get(prf - 1)];
                else    
                    sum -= f[get(prf)];
                ans += sum;
                f[get(prf)]++;
            }
        }
    }

    cout << ans << "\n";

    
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 166
      |                    ^~~
Main.cpp:89:21: note: in expansion of macro 'debug'
   89 |                     debug(i, j, mx);
      |                     ^~~~~
Main.cpp: In lambda function:
Main.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 166
      |                    ^~~
Main.cpp:102:39: note: in expansion of macro 'debug'
  102 |             auto get = [&] (int _x) { debug(_x); return _x + n; };
      |                                       ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 336 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 336 KB Output is correct
15 Correct 5 ms 336 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Incorrect 3 ms 336 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 256 ms 3180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 508 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 5 ms 336 KB Output is correct
10 Correct 5 ms 336 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 6 ms 336 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 5 ms 336 KB Output is correct
15 Correct 5 ms 336 KB Output is correct
16 Correct 5 ms 336 KB Output is correct
17 Incorrect 3 ms 336 KB Output isn't correct
18 Halted 0 ms 0 KB -