/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 8ms 1.27 MiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 13ms 812.0 KiB
#5 Accepted 16ms 788.0 KiB
#6 Accepted 17ms 1.02 MiB
#7 Wrong Answer 4ms 532.0 KiB
#8 Wrong Answer 5ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll N = 1e5+7;
multiset<ll> st;
ll n, arr[N];

bool valid(ll mn, ll mx) {
    auto it = st.lower_bound(mn+1);
    if (it != st.end() and *it < mx) return false;
    return true;
}

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

bool check(ll i, ll j) {
    ll mn, mx;
    if (i > 1) mn = mx = arr[1];
    else mn = mx = arr[n];

    while (i < j) {
        // Delete(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]);

        // Delete(arr[j]);
        if (valid(min(mn, arr[j]), max(mx, arr[j]))) {
            mn = min(mn, arr[j]);
            mx = max(mx, arr[j]);
            j--;
        }
        else return false;
    }

    return true;
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll tc; cin >> tc; 

    test:
    while (tc--) {
        cin >> n;
        for (ll i = 1; i <= n; i++) cin >> arr[i];
        
        st.clear();
        for (ll i = 2; i <= n; i++) st.insert(arr[i]);
        if (check(2, n)) {
            cout << "YES\n";
            goto test;
        }
        
        st.clear();
        for (ll i = 1; i < n; i++) st.insert(arr[i]);
        if (check(1, n-1)) {
            cout << "YES\n";
            goto test;
        }
        
        cout << "NO\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-05 16:20:52
Judged At
2025-09-05 16:20:52
Judged By
Score
60
Total Time
17ms
Peak Memory
1.27 MiB