Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <bits/stdc++.h>
- #include <map>
- #define pb push_back
- #define ll long long
- using namespace std;
- int n,q,rez,maxim;
- int a[200010];
- bool viz[200010];
- int max_app,cntViz[200010],Reprez[200010];
- bool isNice()
- {
- int i;
- for(i=1;i<=n;i++){
- cntViz[a[i]]++;
- Reprez[a[i]]=i;
- max_app=max(cntViz[a[i]],max_app);
- if(i>=2 && viz[a[i]]==true && viz[a[i-1]]==true && a[i]!=a[i-1]){
- return false;
- }
- if(viz[a[i]]==false){
- viz[a[i]]=true;
- }
- }
- return true;
- }
- int main()
- {
- cin>>n>>q;
- int i;
- for(i=1;i<=n;i++){
- cin>>a[i];
- }
- if(isNice()==true){
- cout<<0;
- }
- int f,S=0,prev=1;
- for(i=1;i<=n;i++)
- {
- maxim=max(maxim,cntViz[a[i]]);
- S+=cntViz[a[i]];
- cntViz[a[i]]=0;
- if(S==i-prev)
- {
- rez+=(S-maxim);
- prev=i+1;
- S=maxim=0;
- }
- }
- cout<<rez;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement