玄关,求助
  • 板块题目总版
  • 楼主Maisie586_
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/1 14:48
  • 上次更新2024/7/1 17:04:53
查看原帖
玄关,求助
1362512
Maisie586_楼主2024/7/1 14:48

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 14:48
加载中...