2019 Hang electric field of the second multi-school

2019 Multi-University Training Contest 2

Replenishment link: 2019 Multi-University Training Contest The 2

1005 Everything Is Generated In Equal Probability (HDU-6595)

The meaning of problems

A given integer \ (N \) , in \ ([1, N] \ ) randomly generate one \ (n-\) . Then generates length \ (n-\) of the full array \ ([. 1, n-] \) .

The arrangement of a running program, the current program seeking to reverse logarithmic arrangement, then a randomly selected sequence from whole arrangement. The sequences present routine continues recursively until the sequence length \ (0 \) exit, the program returns the total number of reverse pair. Program generates seeking answers expectations.

answer

#include <iostream>
#include <queue>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 998244353;

ll qpow(ll a, ll n, ll m) {
    ll ans = 1;
    while (n) {
        if (n & 1) {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}

int main() {
    int n;
    ll k = qpow(9, mod - 2, mod);
    while (~scanf("%d", &n)) {
        ll ans = n * n - 1;
        printf("%lld\n", ans * k % mod);
    }
    return 0;
}

1010 Just Skip The Problem (HDU-6600)

\ (Solved \ by \ ZMZ \)

The meaning of problems

Given a number \ (n \) , you can ask many times \ (y_i \) , then you can know \ (n \ xor \ y_i \ ) is equal to \ (y_i \) , the minimum number of inquiries can know \ (n \ ) is the number, find the least number of inquiries asking several programs.

Results of the \ (1e6 + 3 \) modulo.

answer

The answer is \ (the n-! \ MOD \ 1e6 + 3 \) .

When \ (n \ ge 1e6 + 3 \) when the answer to \ (0 \) .

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 5;
const ll mod = 1e6 + 3;
ll fac[maxn];

void init() {
    fac[0] = 1;
    for (int i = 1; i <= mod; ++i) {
        fac[i] = i * fac[i - 1];
        fac[i] %= mod;
    }
}

int main() {
    int n;
    init();
    while (~scanf("%d", &n)) {
        if (n <= mod) {
            printf("%lld\n", fac[n]);
        }
        else {
            printf("0\n");
        }
    }
    return 0;
}

1011 Keen On Everything But Triangle (HDU-6601)

The meaning of problems

Given \ (n-\) number, \ (Q \) th interrogation.

Each interrogation a given interval \ ([L, R] \ ) maximum perimeter, the inner section can be composed of triangular and asked how much.

answer

Chairman of the enumeration tree

Chairman of the tree seeking Interval \ (k \) large, from the largest, the second largest, the \ (k \) big so continue to enumerate, meet the conditions on the output.

Number not constitute a triangle as a Fibonacci number. Since Fibonacci column \ (40 \) number more than \ (1E9 \) , and therefore will not enumerate the number of times a lot.

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;

struct node {
    int ls, rs, sum;
} ns[MAXN * 20];

int ct;
int rt[MAXN * 20];

void cpy(int& now, int old) {
    now = ++ct;
    ns[now] = ns[old];
}

void pushUp(int& now) {
    ns[now].sum = ns[ns[now].ls].sum + ns[ns[now].rs].sum;
}

void build(int& now, int l, int r) {
    now = ++ct;
    ns[now].sum = 0;
    if (l == r) return;
    int m = (l + r) >> 1;
    build(ns[now].ls, l, m);
    build(ns[now].rs, m + 1, r);
}

void update(int& now, int old, int l, int r, int x) {
    cpy(now, old);
    if (l == r) {
        ns[now].sum++;
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) update(ns[now].ls, ns[old].ls, l, m, x);
    else update(ns[now].rs, ns[old].rs, m + 1, r, x);
    pushUp(now);
}

int query(int s, int t, int l, int r, int k) {
    if (l == r) return l;
    int m = (l + r) >> 1;
    int cnt = ns[ns[t].ls].sum - ns[ns[s].ls].sum;
    //cout << s << " " << t << " " << cnt << endl;
    if (k <= cnt) return query(ns[s].ls, ns[t].ls, l, m, k);
    return query(ns[s].rs, ns[t].rs, m + 1, r, k - cnt);
}

void init(int n) {
    ct = 0;
    build(rt[0], 1, n);
}

int a[MAXN], b[MAXN];
int c[MAXN];

int main() {
    int n, m;
    while (cin >> n >> m) {
        // scanf("%d%d", &n, &m);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            b[i] = a[i];
        }
        sort(b + 1, b + n + 1);
        int sz = unique(b + 1, b + 1 + n) - b - 1;
        init(sz);
        for (int i = 1; i <= n; i++) {
            a[i] = lower_bound(b + 1, b + 1 + sz, a[i]) - b;
            update(rt[i], rt[i - 1], 1, sz, a[i]);
        }
        while (m--) {
            int s, t, k;
            scanf("%d%d", &s, &t);
            // printf("%d", t - s + 1);
            // printf("%d\n", b[query(rt[s - 1], rt[t], 1, sz, k)]);
            if(t - s + 1 < 3) printf("-1\n");
            else {
                int cnt = 0, flag = 0;
                for(int i = t - s + 1; i > 0; --i) {
                    c[cnt] = b[query(rt[s - 1], rt[t], 1, sz, i)];
                    if(cnt > 1 && c[cnt - 2] < c[cnt - 1] + c[cnt]) {
                        printf("%lld\n", c[cnt - 2] * 1ll + c[cnt - 1] * 1ll + c[cnt] * 1ll);
                        flag = 1;
                        break;
                    }
                    ++cnt;
                }
                if(!flag) printf("-1\n");
            }
        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/wulitaotao/p/11428288.html