S T3 95pts wa on #17 求调
  • 板块学术版
  • 楼主gty271828
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/25 22:58
  • 上次更新2023/11/2 11:23:30
查看原帖
S T3 95pts wa on #17 求调
1064609
gty271828楼主2023/10/25 22:58

萌新袜子刚学 CSP-S 求助 QAQ

#include <bits/stdc++.h>

#define F(i, a, b) for(int i = a; i <= (b); ++i)
#define dF(i, a, b) for(int i = a; i >= (b); --i)

using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int N = 105;

LL f(LL x, LL p) { return p * (x / p + (x % p > 0)); }
bool find(string x, string &y) {
	int xlen = x.size(), ylen = y.size();
	if (xlen > ylen) return 0;
	F(i, 0, xlen - 1)
		if (x[i] != y[i]) return 0;
	if (xlen == ylen) { y.erase(0, xlen); return 1; }
	if (y[xlen] == '.') { y.erase(0, xlen + 1); return 1; }
	return 0;
}

map<string, int> id;
int cnt;
struct type {
	int k, t[N];
	string n[N];
	LL a, s, o[N];
} t[N];
void Init() {
	id["byte"] = 1, t[1].a = t[1].s = 1;
	id["short"] = 2, t[2].a = t[2].s = 2;
	id["int"] = 3, t[3].a = t[3].s = 4;
	id["long"] = 4, t[4].a = t[4].s = 8;
	cnt = 4;
	return ;
}
void Newtype() {
	int u = ++cnt;
	string str;
	cin >> str >> t[u].k;
	id[str] = u;
	F(i, 1, t[u].k)
		cin >> str >> t[u].n[i],
		t[u].t[i] = id[str],
		t[u].a = max(t[u].a, t[t[u].t[i]].a);
	t[u].o[1] = 0;
	F(i, 2, t[u].k) t[u].o[i] = f(t[u].o[i - 1] + t[t[u].t[i - 1]].s, t[t[u].t[i]].a);
	t[u].s = f(t[u].o[t[u].k] + t[t[u].t[t[u].k]].s, t[u].a);
	cout << t[u].s << " " << t[u].a << "\n";
	return ;
}

int tot;
struct node {
	int tp;
	string name;
	LL b;
} s[N];
void Newnode() {
	int u = ++tot;
	string str;
	cin >> str >> s[u].name;
	s[u].tp = id[str];
	if (u != 1) s[u].b = f(s[u - 1].b + t[s[u - 1].tp].s, t[s[u].tp].a);
	cout << s[u].b << "\n";
	return ;
}

LL Query(int u, string str) {
	F(i, 1, t[u].k)
		if (find(t[u].n[i], str))
			return t[u].o[i] + Query(t[u].t[i], str);
	return 0;
}
void Query() {
	LL res;
	string str;
	cin >> str;
	F(i, 1, tot)
		if (find(s[i].name, str))
			res =  s[i].b + Query(s[i].tp, str);
	cout << res << "\n";
	return ;
}

string Search(int u, LL addr) {
	F(i, 1, t[u].k)
		if (t[u].o[i] <= addr && addr < t[u].o[i] + t[t[u].t[i]].s)
			if (!t[t[u].t[i]].k) return t[u].n[i];
			else {
				string res = Search(t[u].t[i], addr - t[u].o[i]);
				if (res == "ERR") return res;
				else return t[u].n[i] + "." + res;
			}
	return "ERR";
}
void Search() {
	string res = "ERR";
	LL addr;
	cin >> addr;
	F(i, 1, tot)
		if (s[i].b <= addr && addr < s[i].b + t[s[i].tp].s)
			if (!t[s[i].tp].k) res = s[i].name;
			else {
				string str = Search(s[i].tp, addr - s[i].b);
				if (str != "ERR") res = s[i].name + "." + str;
			}
	cout << res << "\n";
	return ;
}

int _;

int main() {
	freopen("struct.in", "r", stdin);
	freopen("struct.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	Init();
	cin >> _;
	while (_--) {
		int op;
		cin >> op;
		if (op == 1) Newtype();
		else if (op == 2) Newnode();
		else if (op == 3) Query();
		else Search();
	}
	return 0;
}
2023/10/25 22:58
加载中...