S组T3 25部分分求调
  • 板块学术版
  • 楼主expnoi
  • 当前回复1
  • 已保存回复1
  • 发布时间2023/10/22 08:17
  • 上次更新2023/11/2 12:02:20
查看原帖
S组T3 25部分分求调
378346
expnoi楼主2023/10/22 08:17
#include<bits/stdc++.h>
#define int long long//ji de gai hui qu
using namespace std;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')w=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		s=(s<<3)+(s<<1)+(ch^48);
		ch=getchar();
	}
	return s*w;
}
inline void print(int x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>=10)print(x/10);
	putchar(x%10+48);
}
//da mo ni ti,zi xi yi xie,duo zhu yi xi jie.
//kao lv xu yao shen me
int wei=0,T,op;
map<string,int> mp;//node string's duiqiyaoqiu is mp 
map<string,int> dx;//dx is the da xiao of the string
//map<pair<string,string>,int> id;
struct edge
{
	string first,second;
	int st;
};
map<string,vector<edge> > ys;//the chengyuan in node s
string s,ti,ni,t,n,st[15];
int sum;
int k,tot;
map<string,int> id,ID;
map<string,string> pp;
inline void work(int dep,string nd)
{
	if(dep==tot+1)return;
	int len=0;
	string to="";
	cout<<dep<<' '<<nd<<"\n";
	if(dep==1)
	{
		len=id[st[dep]];
	}
	else
	{
		for(int i=0;i<(int)ys[nd].size();i++)
		{
			auto now=ys[st[dep-1]][i];
			if(now.second==st[dep])
			{
				to=now.first;
				len=now.st;
			}
		}
	}
	work(dep+1,to);
	sum+=len;
}
//inline void work()
//{
//	sum+=now;
//	for(int i=1;i<=tot;i++)
//	
inline __int128 gcd(__int128 a,__int128 b)
{
	return !b?a:gcd(b,a%b);
}
inline __int128 lcm(__int128 a,__int128 b)
{
	return a*b/gcd(a,b);
}
signed main()
{
	T=read();
	mp["byte"]=dx["byte"]=1;
	mp["short"]=dx["short"]=2;
	mp["int"]=dx["int"]=4;
	mp["long"]=dx["long"]=8;
	for(int _=1;_<=T;_++)
	{
		op=read();
		if(op==1)//dingyiyigejiegouti,
		{
			cin>>s;
			k=read();//t ge cheng yuan
			//yi ge ji gou ti de da xiao shi dui qi yao qiu de zui xiao bei shu,er qie man zu zhe ge shu da yu 
			int duiqi=1,daxiao=0;
			int kk=0;
			for(int i=1;i<=k;i++)
			{
				cin>>ti>>ni;//ti leixing ni mingcheng
				//yihou zai xie ni chu li
				int tt=(daxiao+mp[ti]-1)/mp[ti]*mp[ti];
				ys[s].push_back({ti,ni,tt});
				kk=tt;
				daxiao=kk+dx[ti];
				if(k==1)duiqi=mp[ti];
				else duiqi=lcm(duiqi,mp[ti]);
			}
			// t*duiqi>=daxiao
			// t>=ceil(daxiao/duiqi)
			// t=(daxiao+duiqi-1)/duiqi
			int tt=(daxiao+duiqi-1)/duiqi*duiqi;
			daxiao=tt;
			print(daxiao);
			putchar(' ');
			print(duiqi);
			puts("");
			mp[s]=duiqi;
			dx[s]=daxiao;
		}
		if(op==2)//ding yi yuan su
		{
			cin>>t>>n;//leixing mingcheng
			//kai pi yi ge kong jian
			int duiqi=mp[t];
			int tt=(wei+duiqi-1)/duiqi*duiqi;
			int l=tt,r=tt+dx[t]-1;
			id[n]=l;//yuansu n qishi l
			ID[n]=r;
			wei=r+1;
			print(l);
			pp[n]=t;
			puts("");
		}
//		if(op==3)
//		{
//			cin>>s;
//			int len=s.size();
//			s=" "+s;
//			string str="";
//			tot=0;
//			for(int i=1;i<=len;i++)
//			{
//				if(s[i]=='.')
//				{
//					st[++tot]=str;
//					str="";
//				}
//				else str+=s[i];
//			}
//			st[++tot]=str;
//			for(int i=1;i<=tot;i++)
//			{
//				cout<<st[i]<<' ';
//			}
//			puts("");
//			sum=0;work(1,pp[st[1]]);
//			print(sum);
//			puts("");
//		}
	}            
	return 0;
}
2023/10/22 08:17
加载中...