-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF1931C.cpp
34 lines (34 loc) · 925 Bytes
/
CF1931C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t T;
cin >> T;
while (T--) {
size_t n;
cin >> n;
map<ui, pair<size_t, size_t>> cnt;
vector<ui> a(n);
for (ui& i : a) cin >> i;
size_t ans1 = 0, ans2 = 0;
{
vector<ui>::iterator it = a.begin(), jt = a.end();
while (it != a.end() && *it == a.front()) ++it;
while (jt != it && *prev(jt) == a.front()) --jt;
ans1 = jt - it;
}
{
reverse(a.begin(), a.end());
vector<ui>::iterator it = a.begin(), jt = a.end();
while (it != a.end() && *it == a.front()) ++it;
while (jt != it && *prev(jt) == a.front()) --jt;
ans2 = jt - it;
}
cout << min(ans1, ans2) << '\n';
}
return 0;
}