QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117231#6626. Real Mountainspandapythoner#3 2ms4332kbC++202.9kb2023-06-30 18:43:072024-05-31 18:43:34

Judging History

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

  • [2024-05-31 18:43:34]
  • 评测
  • 测评结果:3
  • 用时:2ms
  • 内存:4332kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 18:43:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(234);
const ll mod = 1e6 + 3;
const ll inf = 1e18;

struct SGT {
    int n;
    vector<ll> t;

    void build(vector<ll> &a) {
        n = 1;
        while (n < (int)a.size()) {
            n *= 2;
        }
        t.assign(n + n, 0);
        for (int i = 0; i < (int)a.size(); i += 1) {
            t[i + n] = a[i];
        }
        for (int i = n - 1; i >= 1; i -= 1) {
            t[i] = min(t[i + i], t[i + i + 1]);
        }
    }

    ll get(int l, int r) {
        l += n;
        r += n;
        ll rs = inf;
        while (l < r) {
            if (l & 1) {
                rs = min(rs, t[l]);
                l += 1;
            }
            if (r & 1) {
                r -= 1;
                rs = min(rs, t[r]);
            }
            l /= 2;
            r /= 2;
        }
        return rs;
    }
};

ll sum_on_seg(ll l, ll r) {
    return (l * (r - l) % mod + (r - l - 1) * (r - l) / 2) % mod;
}

int n;
vector<ll> h;

ll solve() {
    ll rs = 0;
    vector<pair<ll, int>> srtd(n);
    for (int i = 0; i < n; i += 1) {
        srtd[i] = make_pair(h[i], i);
    }
    sort(all(srtd));
    int i = 0;
    int l = 0;
    int r = n - 1;
    set<int> st;
    ll val = -inf;
    SGT sgt;
    sgt.build(h);
    while (l < r) {
        ll new_val = val;
        if (i < n) {
            new_val = srtd[i].first;
        }
        if (!st.empty()) {
            int x = *st.begin();
            int y = *prev(st.end());
            ll mnl = sgt.get(l, x);
            ll mnr = sgt.get(y + 1, r + 1);
            rs = (rs + (mnl + mnr) * (new_val - val) % mod) % mod;
            assert(mnl >= new_val && mnr >= new_val);
            ll f = (int)st.size() - 1;
            rs = (rs + sum_on_seg(val + 1, new_val + 1) * (f + max(0ll, f - 1)) % mod) % mod;
            if (f > 1) {
                rs = (rs + new_val * (new_val - val)) % mod;
            }
        }
        val = new_val;
        while (i < n && srtd[i].first == val) {
            st.insert(srtd[i].second);
            i += 1;
        }
        while (!st.empty() && l == *st.begin()) {
            st.erase(st.begin());
            rs = (rs + sum_on_seg(h[l], val)) % mod;
            l += 1;
        }
        while (!st.empty() && r == *prev(st.end())) {
            st.erase(prev(st.end()));
            rs = (rs + sum_on_seg(h[r], val)) % mod;
            r -= 1;
        }
    }
    return rs;
}

int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    cin >> n;
    h.resize(n);
    for (int i = 0; i < n; i += 1) {
        cin >> h[i];
    }
    cout << solve() << "\n";
    return 0;
}

詳細信息

Subtask #1:

score: 3
Accepted

Test #1:

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

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

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

input:

10
72 33 22 22 13 49 53 57 72 85

output:

40403

result:

ok 1 number(s): "40403"

Test #4:

score: 3
Accepted
time: 2ms
memory: 4072kb

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:

481053

result:

ok 1 number(s): "481053"

Test #5:

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

input:

5000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

5000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

12595

result:

ok 1 number(s): "12595"

Test #7:

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

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 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 100 100 100 100 100 100 100 100...

output:

299

result:

ok 1 number(s): "299"

Test #8:

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

input:

5000
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

224232

result:

ok 1 number(s): "224232"

Test #9:

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

input:

5000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4...

output:

0

result:

ok 1 number(s): "0"

Test #10:

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

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 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 99 99 99 99 9...

output:

0

result:

ok 1 number(s): "0"

Test #11:

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

input:

5000
100 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4...

output:

499735

result:

ok 1 number(s): "499735"

Test #12:

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

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 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 99 99 99 99 9...

output:

461407

result:

ok 1 number(s): "461407"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #13:

score: 3
Accepted
time: 2ms
memory: 4128kb

input:

5000
37 39 93 78 85 71 59 21 57 96 61 59 23 16 57 90 13 59 85 70 62 67 78 97 16 60 8 48 28 53 4 24 1 97 97 98 57 87 96 91 74 54 100 76 86 86 46 39 100 57 70 76 73 55 84 93 64 6 84 39 75 94 30 15 3 31 11 34 27 10 6 81 30 76 60 9 4 47 1 88 17 71 61 30 19 10 4 57 79 37 22 74 84 8 91 58 15 45 7 98 32 46...

output:

216624

result:

ok 1 number(s): "216624"

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

29
29 62 90 18 57 29 75 67 93 45 53 45 30 77 3 52 16 31 56 37 47 52 3 23 61 66 50 39 30

output:

110358

result:

wrong answer 1st numbers differ - expected: '110566', found: '110358'

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:

100%
Accepted

Dependency #2:

0%