WA #2 #3 #7
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
using namespace std;
struct node{
int k;
long long siz,tot,st[105];
string t[105],N[105];
};
map<string,node>st;
int n,op,cnt,cn;
long long St[105],now,ans,ad;
string s,t,N,tp[105],nm[105],rd[105];
void search(string typ,int d){
if(d==cn) return;
for(int i=1;i<=st[typ].k;i++)
if(st[typ].N[i]==rd[d+1]){
ans+=st[typ].st[i];
search(st[typ].t[i],d+1);
return;
}
}
void search2(string typ,long long now){
if(typ=="byte"||typ=="short"||typ=="int"||typ=="long"){
if(now+st[typ].tot-1<ad) printf("ERR");
else{
cout<<rd[1];
for(int i=2;i<=cn;i++) cout<<'.'<<rd[i];
}
putchar('\n');
return;
}
for(int i=1;i<=st[typ].k;i++)
if(now+st[typ].st[i]<=ad&&ad<now+st[typ].st[i+1]){
rd[++cn]=st[typ].N[i];
search2(st[typ].t[i],now+st[typ].st[i]);
return;
}
}
int main(){
scanf("%d",&n);
st["byte"].tot=st["byte"].siz=1;
st["short"].tot=st["short"].siz=2;
st["int"].tot=st["int"].siz=4;
st["long"].tot=st["long"].siz=8;
while(n--){
scanf("%d",&op);
switch(op){
case 1:{
cin>>s;
cin>>st[s].k;
st[s].siz=0;
for(int i=1;i<=st[s].k;i++){
cin>>st[s].t[i]>>st[s].N[i];
st[s].siz=max(st[s].siz,st[st[s].t[i]].siz);
}
long long rt=0;
for(int i=1;i<=st[s].k;i++){
if(rt%st[st[s].t[i]].siz) rt+=st[st[s].t[i]].siz-rt%st[st[s].t[i]].siz;
st[s].st[i]=rt;
rt+=st[st[s].t[i]].tot;
}
if(rt%st[s].siz) rt+=st[s].siz-rt%st[s].siz;
st[s].st[st[s].k+1]=rt;
st[s].tot=rt;
printf("%lld %lld\n",st[s].tot,st[s].siz);
break;
}
case 2:{
cin>>t>>N;
if(now%st[t].siz) now+=st[t].siz-now%st[t].siz;
St[++cnt]=now;
tp[cnt]=t;
nm[cnt]=N;
printf("%lld\n",now);
now+=st[t].tot;
break;
}
case 3:{
cin>>s;
int p=-1;
cn=0;
for(int i=1;i<s.size();i++)
if(s[i]=='.')
rd[++cn]=s.substr(p+1,i-p-1),p=i;
rd[++cn]=s.substr(p+1,s.size()-p-1);
for(int i=1;i<=cnt;i++)
if(nm[i]==rd[1]){
ans=St[i];
search(tp[i],1);
printf("%lld\n",ans);
}
break;
}
case 4:{
cn=0;
scanf("%lld",&ad);
for(int i=1;i<=cnt;i++)
if(St[i]<=ad&&ad<St[i]+st[tp[i]].tot){
rd[++cn]=nm[i];
search2(tp[i],St[i]);
}
if(ad>=now) printf("ERR\n");
break;
}
}
}
return 0;
}