求助 S 组 T3
  • 板块学术版
  • 楼主linxuanrui
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/10/21 22:07
  • 上次更新2023/11/2 12:06:09
查看原帖
求助 S 组 T3
857323
linxuanrui楼主2023/10/21 22:07

写了 120 行,wssb。

#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const ll N = 105;
ll n,opt,node_cnt,now,yuansu_cnt,addr;
unordered_map<string,ll> m,m1;
string target;
struct node{
	string s;
	ll k,num,st[N],en[N],use_zijie;
	string name[N],type[N];
}a[N];
struct yuansu{
	string type,name;
	ll st,en;
}b[N];
ll get(string type,bool xuanze){
	if(type == "byte")return 1;
	else if(type == "short")return 2;
	else if(type == "int")return 4;
	else if(type == "long")return 8;
	else return (xuanze == 0 ? a[m[type]].num : a[m[type]].use_zijie);
}
ll nxt(ll num,ll k){
	return ((num + k - 1) / k * k);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	freopen("struct.in","r",stdin);
	freopen("struct.out","w",stdout);
	cin >> n;
	while(n--){
		cin >> opt;
		if(opt == 1){
			node_cnt++;
			cin >> a[node_cnt].s >> a[node_cnt].k;
			a[node_cnt].num = 0;
			m[a[node_cnt].s] = node_cnt;
			for(ll i = 1;i <= a[node_cnt].k;i++){
				cin >> a[node_cnt].type[i] >> a[node_cnt].name[i];
				a[node_cnt].num = max(a[node_cnt].num,get(a[node_cnt].type[i],0));
				if(i == 1)a[node_cnt].st[1] = 0;
				else a[node_cnt].st[i] = nxt(a[node_cnt].en[i - 1] + 1,get(a[node_cnt].type[i],0));
				a[node_cnt].en[i] = a[node_cnt].st[i] + get(a[node_cnt].type[i],1) - 1;
			}
			a[node_cnt].use_zijie = nxt(a[node_cnt].en[a[node_cnt].k],a[node_cnt].num);
			cout << a[node_cnt].use_zijie << " " << a[node_cnt].num << endl;
		}else if(opt == 2){
			yuansu_cnt++;
			cin >> b[yuansu_cnt].type >> b[yuansu_cnt].name;
			m1[b[yuansu_cnt].name] = yuansu_cnt;
			if(yuansu_cnt == 1)b[yuansu_cnt].st = 0;
			else b[yuansu_cnt].st = nxt(now + 1,get(b[yuansu_cnt].type,0));
			b[yuansu_cnt].en = b[yuansu_cnt].st + get(b[yuansu_cnt].type,1) - 1;
			now = b[yuansu_cnt].en;
			cout << b[yuansu_cnt].st << endl;
		}else if(opt == 3){
			cin >> target;
			target += ".";
			ll last = 0,ans = 0;
			string type = "";
			while(target.find(".",last) != target.npos){
				ll pos = target.find(".",last) - 1;
				string name = target.substr(last,pos - last + 1);
				if(type == "")type = b[m1[name]].type,ans = b[m1[name]].st;
				else{
					ll bianhao = m[type];
					if(bianhao == 0)break;
					for(ll i = 1;i <= a[bianhao].k;i++){
						if(a[bianhao].name[i] == name){
							ans += a[bianhao].st[i];
							type = a[bianhao].type[i];
							break;
						}
					}
				}
				last = pos + 2;
			}
			cout << ans << endl;
		}else{
			cin >> addr;
			string ans = "";
			ll pos = -1;
			for(ll i = 1;i <= yuansu_cnt;i++){
				if(b[i].st <= addr && addr <= b[i].en){
					pos = i;
					break;
				}
			}
			if(pos == -1)cout << "ERR\n";
			else{
				ans += b[pos].name;
				bool flag = true;
				string type = b[pos].type;
				while(m[type]){
					ll bianhao = m[type];
					pos = -1;
					for(ll i = 1;i <= a[bianhao].k;i++){
						if(a[bianhao].st[i] <= addr && addr <= a[bianhao].en[i]){
							addr -= a[bianhao].st[i];
							pos = i;
							ans += "." + a[bianhao].name[i];
							type = a[bianhao].type[i];
							break;
						}
					}
					if(pos == -1){
						cout << "ERR\n";
						flag = false;
						break;
					}
				}
				if(flag)cout << ans << endl;
			}
		}
	}
}
2023/10/21 22:07
加载中...