大意: 给定某一段连续的上线下线记录, 老板上线或下线时房间无人, 并且每次会议都在场, 求哪些人可能是老板.
结论1: 从未出现过的人一定可以是老板.
结论2: 出现过的人中老板最多只有1个.
结论3: 若存在离线时未上线过的人, 那么最后一个这样的人可能是老板. 否则第一个进入的人可能是老板.
#include <iostream>
#include <cstdio>
#include <set>
#define REP(i,a,n) for(int i=a;i<=n;++i)
using namespace std;
const int N = 1e6+10;
int n, m, id[N], ans[N];
char op[N];
int main() {
scanf("%d%d", &n, &m);
REP(i,1,n) ans[i] = 1;
int s = 0, t = 0;
REP(i,1,m) {
scanf(" %c%d", op+i, id+i);
if (op[i]=='-'&&ans[id[i]]) t = id[i];
if (op[i]=='+'&&!s) s = id[i];
ans[id[i]] = 0;
}
set<int> q;
int leader = t?t:s;
q.insert(leader);
ans[leader] = 1;
REP(i,1,m) {
if (op[i]=='+') {
q.insert(id[i]);
if (!q.count(leader)) ans[leader] = 0;
}
else {
q.erase(id[i]);
if (q.size()&&!q.count(leader)) ans[leader] = 0;
}
}
int sum = 0;
REP(i,1,n) sum += ans[i];
printf("%d\n", sum);
REP(i,1,n) if (ans[i]) printf("%d ", i);
puts("");
}