CSP-S T3 求助
  • 板块学术版
  • 楼主small_john
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/10/22 11:46
  • 上次更新2023/11/2 11:57:21
查看原帖
CSP-S T3 求助
581316
small_john楼主2023/10/22 11:46

RT,打的 65pts 的档,实则 0pts,思路就是大模拟。

#include<bits/stdc++.h>
#define int long long
using namespace std;
map<string,int> mp,id1,id2,sz;
map<string,string> kind;
void init()
{
	mp["byte"] = 1;
	mp["short"] = 2;
	mp["int"] = 4;
	mp["long"] = 8;
	sz["byte"] = 1;
	sz["short"] = 2;
	sz["int"] = 4;
	sz["long"] = 8;
}
const int N = 105;
int n,cnt,st[N],en[N],len[N],tot;
string typ[N][N],s[N][N],kkk[N];
bool ok(string op)
{
	return op=="byte"||op=="short"||op=="int"||op=="long";
}
int get(int x,int y)//大于等于 x 的最小的 y 的倍数
{
	return (x+y-1)/y*y;
}
signed main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	init();
	cin>>n;
	en[0] = -1;
	for(int _ = 1;_<=n;_++)
	{
		int op;
		cin>>op;
		if(op==1)
		{
			string name;
			cin>>name>>len[++cnt];
			id1[name] = cnt;
			int mx = 0,las = -1;
			for(int i = 1;i<=len[cnt];i++)
				cin>>typ[cnt][i]>>s[cnt][i],mx = max(mx,mp[typ[cnt][i]]),las = get(las+1,mp[typ[cnt][i]])+mp[typ[cnt][i]]-1;
			mp[name] = mx,sz[name] = get(las,mx);
		}
		else if(op==2)
		{
			string ty,name;
			cin>>ty>>name;
			tot++;
			kind[name] = ty,id2[name] = tot,kkk[tot] = ty;
			st[tot] = get(en[tot-1]+1,mp[ty]),en[tot] = st[tot]+sz[ty]-1;
		}
		else if(op==3)
		{
			string ss;
			cin>>ss;
			if(kind[ss]!="") cout<<st[id2[ss]]<<'\n';
			else
			{
				string name = "",to = "";
				int tt = 0;
				while(ss[tt]!='.'&&tt<ss.size()) name+=ss[tt],tt++;
				tt++;
				while(tt<ss.size()) to+=ss[tt],tt++;
				int id = id1[kind[name]],now = st[id2[name]]-1;
				for(int i = 1;i<=len[id];i++)
				{
					if(s[id][i]==to)
					{
						cout<<get(now+1,mp[typ[id][i]])<<'\n';
						break;
					}
					now = get(now+1,mp[typ[id][i]])+mp[typ[id][i]]-1;
				}
			}
		}
		else if(op==4)
		{
			int wz;
			cin>>wz;
			int id = lower_bound(st+1,st+tot+1,wz)-st-1;
			if(id>tot||id<1)
			{
				cout<<"ERR\n";
				continue;
			}
			if(ok(kkk[id]))
			{
				if(en[id]<wz) cout<<"ERR\n";
				else cout<<st[id]<<'\n';
			}
			else
			{
				bool flag = 0;
				string name = kkk[id];
				int now = st[id]-1,be,la;
				id = id1[name];
				for(int i = 1;i<=len[id];i++)
				{
					be = get(now+1,mp[typ[id][i]]),la = be+mp[typ[id][i]]-1;
					if(be<=wz&&la>=wz)
					{
						cout<<be<<'\n';
						flag = 1;
						break;
					}
					now = la;
				}
				if(!flag) cout<<"ERR\n";
			}
		}
	}
	return 0;
}
2023/10/22 11:46
加载中...