Oh, my God. CLJ is too strong!
There are set_union and set_intersection, the same thing ...
So just hash each element of the top of the stack and record it in a vector.
1 /**************************************************************2 problem:19323 User:rausen4 language:c++5 result:accepted6 time:148 Ms7 memory:3372 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <vector> A#include <stack> -#include <algorithm> - the using namespacestd; -typedef unsignedLong Longull; -typedef vector <ull>Vec; - Const intN = 2e3 +5; + Const int Base=2333; - +Inline ull Add (ConstVEC &v) { A Staticull Res; at Static inti; - for(i = res =0; I < v.size (); ++i) -Res *=Base, res + = V[i] +101; - returnRes; - } - inInlinevoid Get(Vec &v) { - sort (V.begin (), V.end ()); toV.resize (Unique (V.begin (), V.end ())-V.begin ()); + } - the intn, top; * VEC s[n]; $ Panax Notoginseng intMain () { - inti; the Charst[ the]; + Vec A, B, C (N); Ascanf"%d",&n); the for(i =1; I <= N; ++i) { +scanf"%s", St +1); - if(st[1] =='P') { $S[++top] =Vec (); $ Gotoend; - } - if(st[1] =='D') { the++top, S[top] = s[top-1]; - Gotoend;Wuyi } theA = s[top--], B = s[top--]; - if(st[1] =='A') { WuB.push_back (Add (a)),Get(b); -S[++top] =b; About Gotoend; $ } -c = VEC (A.size () +b.size ()); - if(st[1] =='U') { -C.resize (Set_union (A.begin (), A.end (), B.begin (), B.end (), C.begin ())-C.begin ()); A Get(c), s[++top] =C; + Gotoend; the } - if(st[1] =='I') { $C.resize (Set_intersection (A.begin (), A.end (), B.begin (), B.end (), C.begin ())-C.begin ()); the Get(c), s[++top] =C; the Gotoend; the } theend:printf ("%d\n", S[top].size ()); - } in return 0; the}View Code
BZOJ1932 [Shoi2007]setstack Collection Stack Machine