답안 #968110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968110 2024-04-23T07:43:59 Z Darren0724 Real Mountains (CCO23_day1problem2) C++17
6 / 25
5000 ms 31560 KB
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define ll long long 
#define LCBorz ios_base::sync_with_stdio(false);cin.tie(0);
const int N=1000005;
const int mod=1e6+3;
const int INF=1e7;
struct segtree{
    int v[N<<2];
    void pull(int id){
        v[id]=min(v[id<<1],v[id<<1|1]);
    }
    void add(int id,int l,int r,int p,int x){
        if(r-l==1){
            v[id]=x;
            return;
        }
        int m=(l+r)>>1;
        if(p<m)add(id<<1,l,m,p,x);
        else add(id<<1|1,m,r,p,x);
        pull(id);
    }
    int ask(int id,int l,int r,int a,int b){
        if(a<=l&&b>=r)return v[id];
        int m=(l+r)>>1;
        if(b<=m)return ask(id<<1,l,m,a,b);
        if(a>=m)return ask(id<<1|1,m,r,a,b);
        return min(ask(id<<1,l,m,a,b),ask(id<<1|1,m,r,a,b));
    }
}st;
int32_t main(){
    LCBorz;
    int n;cin>>n;
    vector<int> v(n+2),pre(n+2),suf(n+2);
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    for(int i=1;i<=n;i++){
        pre[i]=max(pre[i-1],v[i]);
    }
    for(int i=n;i>=1;i--){
        suf[i]=max(suf[i+1],v[i]);
    }
    for(int i=1;i<=n;i++){
        st.add(1,1,n+1,i,v[i]);
    }
    ll ans=0;
    for(int val=1;val<=100;val++){
        vector<int> t;
        for(int j=1;j<=n;j++){
            if(v[j]<=val){
                st.add(1,1,n+1,j,INF);
            }
            if(min(pre[j],suf[j])>v[j]&&v[j]==val){
                t.push_back(j);
            }
        }
        for(int j:t){
            v[j]++;
        }
        int m=t.size();
        if(m==0){
            continue;
        }
        if(m==1){
            ans+=val+st.ask(1,1,n+1,1,t[0])+st.ask(1,1,n+1,t[0]+1,n+1);
            ans%=mod;
            //cout<<ans<<endl;
            continue;
        }
        int tmp=st.ask(1,1,n+1,1,t[0])+st.ask(1,1,n+1,t[0]+1,n+1)+val+(val+1)+val+st.ask(1,1,n+1,t[m-1]+1,n+1);
        int tmp1=st.ask(1,1,n+1,1,t[m-1])+st.ask(1,1,n+1,t[m-1]+1,n+1)+val+(val+1)+val+st.ask(1,1,n+1,1,t[0]);
        ans+=min(tmp,tmp1);
        ans+=(m-2)*(3*val+2);
        ans%=mod;
    }
    cout<<ans<<endl;
    
    return 0;
}
/*
20
1 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 -1 1 -1 -1 1
4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
13 Correct 14 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 636 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 14 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 22 ms 608 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 22 ms 604 KB Output is correct
23 Correct 11 ms 600 KB Output is correct
24 Correct 11 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 12 ms 628 KB Output is correct
27 Correct 12 ms 600 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
13 Correct 14 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 636 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 14 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 22 ms 608 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 22 ms 604 KB Output is correct
23 Correct 11 ms 600 KB Output is correct
24 Correct 11 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 12 ms 628 KB Output is correct
27 Correct 12 ms 600 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Incorrect 3 ms 604 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
13 Correct 14 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 636 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 14 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 22 ms 608 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 22 ms 604 KB Output is correct
23 Correct 11 ms 600 KB Output is correct
24 Correct 11 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 12 ms 628 KB Output is correct
27 Correct 12 ms 600 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Incorrect 3 ms 604 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
13 Correct 14 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 636 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 14 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 22 ms 608 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 22 ms 604 KB Output is correct
23 Correct 11 ms 600 KB Output is correct
24 Correct 11 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 12 ms 628 KB Output is correct
27 Correct 12 ms 600 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 4062 ms 31352 KB Output is correct
36 Correct 4100 ms 30828 KB Output is correct
37 Correct 4127 ms 31560 KB Output is correct
38 Correct 4152 ms 30324 KB Output is correct
39 Correct 4080 ms 30580 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Execution timed out 5042 ms 30384 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
13 Correct 14 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 636 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 14 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 22 ms 608 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 22 ms 604 KB Output is correct
23 Correct 11 ms 600 KB Output is correct
24 Correct 11 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 12 ms 628 KB Output is correct
27 Correct 12 ms 600 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Incorrect 3 ms 604 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 11 ms 596 KB Output is correct
5 Correct 23 ms 600 KB Output is correct
6 Correct 23 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 23 ms 604 KB Output is correct
9 Correct 11 ms 596 KB Output is correct
10 Correct 11 ms 600 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 12 ms 604 KB Output is correct
13 Correct 14 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 636 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 14 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 22 ms 608 KB Output is correct
21 Correct 22 ms 604 KB Output is correct
22 Correct 22 ms 604 KB Output is correct
23 Correct 11 ms 600 KB Output is correct
24 Correct 11 ms 604 KB Output is correct
25 Correct 11 ms 604 KB Output is correct
26 Correct 12 ms 628 KB Output is correct
27 Correct 12 ms 600 KB Output is correct
28 Correct 13 ms 600 KB Output is correct
29 Correct 0 ms 352 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Incorrect 3 ms 604 KB Output isn't correct
36 Halted 0 ms 0 KB -