求助S T3
查看原帖
求助S T3
1074188
Secret_Ingredient楼主2023/10/22 08:54

rt,考场上心态爆炸一通乱写,想冲65pts但是锣鼓保龄。

求问下面代码为什么会挂

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second

typedef pair<string, string> pss;

struct node {
	int l, r;
	string name;
	node(int ll = 0, int rr = 0, string s = "") {
		l = ll, r = rr, name = s;
	}
	bool operator <(const node &x) const {
		return l < x.l;
	}
}; set<node> s;

struct str {
	int mx;
	vector<pss> var;
}; map<string, str> t;

int n, sz = -1;
map<string, int> mp, pos;

void insert(string tp, string pre) {
	if(mp[tp]) {
		node a;
		a.l = sz + 1, a.r = sz + mp[tp];
		a.name = pre;
		s.insert(a);
		sz += mp[tp];
		pos[a.name] = a.l;
		return ;
	}
	str x = t[tp];
	for(auto p: x.var) {
		node a; 
		a.l = sz + 1, a.r = sz + mp[p.se];
		a.name = pre + '.' + p.fi;
		s.insert(a);
		pos[a.name] = a.l;
		sz += x.mx;
	}
}

signed main() {
	//freopen("struct.in", "r", stdin);
	//freopen("struct.out", "w", stdout);
	cin >> n;
	mp["byte"] = 1;
	mp["short"] = 2;
	mp["int"] = 4;
	mp["long"] = 8;
	while(n --) {
		int opt; cin >> opt;
		if(opt == 1) {
			string nm; cin >> nm;
			str tmp;
			int k, mx = 0; cin >> k;
			for(int i = 1; i <= k; ++ i) {
				string s, m; cin >> s >> m;
				tmp.var.push_back({m, s});
				if(mp[s]) mx = max(mx, mp[s]);
				else mx = max(mx, t[s].mx);
			}
			tmp.mx = mx;
			t[nm] = tmp;
		} else if(opt == 2) {
			string a, b; cin >> a >> b;
			insert(a, b);
		} else if(opt == 3) {
			string s; cin >> s;
			cout << pos[s] << endl;
		} else {
			int addr; cin >> addr;
			auto it = s.lower_bound(node(addr));
			if(it != s.end() && it -> l == addr) {
				cout << it -> name << endl;
				continue;
			}
			-- it;
			if(it -> r < addr) puts("ERR");
			else cout << it -> name << endl;
		}
	}
	//for(auto p: s) cout << p.l << ' ' << p.r << ' ' << p.name << endl;
	return 0;
}
2023/10/22 08:54
加载中...