제출 #1368792

#제출 시각아이디문제언어결과실행 시간메모리
1368792em4ma2Gift Boxes (EGOI25_giftboxes)C++20
8 / 100
56 ms4312 KiB
#include "bits/stdc++.h"

using namespace std;

#define pb push_back

int t,n;

pair<int,int>check(int l,vector<int>& a){
    int f=0;
    vector<int>mp(t+1);
    for (int i=l;i<n;i++){
        mp[a[i]]++;
        if (mp[a[i]]==2)f++;
    }
    if (!f)return {0,l-1};
    // cout<<"SDF";
    for (int i=l;i<n;i++){
        int fi=a[i-l],se=a[i];
        mp[fi]++;
        mp[se]--;
        if (mp[fi]==2)f++;
        if (mp[se]==1)f--;
        if (!f)return {i-l+1,i};
    }
    return {-1,-1};
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    cin>>t>>n;
    vector<int>a(n);
    for (int i=0;i<n;i++)cin>>a[i];
    int l=1,r=n;
    pair<int,int>ans;
    while (l<=r){
        int mid=(l+r)/2;
        pair<int,int>ex=check(mid,a);
        if (ex.first==-1){
            l=mid+1;
        }else{
            // cout<<mid<<endl;
            r=mid-1;
            ans=ex;
        }
    }
    cout<<ans.first<<" "<<ans.second<<endl;

    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…