能不能帮忙看看CSPS-T3是不是真的错了
  • 板块学术版
  • 楼主imsaileach
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/10/22 20:06
  • 上次更新2023/11/2 11:49:08
查看原帖
能不能帮忙看看CSPS-T3是不是真的错了
345037
imsaileach楼主2023/10/22 20:06

在洛谷和小图灵上 100,但是云斗上面就全 WA,同学说可能是运行环境或 pbds 的问题(ccf 能使用 pbds)。现在很紧张,大佬们能不能帮忙看看是不是真的错了,或者给组 hack,谢谢。

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
gp_hash_table < string , int > Type_Name, A_Name;
int n, las_pos;
string ls;
char lc;
int cnt_type = 3;
struct Type {
	int k, typ[105], pos[105], len, tb;
	string nameT, namem[105];
	gp_hash_table < string , int > Mem_Name;
	Type (){
		k = 0;
		len = 0;
		tb = 0;
	}
} tp[115];
int cnt_A = 0;
struct A {
	int typ, pos;
	string nameA;
} a[115];
void Write (string &Ans, int u, int ps){
	if (ps >= tp[u].len){
		Ans = "ERR";
		return ;
	}
	if (u < 4)
		return ;
	int L = 0, R = tp[u].k, mid;
	while (L < R){
		mid = (L + R) >> 1;
		if (tp[u].pos[mid] <= ps)
			L = mid + 1;
		else
			R = mid;
	}
	-- L;
	Ans += '.';
	Ans += tp[u].namem[L];
	Write (Ans, tp[u].typ[L], ps - tp[u].pos[L]);
}
signed main (){
	tp[0].nameT = "byte";
	tp[0].len = tp[0].tb = 1;
	tp[1].nameT = "short";
	tp[1].len = tp[1].tb = 2;
	tp[2].nameT = "int";
	tp[2].len = tp[2].tb = 4;
	tp[3].nameT = "long";
	tp[3].len = tp[3].tb = 8;
	Type_Name["byte"] = 0;
	Type_Name["short"] = 1;
	Type_Name["int"] = 2;
	Type_Name["long"] = 3;
	cin >> n;
	while (n --){
		int opt;
		cin >> opt;
		if (opt == 1){
			++ cnt_type;
			int u = cnt_type;
			cin >> tp[u].nameT >> tp[u].k;
			Type_Name[tp[u].nameT] = u;
			for (int i = 0;i < tp[u].k;++ i){
				cin >> ls >> tp[u].namem[i];
				tp[u].typ[i] = Type_Name[ls];
				tp[u].Mem_Name[tp[u].namem[i]] = i;
				tp[u].tb = max (tp[u].tb, tp[tp[u].typ[i]].tb);
			}
			tp[u].pos[0] = 0;
			tp[u].len = tp[tp[u].typ[0]].len;
			for (int i = 1;i < tp[u].k;++ i){
				int len = tp[tp[u].typ[i - 1]].len, tb = tp[tp[u].typ[i]].tb;
				tp[u].pos[i] = ((tp[u].pos[i - 1] + len - 1) / tb + 1) * tb;
				tp[u].len = tp[u].pos[i] + tp[tp[u].typ[i]].len;
			}
			tp[u].len = tp[u].len + tp[u].tb - 1;
			tp[u].len = tp[u].len / tp[u].tb * tp[u].tb;
			cout << tp[u].len << " " << tp[u].tb << "\n";
		} else
		if (opt == 2){
			++ cnt_A;
			int u = cnt_A;
			cin >> ls >> a[u].nameA;
			A_Name[a[u].nameA] = u;
			a[u].typ = Type_Name[ls];
			int Tp = a[u].typ;
			a[u].pos = ((las_pos + tp[Tp].tb - 1) / tp[Tp].tb) * tp[Tp].tb;
			las_pos = a[u].pos + tp[Tp].len;
			cout << a[u].pos << "\n";
		} else
		if (opt == 3){
			ls = "";
			lc = getchar ();
			lc = '.';
			int u = - 1, ps = 0;
			while (lc != '\n' && lc != ' '){
				lc = getchar ();
				if (lc == '.' || lc == '\n' || lc == ' '){
					if (u == - 1){
						u = a[A_Name[ls]].typ;
						ps = a[A_Name[ls]].pos;
					}
					else {
						int v = tp[u].Mem_Name[ls];
						ps += tp[u].pos[v];
						u = tp[u].typ[v];
					}
					ls = "";
				} else
					ls += lc;
			}
			cout << ps << "\n";
		} else
		if (opt == 4){
			int ps;
			string Ans;
			cin >> ps;
			int L = 1, R = cnt_A + 1, mid;
			while (L < R){
				mid = (L + R) >> 1;
				if (a[mid].pos <= ps)
					L = mid + 1;
				else
					R = mid;
			}
			-- L;
			Ans = a[L].nameA;
			if (ps >= a[L].pos + tp[a[L].typ].len || cnt_A == 0)
				Ans = "ERR";
			else
				Write (Ans, a[L].typ, ps - a[L].pos);
			cout << Ans << "\n";
		}
	}
	return 0;
}
2023/10/22 20:06
加载中...