/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 9ms 1.273 MiB
#3 Accepted 2ms 580.0 KiB
#4 Wrong Answer 4ms 752.0 KiB
#5 Wrong Answer 6ms 836.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N = 1e5 + 7;
multiset<ll> st;

bool valid(ll mn, ll mx) {
    auto it = st.lower_bound(mn);

    if (it != st.end() && *it <= mx) return false;
    return true;
}

void delet(ll tmp) {
    auto it = st.find(tmp);
    st.erase(it);
}

bool check(vector<ll> &arr, ll i, ll j) {
    bool ok = true;
    ll mn, mx;
    if (i > 1) mn = mx = arr[1];
    else mn = mx = arr[j + 1];

    while (i < j) {
        delet(arr[i]);
        if (valid(min(mn, arr[i]), max(mx, arr[i]))) {
            mn = min (mn, arr[i]);
            mx = max (mx, arr[i]);
            i++;
            continue;
        }
        st.insert(arr[i]);

        delet(arr[j]);
        if(valid(min(mn, arr[j]), max(mx, arr[j]))) {
            mn = min (mn, arr[j]);
            mx = max (mx, arr[j]);
            j--;
        }
        else {
            ok = false;
            break;
        }
    }

    return ok;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    ll t = 1;
    cin >> t; 

    while (t--) {
        ll n; cin >> n;
        vector<ll> arr(n + 1);

        st.clear();
        for (ll i = 1; i <= n; i++) cin >> arr[i];
        for (int i = 2; i <= n; i++) st.insert(arr[i]);

        if (check(arr, 2, n)) {
            cout << "YES\n";
            continue;
        }
        st.clear();
        for (int i = 1; i < n; i++) st.insert(arr[i]);

        if (check(arr, 1, n - 1)) cout << "YES\n";
        else cout << "NO\n";

    }
}

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-04 07:12:49
Judged At
2025-09-04 22:38:57
Judged By
Score
30
Total Time
9ms
Peak Memory
1.273 MiB