2020 计蒜之道 线上决赛

A

不是 2 就是 3

int main() {
    IOS; cin >> n >> m;
    int cnt = 0;
    rep (i, 1, n) cin >> a[i], cnt += (a[i] == 1);
    if (cnt >= 2) cout << 2 << '\n';
    else cout << 3 << '\n';
    return 0;
}

B

水题

int main() {
    IOS; cin >> n >> m;
    rep (i, 1, n) cin >> a[i].se >> a[i].fi;
    sort(a + 1, a + 1 + n);
    rep (i, 1, n - 1) {
        ll cur = i * a[i].fi;
        cout << a[i].se << ' ' << cur / m << ' ' << m - cur % m << '\n';
    } cout << a[n].se;
    return 0;
}

C

静态主席树板子题

const int N = 1e5 + 5;

struct CHT {
    struct node {
        int val, lson, rson;
        node (int Val = 0, int Ls = 0, int Rs = 0)
            : val(Val), lson(Ls), rson(Rs){}
    } tr[20 * N]; //log2(n)*n

    int root[N], tot;

    void update(int &x, int y, int l, int r, int k, int cnt) {
        tr[x = ++tot] = tr[y]; tr[x].val += cnt;
        if (l == r) return;
        int mid = l + r >> 1;
        if (k <= mid) update(tr[x].lson, tr[y].lson, l, mid, k, cnt);
        else update(tr[x].rson, tr[y].rson, mid + 1, r, k, cnt);
    }

    int ask(int x, int y, int l, int r, int cnt) {
        if (l == r) return l;
        int mid = l + r >> 1;
        int res = -1;
        if (tr[tr[x].lson].val - tr[tr[y].lson].val > cnt)
            umax(res, ask(tr[x].lson, tr[y].lson, l, mid, cnt));
        if (tr[tr[x].rson].val - tr[tr[y].rson].val > cnt)
            umax(res, ask(tr[x].rson, tr[y].rson, mid + 1, r, cnt));
        return res;
    }
} bit;

int n, m, _, k;

int main() {
    IOS; cin >> n >> m;
    VI a(n + 1), c(n + 1);
    rep (i, 1, n) cin >> a[i], c[i] = a[i];
    sort(all(c)); c.erase(unique(all(c)), c.end());
    rep (i, 1, n) {
        a[i] = lower_bound(all(c), a[i]) - c.begin();
        bit.update(bit.root[i], bit.root[i - 1], 1, n, a[i], 1);
    }
    rep (i, 1, m) {
        int x, y, t; cin >> x >> y >> t;
        int ans = bit.ask(bit.root[y], bit.root[x - 1], 1, n, (y - x + 1) / t);
        cout << (ans == -1 ? -1 : c[ans]) << '\n';
    }
    return 0;
}

F

组合数学, 选1~m种板子(颜色), 最后一块板子一定放到 第m个小球的后面

剩下的 i - 1块板子, 放到 m - 1 个缝隙之中

ll inv[N] = {0, 1}, a[N] = {1, 1}, b[N] = {1, 1};

ll C(int x, int y, int p = mod) {
    if (y == 0 || x == p) return 1;
    if (x < 0 || y < 0 || y > x) return 0;
    return a[x] * b[y] % p * b[x - y] % p;
}

void init(int n, int p = mod) {
    rep (i, 2, n) {
        inv[i] = (ll)(p - p / i) * inv[p % i] % p;
        a[i] = (ll)a[i - 1] * i % p;
        b[i] = (ll)b[i - 1] * inv[i] % p;
    }
}

int main() {
    IOS; cin >> n >> m; init(n);
    ll ans = 0;
    rep (i, 1, m) ans = (ans + (ll)C(n, i) * C(m - 1, i - 1) % mod) % mod;
    cout << ans;
    return 0;
}
posted @ 2020-10-25 01:34  洛绫璃  阅读(102)  评论(0编辑  收藏  举报