rt,真的哭死,65→5,有没有善良的大佬帮我调调…………
// A + B + C = 65pts
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int n=0,f=1;
char c=getchar();
while(!isdigit(c))
{
if(c=='-') f=-1;
c=getchar();
}
while(isdigit(c)) n=(n<<3)+(n<<1)+(c^48),c=getchar();
return n*f;
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10^48);
return;
}
struct node
{
bool err,sim;
string up;
string name;
};
struct st
{
int size,per;
vector<string>type,name;
};
map<string,st>in;
map<string,int>size;
vector<node>ad;
inline void work()
{
size["byte"]=1;
size["short"]=2;
size["int"]=4;
size["long"]=8;
}
signed main()
{
work();
freopen("struct.in","r",stdin);
freopen("struct.out","w",stdout);
int T=read();
while(T--)
{
int op=read();
if(op==1)
{
st res;
string name;
int maxn=0;
cin>>name;
int k=read();
while(k--)
{
string type,name;
cin>>type>>name;
if(!size[type]) return 0;
res.name.push_back(name);
res.type.push_back(type);
maxn=max(maxn,size[type]);
}
res.per=maxn;
res.size=maxn*res.type.size();
write(res.size),putchar(' '),write(res.per);
in[name]=res;
}
if(op==2)
{
string name,type;
cin>>type>>name;
write(ad.size());
if(size[type])
{
node t;
t.name=name;
t.sim=1;
t.err=0;
for(int i=1;i<=size[type];i++) ad.push_back(t);
}
else
{
st res=in[type];
for(int i=1;i<=res.size/res.per;i++)
{
for(int j=1;j<=res.per;j++)
{
node t;
if(j<=size[res.type[i-1]])
{
t.err=0;
t.sim=0;
t.name=res.name[i-1];
t.up=name;
ad.push_back(t);
}
else
{
t.err=1;
t.sim=0;
ad.push_back(t);
}
}
}
}
}
if(op==3)
{
string s;
cin>>s;
int f=0;
for(int i=0;i<s.size();i++) if(s[i]=='.') f=i+1;
if(!f)
{
for(int i=0;i<ad.size();i++) if(!ad[i].err&&ad[i].name==s&&ad[i].sim)
{
write(i);
break;
}
}
else
{
f--;
string fa=s.substr(0,f);
s=s.substr(f+1,s.size()-f-1);
for(int i=0;i<ad.size();i++) if(!ad[i].err&&!ad[i].sim&&ad[i].name==s&&ad[i].up==fa)
{
write(i);
break;
}
}
}
if(op==4)
{
int addr=read();
if(addr>=ad.size()){puts("ERR");continue;}
node t=ad[addr];
if(t.err)puts("ERR");
else if(t.sim)cout<<t.name<<endl;
else cout<<t.up<<"."<<t.name<<endl;
continue;
}
puts("");
}
return 0;
}