在stack里套set,然后每次根据他的操作,在set里操作,把括号hash,插入,输出set的size-1
#include<iostream>
#include<set>
#include<cstdio>
#include<stack>
#define ll long long
#define st set<ll>
using namespace std;
stack<st>s;
ll T,n,tot;
char S[];
int main()
{
cin>>T;
while(T--)
{
cin>>n;
while(!s.empty())s.pop();
for(int i=;i<=n;i++)
{
scanf("%s",S);
if(S[]=='P')
{
st x;x.clear();
x.insert();
s.push(x);
printf("%d\n",);
}
if(S[]=='D')
{
st a;a.clear();
a=s.top();
ll temp=a.size()-;
s.push(a);
printf("%d\n",temp);
}
if(S[]=='U')
{
st a=s.top();s.pop();
st b=s.top();s.pop();
for(st::iterator it=a.begin();it!=a.end();it++)
b.insert(*it);
s.push(b);
printf("%d\n",b.size()-);
}
if(S[]=='I')
{
st a=s.top();s.pop();
st b=s.top();s.pop();
st c;c.clear();
for(st::iterator it=a.begin();it!=a.end();it++)
if(b.count(*it))c.insert(*it);
s.push(c);
printf("%d\n",c.size()-);
}
if(S[]=='A')
{
st a=s.top();s.pop();
st b=s.top();s.pop();
st c;c.clear();
ll sum=;
for(st::iterator it=a.begin();it!=a.end();it++)
{sum*=;sum+=*it;}
sum*=;
b.insert(sum);
s.push(b);
printf("%d\n",b.size()-);
}
}
printf("***\n");
}
return ;
}