Submission #1370042

#TimeUsernameProblemLanguageResultExecution timeMemory
1370042turkeyorzGift Boxes (EGOI25_giftboxes)C++20
40 / 100
38 ms12292 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(int tc)
{
    int t, n;
    cin>>t>>n;
    vector<int> a(n), cnt(t, 0);
    for(auto &i : a) {
        cin>>i;
        ++cnt[i];
    }
    int tot = 0, nn = 0;
    for(int i=0;i<t;++i) {
        tot += (int)(cnt[i] - 1);
    }
    pair<int, int> p = {-1, -1};
    deque<int> p3;
    deque<pair<int, int>> p2;
    vector<int> cnt2(t, 0);
    for(int i=0;i<n;++i) {
        ++cnt2[a[i]];
        p2.push_back({a[i], cnt2[a[i]]});
        p3.push_back(i);
        if(cnt2[a[i]] == 1 && cnt[a[i]] > 1)
            ++nn;
        while(p2.size() > 0 && p2[0].second == 1 && cnt2[p2[0].first] == cnt[p2[0].first]) {
            p2.pop_front();
            p3.pop_front();
        }
        if(nn >= tot && p3.size()) {
            int gg = i - p3.front() + 1;
            if(p.first == -1 || p.second - p.first + 1 > gg) {
                p = {p3.front(), i};
            }
        }
    }
    cout<<p.first<<' '<<p.second<<'\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // freopen("problem.in", "r", stdin);
    // freopen("problem.out", "w", stdout);

    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve(t - i);
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...