Skip to content

Commit 051ec78

Browse files
Add files via upload
1 parent ef50cca commit 051ec78

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef vector<int> vi;
7+
#define fast_cin() \
8+
ios_base::sync_with_stdio(false); \
9+
cin.tie(NULL); \
10+
cout.tie(NULL);
11+
12+
int main() {
13+
fast_cin();
14+
int tc;
15+
cin >> tc;
16+
while (tc--) {
17+
int n;
18+
cin >> n;
19+
vi arr(n);
20+
for (int i = 0; i < n; i++) {
21+
cin >> arr[i];
22+
}
23+
unordered_map<int, int> c;
24+
for (int i = 0; i < n; i++) {
25+
c[arr[i]]++;
26+
}
27+
vi d(n);
28+
for (int i = 0; i < n; i++) {
29+
if (c[arr[i]] > 1) {
30+
d[i] = 1;
31+
}
32+
}
33+
int curStart = -1;
34+
int bestStart = -1;
35+
int bestLength = 0;
36+
for (int i = 0; i < n; i++) {
37+
if (d[i] == 0 && ((i == 0) || (d[i - 1] == 1))) {
38+
curStart = i;
39+
}
40+
if (d[i] == 0 && (i == n - 1 || d[i + 1] == 1)) {
41+
if (i - curStart + 1 > bestLength) {
42+
bestLength = i - curStart + 1;
43+
bestStart = curStart;
44+
}
45+
}
46+
}
47+
if (bestStart == -1) {
48+
cout << 0 << endl;
49+
} else {
50+
cout << bestStart + 1 << " " << bestStart + bestLength << endl;
51+
}
52+
}
53+
54+
return 0;
55+
}

0 commit comments

Comments
 (0)