This question is really a pitfall. I don't know the meaning of the question. In fact, it is to press an empty set into the notebook, so the size of the previous questions is only 0, only when adding, to generate a new set of occupied space.
Directly simulate with Stack and set
# Include <iostream> # include <cstdio> # include <cstring> # include <set> # include <stack> # include <map> using namespace STD; int CNT; set <int> S1, S2; stack <set <int> S; Map <set <int>, int> MP; void POP () {S1 = S. top (); S. pop (); S2 = S. top (); S. pop ();} void push () {set <int> TMP; S. push (TMP); puts ("0");} void DUP () {S. push (S. top (); printf ("% d \ n", S. top (). size ();} void uni () {Pop (); For (set <int >:: iterator it = s1.begin (); It! = S1.end (); It ++) {s2.insert (* It);} s. push (S2); printf ("% d \ n", s2.size ();} void inter () {Pop (); set <int> S3; for (set <int >:: iterator it = s1.begin (); it! = S1.end (); It ++) {If (s2.find (* It )! = S2.end () {s3.insert (* It) ;}} S. push (S3); printf ("% d \ n", s3.size ();} void add () {Pop (); If (s1.empty ()) {s2.insert (0);} else {If (! MP [S1]) {MP [S1] = CNT ++;} s2.insert (MP [S1]);} s. push (S2); printf ("% d \ n", s2.size () ;}int main () {int t; scanf ("% d", & T ); char STR [20]; while (t --) {CNT = 1; int m; scanf ("% d", & M); While (! S. empty () s. pop (); MP. clear (); While (M --) {scanf ("% s", STR); If (STR [0] = 'P') Push (); if (STR [0] = 'D') DUP (); If (STR [0] = 'A') add (); if (STR [0] = 'U') Uni (); If (STR [0] = 'I') Inter ();} puts ("***");} return 0 ;}