Submission #613624

# Submission time Handle Problem Language Result Execution time Memory
613624 2022-07-30T08:19:49 Z yuto1115 Diversity (CEOI21_diversity) C++17
0 / 100
1 ms 1492 KB
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n) - 1; i >= 0; --i)
#define rrep2(i, n, t) for(ll i = ll(n) - 1; i >= ll(t); --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int sz = 300000;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vi a(n);
    for (int &i: a) {
        cin >> i;
        --i;
    }
    vi l(q), r(q);
    rep(i, q) {
        cin >> l[i] >> r[i];
        --l[i];
    }
    const int B = min(n, 1338);
    vi ord(q);
    iota(all(ord), 0);
    sort(all(ord), [&](int i, int j) {
        if (r[i] / B != r[j] / B) return r[i] / B < r[j] / B;
        return l[i] < l[j];
    });
    vi cnt(sz);
    map<int, int> mp;
    mp[0] = sz;
    auto add = [&](int x) {
        if (--mp[cnt[x]] == 0) mp.erase(cnt[x]);
        ++mp[++cnt[x]];
    };
    auto del = [&](int x) {
        if (--mp[cnt[x]] == 0) mp.erase(cnt[x]);
        ++mp[--cnt[x]];
    };
    vvp ls(q);
    int nl = 0, nr = 0;
    for (int i: ord) {
        while (nl > l[i]) add(a[--nl]);
        while (nr < r[i]) add(a[nr++]);
        while (nl < l[i]) del(a[nl++]);
        while (nr > r[i]) del(a[--nr]);
        ls[i].reserve(SZ(mp));
        for (auto[f, s]: mp) if (f) ls[i].eb(f, s);
    }
    rep(i, q) cerr << SZ(ls[i]) << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -