最后一个点UKE求助:
提交记录
#include <bits/stdc++.h>
#define ll long long
#define reg register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
const int N=5e4+30;
const int M=1e6+10;
int record[N];
int sta[2*N],ans[M],cnt=0;
int l=1,r=0;
int n;
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;
int x;
for(reg int i=1;i<=2*n;++i){
cin>>x;
if(record[x]==0){
sta[++r]=x;
record[x]=r;
}
else{
while(record[x]!=r){
ans[++cnt]=record[x];
swap(sta[record[x]],sta[record[x]+1]);
swap(record[x],record[sta[record[x]]]);
}
r--;
}
while(sta[r]==sta[r-1]) r-=2;
}
cout<<cnt<<'\n';
for(reg int i=1;i<=cnt;++i){
cout<<ans[i]<<'\n';
}
return 0;
}