/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 484.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Wrong Answer 1ms 340.0 KiB
#5 Wrong Answer 1ms 532.0 KiB

Code

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long int ll;


using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007

ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}


ll binExp(ll a,ll b)
{
    if(b==0)
        return 1;

    ll res=binExp(a,b/2);

    if(b&1)
    {
        return (a*res*res)%mod;

    }
    else
    {
        return (res*res)%mod;
    }
}


bool isPrime(long long  n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (long long i = 5; i * i <= n; i += 6)
    {
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}

class DisjointSet
{

public:
    vector<ll> parent,rnk,sz;
    DisjointSet(ll n)
    {
        rnk.resize(n+1,0);
        parent.resize(n+1);
        sz.resize(n+1);

        for(ll i=0; i<=n; i++)
        {
            parent[i]=i;
            sz[i]=1;
        }
    }

    ll findUPar(ll node)
    {
        if(node==parent[node])
        {
            return node;
        }
        return parent[node]=findUPar(parent[node]);
    }

    bool unionByRank(ll u,ll v)
    {
        ll ulp_u=findUPar(u);
        ll ulp_v=findUPar(v);

        if(ulp_u==ulp_v)
        {
            return false;
        }
        if(rnk[ulp_u]==rnk[ulp_v])
        {
            parent[ulp_u]=ulp_v;
            rnk[ulp_v]++;
        }
        else if(rnk[ulp_u]<rnk[ulp_v])
        {
            parent[ulp_u]=ulp_v;
        }
        else if(rnk[ulp_v]<rnk[ulp_u])
        {
            parent[ulp_v]=ulp_u;
        }
        return true;
    }

    bool unionBYSize(ll u,ll v)
    {
        ll ulp_u=findUPar(u);
        ll ulp_v=findUPar(v);
        if(ulp_u==ulp_v)
            return false;

        if(sz[ulp_u]<sz[ulp_v])
        {
            parent[ulp_u]=ulp_v;
            sz[ulp_v]+=sz[ulp_u];
        }
        else
        {
            parent[ulp_v]=ulp_u;
            sz[ulp_v]+=sz[ulp_u];
        }
        return true;
    }




};





void solve()
{
    ll n,k;
    cin>>n>>k;


    ll arr[n];
    ll brr[n];
    for(ll i=0; i<n; i++)
    {
        cin>>arr[i];
        brr[i]=arr[i];
    }


    sort(brr,brr+n);


    vector<pair<ll,ll>> vec;

    ll first=-1,second=-1;
    ll i=0;
    while(i<n)
    {
        if(arr[i]!=brr[i] && first==-1)
        {
            first=i+1;
            second=i+1;
        }
        else if(arr[i]!=brr[i] && first!=-1)
        {
            second=i+1;
        }
        else if(arr[i]==brr[i])
        {
            if(first==-1)
            {

            }
            else
            {
                vec.push_back({first,second});
                first=-1;
                second=-1;
            }
        }
        i++;
    }

    if(first!=-1)
    {
        vec.push_back({first,second});
    }
    if(vec.size()>1)
    {
        cout<<"NO"<<endl;
        return;
    }

    if(vec.size()==0)
    {
        cout<<"YES"<<endl;
        cout<<1<<" "<<2<<endl;
        return;
    }

    for(auto v:vec)
    {
        ll ff=v.first;
        ll ss=v.second;
        ll len=abs(ff-ss)+1;
        if(len>k)
        {
            cout<<"NO"<<endl;
            return;
        }
    }
    cout<<"YES"<<endl;
    cout<<vec[0].first<<" "<<vec[0].second<<endl;
}


























int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);





    ll t;

    //cin>>t;
   t=1;






    ll caseNo=1;



    while(t--)
    {
        //cout<<"Case "<<caseNo<<": ";
        // caseNo++;

        solve();


    }


    return 0;




}







Information

Submit By
Type
Submission
Problem
P1120 Stairway to the Skyline
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 15:04:25
Judged At
2024-11-05 15:04:25
Judged By
Score
6
Total Time
1ms
Peak Memory
532.0 KiB