Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define Ore_Batpar___Ore_Batpar ios_base :: sync_with_stdio(false);
- #define ll long long
- #define MAXN 200007
- bool comp (pair <ll, pair <ll, ll> > p, pair <ll, pair <ll, ll> > q)
- {
- if (p.first == q.first) return p.second.first < q.second.first;
- return p.first < q.first;
- }
- int main ()
- {
- Ore_Batpar___Ore_Batpar
- int test_case; cin >> test_case;
- for (int t = 1; t <= test_case; t++)
- {
- set <ll> Set;
- ll n, currUnique = 0; cin >> n;
- vector <ll> vec(n);
- vector < pair <ll, pair <ll, ll> > > res;
- map <ll, ll> cnt;
- for (int i = 0; i<n; i++) {cin >> vec[i]; Set.insert(vec[i]);}
- ll k = Set.size(), i = 0, j = 0;
- if (k == 1) {cout << "Case " << t << ": " << 0 << " " << 0 << endl; continue;}
- while(j < n)
- {
- if (cnt[vec[j]] == 0) currUnique++;
- cnt[vec[j]]++;
- //cout << "maIN i : " << i << " J : " << j << " CurUn : " << currUnique << endl;
- if (currUnique == k)
- {
- //cout << "Inside of that loop" << endl;
- while(i < j)
- {
- cnt[vec[i]]--;
- if (cnt[vec[i]] == 0)
- {
- currUnique--;
- res.push_back({(j - i + 1), {i, j}});
- //cout << "I : " << i << " J : " << j << endl;
- i++;
- break;
- }
- i++;
- }
- }
- j++;
- }
- sort(res.begin(), res.end(), comp);
- cout << "Case " << t << ": " << res[0].second.first << " " << res[0].second.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement