1006 毒瘤数据结构题
分析:注意第一个和第二个0的位置即可
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6+10;.
int n, p1, p2, a[maxn];
// p1 : 第一个 0, p2 : 第二个 0
int main() {
scanf("%d", &n);
p1 = 1, p2 = 2;
for (int i = 1; i <= n; i++) {
int op, x; scanf("%d%d", &op, &x);
if (op == 1) {
a[x] = 1;
if (x == p1) {
p1 = p2; p2 = p1 + 1;
while (a[p2]) ++ p2;
} else if (x == p2) {
while (a[p2]) ++ p2;
}
} else {
if (x == p1) printf("%d\n", p2);
else printf("%d\n", p1);
}
}
return 0;
}
京公网安备 11010502036488号