/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 2ms 336.0 KiB
#3 Accepted 2ms 484.0 KiB
#4 Accepted 2ms 444.0 KiB
#5 Accepted 2ms 328.0 KiB
#6 Accepted 2ms 328.0 KiB
#7 Accepted 2ms 536.0 KiB
#8 Accepted 2ms 328.0 KiB
#9 Accepted 2ms 772.0 KiB
#10 Accepted 3ms 328.0 KiB
#11 Accepted 2ms 332.0 KiB
#12 Accepted 2ms 520.0 KiB
#13 Accepted 2ms 520.0 KiB
#14 Accepted 2ms 492.0 KiB
#15 Accepted 2ms 332.0 KiB
#16 Accepted 2ms 560.0 KiB
#17 Accepted 2ms 332.0 KiB
#18 Accepted 3ms 564.0 KiB
#19 Accepted 2ms 480.0 KiB
#20 Accepted 2ms 512.0 KiB
#21 Accepted 3ms 540.0 KiB
#22 Accepted 24ms 1.781 MiB
#23 Accepted 25ms 1.824 MiB
#24 Accepted 30ms 2.312 MiB
#25 Accepted 50ms 3.188 MiB
#26 Accepted 20ms 1.848 MiB
#27 Accepted 5ms 584.0 KiB
#28 Accepted 29ms 1.961 MiB
#29 Accepted 34ms 2.117 MiB
#30 Accepted 38ms 3.258 MiB
#31 Accepted 42ms 2.707 MiB
#32 Accepted 47ms 3.375 MiB
#33 Accepted 36ms 2.824 MiB
#34 Accepted 44ms 2.301 MiB
#35 Accepted 43ms 3.598 MiB

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);
    ll first=-1,last=-1;

    for(ll i=0; i<n; i++)
    {
        if(arr[i]!=brr[i])
        {
            first=i;
            break;
        }
    }
    if(first==-1)
    {
        cout<<"YES"<<endl;
        cout<<1<<" "<<2<<endl;
        return;
    }
    for(ll i=0; i<n; i++)
    {
        if(arr[i]!=brr[i])
        {
            last=i;
        }
    }

    ll len=(last-first)+1;

    if(len>k)
    {
        cout<<"NO"<<endl;
        return;
    }
    cout<<"YES"<<endl;
    cout<<first+1<<" "<<last+1<<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:09:12
Judged At
2024-11-11 02:31:24
Judged By
Score
100
Total Time
50ms
Peak Memory
3.598 MiB