-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetStack.cpp
More file actions
42 lines (40 loc) · 1.04 KB
/
SetStack.cpp
File metadata and controls
42 lines (40 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <stack>
using namespace std;
typedef set<int>Set;
map<Set,int>IDcache;
vector<Set> Setcache;
//查找给定集合x的ID。如果找不到,分配一个新ID
int ID(Set s){
if(IDcache.count(s)) return IDcache[s];
Setcache.push_back(s);
return IDcache[s]=Setcache.size()-1;
}
//宏定义
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
int main(){
stack <int>s;
int n;
cin>>n;
for(int i=0;i<n;i++){
string op;
cin>>op;
if(op[0]=='P') s.push(ID(Set()));
else if(op[0]=='D') s.push(s.top());
else{
Set x1=Setcache[s.top()];s.pop();
Set x2=Setcache[s.top()];s.pop();
Set x;
if(op[0]=='U'); //set_union(ALL(x1),ALL(x2),INS(x));
if(op[0]=='I'); //set_intersection(ALL(x1),ALL(x2),INS(x));
if(op[0]=='A') {x=x2;x.insert(ID(x1));}
s.push(ID(x));
}
cout<<Setcache[s.top()].size()<<endl;
}
return 0;
}