QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137589#6626. Real Mountainstatyam#0 1ms3844kbC++172.8kb2023-08-10 14:07:092024-07-04 01:29:23

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 01:29:23]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3844kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 14:07:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void chmin(ll& a, ll b) { if(a > b) a = b; }
void chmax(ll& a, ll b) { if(a < b) a = b; }
#define all(A) begin(A), end(A)


/*
    saishuutekina yama wo u[i] to suru
    h[i] no hikui junnni fuyasu
    h[i] tte unique? tabun
    for x = min(h), ...:
        h.strip(x)
        h[i] == x de aru connected component to h[i] > x de aru CC ni wakete, saishouti wo kannri
        leftmost, rightmost ha 1 kai erabareru
        h[i] > x de aru CC no min{h[i]} no retsu wo U[1], ..., U[k] to suru
        D := #{i | h[i] == x}
        D == 1 ==> cost = U[1] + U[2]
        else ==> cost = U[1] + U[k] + min(U) + (2 * D - 3) * (x + 1)
    dekita
*/
struct ST {
    ll lg = 0;
    vector<vector<ll>> table;
    ST(vector<ll> a) {
        while((2 << lg) <= a.size()) lg++;
        table.resize(lg + 1, a);
        for(ll l = 0; l < lg; l++) for(ll i = 0; i + (2 << l) <= a.size(); i++) {
            table[l + 1][i] = min(table[l][i], table[l][i + (1 << l)]);
        }
    }
    ll get(ll L, ll R) {
        if(L == R) return LLONG_MAX;
        const ll l = __lg(R - L);
        return min(table[l][L], table[l][R - (1 << l)]);
    }
};
int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    ll N;
    cin >> N;
    vector<ll> H(N);
    for(ll& h : H) cin >> h;
    auto X = H;
    sort(all(X));
    X.erase(unique(all(X)), X.end());
    vector idx(N, 0LL);
    for(ll i = 0; i < N; i++) idx[i] = i;
    sort(all(idx), [&](ll i, ll j) { return H[i] > H[j]; });
    ST st(H);
    ll D = 0, L = 0, R = N, ans = 0;
    for(ll x = 0; x + 1 < X.size(); x++) {
        const ll h = X[x], h2 = X[x + 1];
        while(idx.size() && H[idx.back()] == h) {
            idx.pop_back();
            D++;
        }
        while(L < R && H[L] <= h) {
            L++; D--;
        }
        while(L < R && H[R - 1] <= h) {
            R--; D--;
        }
        const ll U1 = [&]{
            ll ok = L + 1, ng = R + 1;
            while(ng - ok > 1) {
                const ll mid = (ok + ng) / 2;
                (st.get(L, mid) > h ? ok : ng) = mid;
            }
            return st.get(L, ok);
        }();
        const ll U2 = [&]{
            ll ok = R - 1, ng = L - 1;
            while(ok - ng > 1) {
                const ll mid = (ok + ng) / 2;
                (st.get(mid, R) > h ? ok : ng) = mid;
            }
            return st.get(ok, R);
        }();
        const ll U3 = X[x + 1];

        if(D == 0) continue;
        ans += D * (h2 - h) * (h + h2 - 1) / 2;
        if(D == 1) ans += (h2 - h) * (U1 + U2);
        else {
            ans += (h2 - h) * (h + h2 + 1) / 2 * (D * 2 - 3);
            ans += (h2 - h) * (U1 + U2 + U3);
        }
    }
    cout << ans << endl;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 1ms
memory: 3488kb

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 3
Accepted
time: 0ms
memory: 3580kb

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

score: 3
Accepted
time: 1ms
memory: 3684kb

input:

10
72 33 22 22 13 49 53 57 72 85

output:

40403

result:

ok 1 number(s): "40403"

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 3844kb

input:

5000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 97 97 97 97 9...

output:

49481200

result:

wrong answer 1st numbers differ - expected: '481053', found: '49481200'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #3:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%