35pts 求条
查看原帖
35pts 求条
730195
Little_Cabbage楼主2024/7/28 20:03
#include <bits/stdc++.h>
#define int long long
#define ll __int128
#define db double
#define ldb long double
#define vo void
#define endl '\n'
#define il inline
#define re register
#define ve vector
#define p_q priority_queue
#define PII pair<int, int>
#define u_m unordered_map
using namespace std;

//#define O2 1
#ifdef O2
	#pragma GCC optimize(1)
	#pragma GCC optimize(2)
	#pragma GCC optimize(3, "Ofast", "inline")
#endif

namespace OI {
	template <typename T>
	il T read() {
		T x = 0, f = 1;
		int ch = getchar();
		while (!isdigit(ch)) {
			if (ch == '-') f = -1;
			ch = getchar();
		}
		while (isdigit(ch)) {
			x = (x << 3) + (x << 1) + (ch ^ 48);
			ch = getchar();
		}
		return x * f;
	}
	template <typename TE>
	il void write(TE x) {
		if (x < 0) {
			x = -x;
			putchar('-');
		}
		TE sta[35];
		int top = 0;
		do {
			sta[top++] = x % 10, x /= 10;
		} while (x);
		while (top) putchar(sta[--top] + '0');
	}
	il string read_with_string() {
		string s = "";
		char ch = getchar();
		while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')) {
			s += ch;
			ch = getchar();
		}
		return s;
	}
	il void write_with_string(string s) {
		for (int i = 0; i < s.size(); i ++ ) putchar(s[i]);
	}
}
namespace COMB {
	int fact[200000];
	int Triangle[1010][1010];
	void Fact(int n, int mod) {
		fact[0] = 1;
		for (int i = 1; i <= n; i ++ ) fact[i] = ((fact[i - 1]) % mod * (i % mod)) % mod;
	}
	void Pascal_s_triangle(int n, int mod) {
		for (int i = 0; i <= n; i ++ ) Triangle[i][0] = 1;
		for (int i = 1; i <= n; i ++ )
			for (int j = 1; j <= i; j ++ )
				Triangle[i][j] = (Triangle[i - 1][j] + Triangle[i - 1][j - 1]) % mod;
	}
	int pw(int x, int y, int mod) {
		int res = 1;
		while (y) {
			if (y & 1) res = ((res % mod) * (x % mod)) % mod;
			x = (x % mod) * (x % mod) % mod;
			y >>= 1;
		}
		return res;
	}
	int pw(int x, int y) {
		int res = 1;
		while (y) {
			if (y & 1) res *= x;
			x *= x;
			y >>= 1;
		}
		return res;
	}
	int GCD(int x, int y, int mod) {
		return __gcd(x, y) % mod;
	}
	int LCM(int x, int y, int mod) {
		return (((x % mod) * (y % mod)) % mod / (GCD(x, y, mod) % mod)) % mod;
	}
	int C(int n, int m, int mod) {
		if (m > n || m < 0) return 0;
		return fact[n] * pw(fact[m], mod - 2, mod) % mod * pw(fact[n - m], mod - 2, mod) % mod;
	}
	int Ask_triangle(int x, int y) {
		return Triangle[x][y];
	}
}
using namespace OI;
using namespace COMB;

//#define fre 1
#define IOS 1
//#define multitest 1

const int N = 2e5 + 10;
const int M = 4e5 + 10;
const int inf = 1e12;

#define PSS pair<string, string>
#define id kjrgtjghfjk

int n;//操作数量

ve<PSS> str[N];//结构体的类型和名称
string Name[N];//结构体的编号
map<string, int> Id;//编号对应的结构体
int cnt;//结构体的数量
int len[N];//结构体的成员数量
int dq[N];//结构体的对齐大小
map<int, int> dz;//地址占用
map<string, int> I;//类型的占据的空间
int now;//当前空间起始地址
map<string, int> qs;//元素起始地址
map<int, string> zy;//占用地址的元素
int a[N], b[N], s[N];
int ccnt;//定义元素个数
int sz[N];

il void Init() {
	I["byte"] = 1;
	I["short"] = 2;
	I["int"] = 4;
	I["long"] = 8;
	cin >> n;
}

il bool ok(string s) {
	if (s == "byte") return true;
	if (s == "short") return true;
	if (s == "int") return true;
	if (s == "long") return true;
	return false;
}

il void dfs(string lx, string name, string from, string nname) {
//lx:   当前类型名字
//name: 定义变量的名字
//from: 上一个结构体
	if (!ok(lx)) {
		int id = Id[lx];
		for (int i = 0; i < str[id].size(); i ++ ) {
			string next_name = str[id][i].first;
			dfs(next_name, name, lx, nname + "." + str[id][i].second);
			if (i == 0) {
				qs[nname] = b[ccnt];
			}
		}
	} else {
		ccnt++;
		int id = Id[from];
		int DQ = dq[id];
		s[ccnt] = I[lx];
		a[ccnt] = DQ;
		if (ccnt == 1) b[1] = 0;
		else
			for (int i = 1; i; i ++ )
				if (i % a[ccnt] == 0 && b[ccnt - 1] + s[ccnt - 1] <= i) {
					b[ccnt] = i;
					break;
				}
//		cout << nname << "    %%%%%\n";
		qs[nname] = b[ccnt];
//		cout << nname << " " << now << "      &&&&\n";
		for (int i = b[ccnt]; i <= b[ccnt] + I[lx] - 1; i ++ ) dz[i] = 1, zy[i] = nname;
		now = b[ccnt] + I[lx];
//		if (nname == "zeewv.uvq") {
//			cout << b[ccnt] << "        %%%%\n";
//		}
	}
}

il void Solve() {
	while (n -- ) {
		int op;
		cin >> op;
		if (op == 1) {
			string struct_name;//结构体名字
			int struct_num;//结构体成员数量
			cin >> struct_name >> struct_num;
			Name[++cnt] = struct_name;//保存结构体的名字
			len[cnt] = struct_num;
			Id[struct_name] = cnt;
			int x1 = 0, x2 = 0;
			for (int i = 1; i <= struct_num; i ++ ) {
				string lx, name;
				cin >> lx >> name;
				str[cnt].push_back(make_pair(lx, name));//保存结构体成员的类型和名字
				if (ok(lx)) dq[cnt] = max(dq[cnt], I[lx]);//求结构体的对齐大小
				else dq[cnt] = max(dq[cnt], dq[Id[lx]]);
				if (ok(lx)) {
					sz[cnt] += I[lx];
//					cout << sz[cnt] << " " << I[lx] << "     ##\n";
					if (lx == "short") x2++;
					else x1++;
				} else {
					sz[cnt] += sz[Id[lx]];
//					cout << sz[Id[lx]] << "      %%%\n";
				}
				if (ok(lx)) {
					if (sz[cnt] % I[lx]) sz[cnt] = (sz[cnt] / I[lx] + 1) * I[lx];
				} else {
					if (sz[cnt] % dq[Id[lx]]) sz[cnt] = (sz[cnt] / dq[Id[lx]] + 1) * dq[Id[lx]];
				}
			}
//			cout << x1 << " " << x2 << "      $$$\n";
			cout << sz[cnt] << " " << dq[cnt] << endl;
		} else if (op == 2) {
			string lx, name;
			cin >> lx >> name;
			if (!ok(lx)) {
				cout << now << endl;
				dfs(lx, name, "", name);
			} else {
				ccnt++;
				int DQ = I[lx];
				string nname = name;
				s[ccnt] = I[lx];
				a[ccnt] = DQ;
				if (ccnt == 1) b[ccnt] = 0;
				else
					for (int i = 1; i; i ++ )
						if (i % a[ccnt] == 0 && b[ccnt - 1] + s[ccnt - 1] <= i) {
							b[ccnt] = i;
							break;
						}
				qs[nname] = b[ccnt];
				for (int i = b[ccnt]; i <= b[ccnt] + I[lx] - 1; i ++ ) dz[i] = 1, zy[i] = nname;
				now = b[ccnt] + I[lx];
				cout << b[ccnt] << endl;
			}
		} else if (op == 3) {
			string s;
			cin >> s;
			cout << qs[s] << endl;
		} else {
			int addr;
			cin >> addr;
			if (dz[addr]) cout << zy[addr] << endl;
			else cout << "ERR\n";
		}
	}
}

signed main() {
	int T;
#ifdef IOS
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
#ifdef fre
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif
#ifdef multitest
	cin >> T;
#else
	T = 1;
#endif
	while (T--) {
		Init();
		Solve();
	}
	return 0;
}
/*
  35
  1 lfqikjtpgg 97
  long mbtn
  long snpj
  long fqb
  long vdnkbv
  long zqqjxhrj
  long upp
  long oe
  long lv
  long sea
  long a
  long fdymaqnuy
  long oyshjkhm
  long secuap
  long o
  long uvq
  long xpw
  long fsytmbpaaw
  long rx
  long nhmski
  long hzop
  long noy
  long mqbitjlx
  long jewquyks
  long auntk
  long ak
  long bsksgoi
  long rmnpgq
  long vmovdiaem
  long eje
  long kmk
  long hp
  long ylyvoqict
  long seliaqt
  long kvlmtwx
  long efdtza
  long ejxnirywfi
  long djvqtmuohb
  long qiuxy
  long til
  long qzotxqv
  long sobbeh
  long kt
  long ahmlev
  long qhranpw
  long riw
  long plpsvguc
  long vzu
  long dkfwbnujc
  long kmemytbbgy
  long dkaizimtl
  long vuheusgva
  long tjoxtez
  long caxso
  long ugccm
  long ygbv
  long xtpqnp
  long qnnxrpqz
  long bgiupvhv
  long ue
  long sqypvs
  long lzke
  long tqye
  long typoz
  long drybikqbr
  long gxcb
  long krpxcirus
  long bsln
  long cdhs
  long oouvqrl
  long nfv
  long cyoj
  long eqppttop
  long uekcrgeikt
  long btyfwt
  long vfhi
  long mvozkegq
  long jxdqwxknb
  long hfanynrlcx
  long zrn
  long vzy
  long lqyfurmsv
  long sydijjk
  long kwrgaxvkyp
  long t
  long myyzqzhbm
  long tmdxmvej
  long abeqpdi
  long qwcob
  long sft
  long khj
  long ccxetwav
  long stc
  long d
  long lk
  long knnjye
  long hvf
  long qlwwz
  2 lfqikjtpgg jrrer
  3 jrrer.jxdqwxknb
  4 24
  3 jrrer
  3 jrrer.vzu
  4 315
  3 jrrer.hfanynrlcx
  2 lfqikjtpgg zeewv
  4 794
  4 932
  3 jrrer.dkfwbnujc
  4 644
  3 zeewv.lzke
  2 long ccdikhjhbu
  2 lfqikjtpgg rrb
  2 lfqikjtpgg a
  4 132
  4 598
  2 lfqikjtpgg yqqjqq
  4 4079
  2 long rwaubd
  4 4020
  2 long qpgj
  3 jrrer.uvq
  2 lfqikjtpgg uwarglwn
  4 2847
  2 long wtholnocr
  4 1798
  4 4970
  4 109
  4 4063
  3 wtholnocr
  3 rrb
  3 zeewv.uvq
 */
//----沃兹基·鞑德
2024/7/28 20:03
加载中...