玄关,求助
查看原帖
玄关,求助
1362512
Maisie586_楼主2024/7/1 19:33

rt,全WA,求调

#include<iostream>
using namespace std;
const int N=1e5+10;
int n, top, ans, a[N], st[N], now[N]; bool v[N];
int main() {
	scanf("%d", &n);
	for(int i=1;i<=n+n;i++) scanf("%d", &a[i]);
	for(int i=1;i<=n+n;i++) {
		if(v[a[i]]) {
			int cnt=0; 
			while(st[top]!=a[i]) ++ans, now[++cnt]=st[top--];
			--top; while(cnt) st[++top]=now[cnt--];
		}
		else st[++top]=a[i], v[a[i]]=true;
	}
	printf("%d\n", ans);
	return 0;
}
2024/7/1 19:33
加载中...