BZOJ1932 [Shoi2007]Setstack 集合堆栈机

妈呀。。。clj大爷太强啦!

原来还有set_union和set_intersection这种东西。。。

于是只要把栈顶的每个元素hash一下记录到一个vector里去就好了

 /**************************************************************
Problem: 1932
User: rausen
Language: C++
Result: Accepted
Time:148 ms
Memory:3372 kb
****************************************************************/ #include <cstdio>
#include <vector>
#include <stack>
#include <algorithm> using namespace std;
typedef unsigned long long ull;
typedef vector <ull> vec;
const int N = 2e3 + ;
const int base = ; inline ull add(const vec &v) {
static ull res;
static int i;
for (i = res = ; i < v.size(); ++i)
res *= base, res += v[i] + ;
return res;
} inline void get(vec &v) {
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
} int n, top;
vec S[N]; int main() {
int i;
char st[];
vec a, b, c(N);
scanf("%d",&n);
for (i = ; i <= n; ++i) {
scanf("%s", st + );
if (st[] == 'P') {
S[++top] = vec();
goto end;
}
if (st[] == 'D') {
++top, S[top] = S[top - ];
goto end;
}
a = S[top--], b = S[top--];
if (st[] == 'A') {
b.push_back(add(a)), get(b);
S[++top] = b;
goto end;
}
c = vec(a.size() + b.size());
if (st[] == 'U') {
c.resize(set_union(a.begin(), a.end(), b.begin(), b.end(), c.begin()) - c.begin());
get(c), S[++top] = c;
goto end;
}
if (st[] == 'I') {
c.resize(set_intersection(a.begin(), a.end(), b.begin(), b.end(), c.begin()) - c.begin());
get(c), S[++top] = c;
goto end;
}
end : printf("%d\n", S[top].size());
}
return ;
}
上一篇:Docker创建MySQL容器环境两部曲


下一篇:【Howie玩docker】-docker安装