loj2392. "JOISC 2017 Day 1" Sparklers

The meaning of problems

The title says very clearly Asia. . The question surfaces again copy it again.

There \ (N \) standing a number line. They staff a fireworks, fireworks are just in the hands of each person can burn \ (T \) seconds. Each fireworks can only be ignited once.
\ (1 \) No. standing origin, \ (I \) Number ( \ (1 \ I Leq \ Leq N \) ) to \ (1 \) from the number of \ (X_i \) . Ensure \ (X_1 = 0 \) , \ (X_1, X_2, ..., x_n \) monotonically increments (position someone may overlap).
At the beginning, \ (K \) fireworks numbers just started burning, others were not ignite fireworks. Their ignition tool is broken, can only use a lighted fireworks will not ignite fireworks ignited. When the two overlapping position and one of them in the hands of burning fireworks, fireworks in the hands of another person can be ignited. Ignore the ignition time required.
We need to ask how fast to run at least, everyone can light fireworks (fireworks at this time there may be some who have gone out). Speed must be a non-negative integer.

note: The minimum required speed of the maximum speed in full.

answer

This question meet half of nature, we can ask a half \ (v \) , and then determine whether there is a legitimate program.

Note that for an interval \ ([L, R & lt] \) , and the first interval has a fireworks burning, if all of the fireworks can be ignited interval, which must meet a solution, the relative position of all does not change. Thus, in this embodiment, as long as \ (x_L + vT (R - L) \ geq x_R - vT (R - L) \) can. The same, if not \ (x_L + vT (R - L) \ geq x_R - vT (R - L) \) the conditions, then obviously the whole interval can not be all lit (with \ (v \) speed ).

Persimmon observed above, transposition, to give
\ [x_L - 2vTL \ geq x_R
- 2vTR \] then let \ (= a_i x_i - 2vTi \) , then the problem becomes the interval \ ([K, K] \ ) began to an outer extension interval, each time to ensure an expansion section \ ([l, r] \ ) to satisfy \ (A_L \ GEQ A_R \) . If and only if the interval can be extended to \ ([. 1, n-] \) , all of the fireworks can be ignited.

A Property Observation: For scalability interval \ ([L, R & lt] \) , for \ (I <L \) , if satisfied:

1. \ (a_i \ geq a_l \)

2.\(\forall j \in [i, l]\)\(a_j \geq a_r\)

It is known that the interval \ ([i, r] \ ) is extensible.

In this way, we can continue to do this operation about every fixed interval legitimate left (right) end point, moving outward and right (left) endpoints.

If a second left to right can not be extended, and because \ (a_i \ geq a_l \ wedge \ exists j \ in [i, l], a_j <a_r \) reason for this, then that can not ignite the whole big range \ ([1, n] \ ) fireworks.

Otherwise, we will get a great interval \ ([ml, of Mr] \) (the section can not be extended by the above-described manner, and because \ (\ nexists I <L, a_i \ GEQ A_L \) ).

In this case, we can only be judged in a different way - from the Greater interval \ ([1, n] \ ) inward contraction.

In this case, the interval may be reduced \ ([L, R & lt] \) , for \ (L <I \ Leq ml \) , if satisfied:

1. \ (a_i \ geq a_l \)

2.\(\forall j \in [l, i]\)\(a_j \geq a_r\)

Interval \ ([i, r] \ ) may be reduced, too.

Until the interval \ ([ml, mr] \ ) if you can avoid shrinking, then that can be lit all the fireworks.

prove? In fact, this is a reverse process, the inverse process click on the very obvious. (You can try to draw a line graph)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, K, T, x[N];
ll a[N];

bool check (int v) {
    for (int i = 1; i <= n; ++i) {
        a[i] = 0ll + x[i] - 2ll * T * v * i;
    }
    if (a[1] < a[n]) {
        return 0;
    }
    int ql = K, qr = K, l, r;
    for (int i = K - 1; i; --i) {
        if (a[i] >= a[ql]) {
            ql = i;
        }
    }
    for (int i = K + 1; i <= n; ++i) {
        if (a[i] <= a[qr]) {
            qr = i;
        }
    }
    for (l = r = K; l != ql || r != qr; ) {
        int ok = 0, L = l, R = r;
        for ( ; L > ql && a[L - 1] >= a[r]; ) {
            if (a[--L] >= a[l]) {
                break;
            }
        }
        if (L < l && a[L] >= a[l]) {
            ok = 1, l = L;
        }
        for ( ; R < qr && a[R + 1] <= a[l]; ) {
            if (a[++R] <= a[r]) {
                break;
            }
        }
        if (R > r && a[R] <= a[r]) {
            ok = 1, r = R;
        }
        if (!ok) {
            return 0;
        }
    }
    for (l = 1, r = n; l != ql || r != qr; ) {
        int ok = 0, L = l, R = r;
        for ( ; L < ql && a[L + 1] >= a[r]; ) {
            if (a[++L] >= a[l]) {
                break;
            }
        }
        if (L > l && a[L] >= a[l]) {
            ok = 1, l = L;
        }
        for ( ; R > qr && a[R - 1] <= a[l]; ) {
            if (a[--R] <= a[r]) {
                break;
            }
        }
        if (R < r && a[R] <= a[r]) {
            ok = 1, r = R;
        }
        if (!ok) {
            return 0;
        }
    }
    return 1;
}
int main () {
    scanf("%d%d%d", &n, &K, &T);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &x[i]);
    }
    int l = 0, r = 1e9, mid, ans = r;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) {
            ans = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Guess you like

Origin www.cnblogs.com/psimonw/p/11203634.html