Files
2026-05-18 15:26:14 +08:00

44 lines
809 B
C++

#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> statu(n + 1);
for (int i = 1; i <= n; i++){
cin >> statu[i];
}
stack<int> sk;
for (int i = 1; i <= n; i++){
if (sk.empty()){
sk.push(i);
}
else{
// 状态一样就都留下,不一样就抵消删掉栈顶
if (statu[i] == statu[sk.top()]){
sk.push(i);
}
else{
sk.pop();
}
}
}
int ans = -1;
// 遍历栈,最后留存的就是最靠前的
while (!sk.empty()){
ans = sk.top();
sk.pop();
}
cout << ans << endl;
return 0;
}