Source Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define sp ' '
#define assert(x,a) if(x){cout << a << endl;return;}
#define sortv(x)sort(x.begin(),x.end())
#define revev(x)reverse(x.begin(),x.end())
inline void fast(){
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    }
vector<vector<int>>graph;

vector<bool>vis(100001,false);
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
inline void answer(int c){assert(c==0,"NO")cout << "YES" << endl;}
void solve()
{
    int n;cin >> n;
    ll ans1 = 0;
    vector<int>l(n);for(int &e : l)cin >> e;
    stack<int>v;
    for(int i = 0;i < l.size();i++)
    {
        if(v.size() == 0)
            v.push(l[i]);
        else
            if(l[i] != v.top())
        {
            ans1++;
            v.pop();
        }
        else
         continue;
    }
    cout << ans1;
}
int main()
{
    fast();
    ll t{ 1 };//cin >> t;
  // cin.ignore();
    while (t--)
    {
        solve();
    }
}
Copy
Tha Bits iwjx
GNU G++17
11 ms
780 KB
Accepted