답안 #792497

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792497 2023-07-25T06:00:11 Z 이동현(#10054) Real Mountains (CCO23_day1problem2) C++17
0 / 25
0 ms 212 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

const int mod = (int)1e6 + 3;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n), srt(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        srt[i] = a[i];
    }
    sort(srt.begin(), srt.end());
    srt.erase(unique(srt.begin(), srt.end()), srt.end());

    int ans = 0;
    for(int i = 0; i + 1 < (int)srt.size(); ++i){
        vector<int> lmn(n, -1), rmn(n, -1);
        set<int> st;

        for(int j = 0; j < n; ++j){
            auto p = st.lower_bound(a[j] + 1);
            if(p != st.end()){
                lmn[j] = *p;
            }
            st.insert(a[j]);
        }
        st.clear();
        for(int j = n - 1; j >= 0; --j){
            auto p = st.lower_bound(a[j] + 1);
            if(p != st.end()){
                rmn[j] = *p;
            }
            st.insert(a[j]);
        }

        for(int j = 0; j < n; ++j){
            if(lmn[j] != -1 && rmn[j] != -1 && a[j] == srt[i]){
                ans += (lmn[j] + rmn[j]) * (srt[i + 1] - srt[i]) + (srt[i] + srt[i + 1] - 1) * (srt[i + 1] - srt[i]) / 2;
                a[j] = srt[i + 1];
            }
        }
    }

    cout << ans % mod << '\n';
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -