/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 5ms 956.0 KiB
#3 Accepted 1ms 764.0 KiB
#4 Wrong Answer 4ms 692.0 KiB
#5 Wrong Answer 3ms 788.0 KiB

Code

// IN THE NAME OF ALLAH
// Coded by Ahsanul Imam
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
// find_by_order() - Returns an iterator to the k-th largest element(counting from zero)
// order_of_key() - The number of items in a set that are strictly smaller than our item
typedef long long int ll;
const int  MOD = 1000000007;
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define f first
#define s second
#define nl '\n';
#define bit(a) __builtin_popcountll(a)
#define cnt_sese_sunno(x) __builtin_ctz(x)
#define cnt_age_sunno(x) __builtin_clz(x)
#define cnt_sese_ek(x) __builtin_ctz(~x)
#define cnt_age_ek(x) __builtin_clz(~x)
#define parity(x) __builtin_parity(x)
#define parityLL(x) __builtin_parityll(x)
#define w(x) while (x--)
#define test int t; cin>>t; for (int i = 1; i <= t; i++)
#define loop for (int i = 0; i < n; i++)
#define print(v) for(auto it:v)cout<<it<<' ';cout<<endl;
#define srt(v) sort(v.begin(), v.end());
#define rsrt(v) sort(v.rbegin(), v.rend());
#define gcd(a, b) __gcd<long long int>(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define pi 2*acos(0.0)
#define pr pair<int, int>
#define Ahsanul (ios_base::sync_with_stdio(false), cin.tie(NULL))
vector<pr>knight_posible{{2, 1}, {2, -1}, {1, 2}, {1, -2}, {-1, 2}, {-1, -2}, {-2, 1}, {-2, -1}};//knight moves
vector<pr>posible{{0,-1},{0,1},{-1,0},{1,0},{-1,-1},{-1,1},{1,-1},{1,1}};//eight direction moves;
int power(int a,int b){int res=1;while (b){if (b&1){res=(res*1ll*a)%MOD;}a=(a*1ll*a)%MOD;b>>=1;}return res;}
ll inversemod(ll base) { return power(base,MOD-2); }
void solve()
{
    int n; cin>>n;
    deque<int>v(n),ans;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    deque<int>tem=v;
    srt(tem);
    map<int,int>fre;
    for(int i=0;i<n;i++)
    {
        fre[tem[i]]=i+1;
    }
    ans.pb(v[0]);
    int curr=fre[v[0]];
    int cnt=1;;
    int i=1,j=n-1;
    while (cnt<n)
    {
        int a=fre[v[i]],b=fre[v[j]];
        //cout<<curr<<' '<<a<<' '<<b<<nl;
        if(a==curr+1)
        {
            ans.pb(v[i]);
            curr=a;
            i++;
        }
        else if(curr==a+1)
        {
            ans.push_front(v[i]);
            i++;
            curr=a;
        }
        else if(curr==b+1)
        {
            ans.push_front(v[j]);
            curr=b;
            j--;
        }
        else if(b==curr+1)
        {
            ans.push_back(v[j]);
            curr=b;
            j--;
        }
        else
        {
            //cout<<curr<<" "<<a<<" "<<b<<' '<<fre[i].f<<' '<<fre[]
            cout<<"NO"<<nl;
            return;
        }
        cnt++;
    }
    //print(ans);
    cout<<"YES"<<nl;
}
int main()
{
    Ahsanul;
    test
    {
        //cout<<"Case "<<i<<": ";
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1229 Array of Beauty
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-04 18:32:00
Judged At
2025-09-04 22:38:57
Judged By
Score
30
Total Time
5ms
Peak Memory
956.0 KiB