BZOJ1932 [Shoi2007]setstack Collection Stack Machine

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.