Source Code
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()

const double eps=1e-7,PI=3.1415926;
const int N=1e6+10;

using namespace std;

int n,q,m,k,x,y,a[N],mx=-1,mn=1e9,sum;
string s,s1,s2;
map < int , int > mp;
vector < int > vec;
int fr[N];
int32_t main(){
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    fr[n]=0;
    for (int i=n-1;i>=0;i--){
        fr[i]=fr[i+1];
        fr[i]+=a[i];
    }
    bool b1=0,b2=0;
    for (int i=0;i<n;i++){
        if (a[i]==0)b1=1;
        if (a[i]==1)b2=1;
        if (b1&&b2&&fr[n-1]-fr[i]!=n-i)sum++,b1=0,b2=0;
    }
    cout<<sum<<endl;
    return 0;
}
Copy
Tha Bits BabaVoss
GNU G++17
19 ms
2.3 MB
Accepted