思路

  • 先按照颜色把每条狗存放起来
  • 对它们的亲密度进行二分,求出第 k 对亲密关系的狗的亲密度是多少
  • calc表示求小于等于x的有多少对数,我们利用异色点对数=总点对数-同色点对数来求
  • 然后在枚举该其亲密度,把第 k 对亲密关系的狗输出

代码

// Problem: 温澈滢的狗狗
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/9984/D
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=100010;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);

int n,c[N];
ll k;
vector<int> g[N];

ll calc(ll x){
    ll sum=x*(x-1)/2+x*(n-x);
    for(int i=1;i<=n;i++){
        int pos=0;
        for(int j=0;j<g[i].size();j++){
            while(pos<g[i].size()&&g[i][pos]-g[i][j]<=x) pos++;
            sum-=pos-1-j;
        }
    }
    return sum;
}

void solve(){
    cin>>n>>k;
    rep(i,1,n){
        cin>>c[i];
        g[c[i]].pb(i);
    }

    int l=1,r=n-1,ans=0;
    while(l<=r){
        int mid=(l+r)>>1;
        if(calc(mid)>=k) r=mid-1,ans=mid;
        else l=mid+1;
    }
    if(!ans){
        cout<<"-1\n";
        return;
    }
    ll kk=calc(ans-1);
    rep(i,1,n-ans){
        if(c[i]!=c[i+ans]) kk++;
        if(kk==k){
            cout<<i<<" "<<i+ans<<"\n";
            return;
        }
    }
}


int main(){
    ios::sync_with_stdio(0);cin.tie(0);
//    int t;cin>>t;while(t--)
    solve();
    return 0;
}