【CF467C】Sequence Transformation


链接

代码

#include <iostream>
#include <algorithm>
#include <map>

using namespace std;
const int N = 2e5 + 10;

map<int, int> mp;
void solve(){
    
    
    mp.clear();
    int n;
    int a[N] = {
    
    0};
    cin >> n;
    for (int i = 1; i <= n; ++i) {
    
    
        cin >> a[i];
        if (a[i - 1] != a[i]) mp[a[i]]++;
    }
    int res = N;
    mp[a[1]]--;
    mp[a[n]]--;
    for (int i = 1; i <= n; ++i) {
    
    
        res = min(mp[a[i]] + 1, res);
    }
    cout << res << endl;
}

int main() {
    
    
    ios::sync_with_stdio(false);
    cin.tie();
    int cases;
    cin >> cases;
    while (cases--){
    
    
        solve();
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_50070650/article/details/112784981