QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117229#6626. Real Mountainspandapythoner#0 1ms3884kbC++202.7kb2023-06-30 18:34:402024-05-31 18:43:31

Judging History

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

  • [2024-05-31 18:43:31]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3884kb
  • [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:34:40]
  • 提交

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) + (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;
            ll f = (int)st.size() - 1;
            rs = (rs + sum_on_seg(val + 1, new_val + 1) * f) % 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: 0
Wrong Answer

Test #1:

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

input:

3
29 9 9

output:

0

result:

ok 1 number(s): "0"

Test #2:

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

input:

3
62 20 71

output:

7287

result:

ok 1 number(s): "7287"

Test #3:

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

input:

10
72 33 22 22 13 49 53 57 72 85

output:

29719

result:

wrong answer 1st numbers differ - expected: '40403', found: '29719'

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%