跳到正文

个人记录

完美开头

luhanyou约 11 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 11 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
namespace lhy
{
#define INT128_MAX ((__int128)1<<127)-1
#define INT128_MIN -(((__int128)1<<127)-1)
#define hash std::unordered_map
#define frw() ios::sync_with_stdio(false);cin.tie();cout.tie()
#define maxl max_element
#define minl min_element
	using ll=long long;
	using lll=__int128;
	using int128=__int128;
	using namespace std;
	inline auto read()
{
	auto x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
		{
			f=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
	inline void write(auto x)
{
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	if(x>9)
	{
		write(x/10);
	}
	putchar(x%10+'0');
}
	struct union_find_set
{
	std::unordered_map<ll,__int128>fa;
	void init(ll s,ll e)
{
	for(long long i=s;i<=e;++i)
	{
		fa[i]=i;
	}
}
	__int128 find(__int128 x)
{
	if(x==fa[x])
	{
		return x;
	}
	else
	{
		fa[x]=find(fa[x]);
		return fa[x];
	}
}
	void merge(__int128 u,__int128 v)
{
	fa[find(u)]=find(v);
}
	bool check(__int128 u,__int128 v)
{
	if(find(u)==find(v))
	{
		return true;
	}
	else
	{
		return false;
	}
}
};
	struct edge
{
	__int128 nxt,to,wei;
};
	__int128 cnt;
	std::unordered_map<long long,edge>e;
	std::unordered_map<long long,__int128>head;
	void add(__int128 x,__int128 y,__int128 w)
{
	e[++cnt].nxt=head[x];
	e[cnt].to=y;
	e[cnt].wei=w;
	head[x]=cnt;
}
	void space()
{
	putchar(' ');
}
	void nxtl()
{
	std::ios::sync_with_stdio(false);
	std::cout.tie();
	std::cout<<std::endl;
}
	struct segmenttree
{
	struct node
{
	__int128 l,r,ls,rs,sum,lazy;
};
	std::unordered_map<long long,node>tree;
	void pushup(__int128 x)
{
	__int128 lson=tree[x].ls,rson=tree[x].rs;
	tree[x].sum=tree[lson].sum+tree[rson].sum;
	tree[x].l=tree[lson].l;
	tree[x].r=tree[rson].r;
}
	void build(__int128 li,__int128 ri,__int128 cur)
{
	if(li==ri)
	{
		tree[cur].ls=tree[cur].rs=tree[cur].lazy=-1;
		tree[cur].l=tree[cur].r=li;
	}
	else
	{
		__int128 mid=(li+ri)/2;
		tree[cur].ls=cnt++;
		tree[cnt].rs=cnt++;
		build(li,mid,tree[cur].ls);
		build(mid+1,ri,tree[cur].rs);
		pushup(cur);
	}
}
	void pushdown(__int128 x)
{
	__int128 lson=tree[x].ls,rson=tree[x].rs;
	tree[lson].sum=tree[x].lazy*(tree[lson].r-tree[lson].l+1);
	tree[rson].sum=tree[x].lazy*(tree[rson].r-tree[rson].l+1);
	tree[lson].lazy=tree[x].lazy;
	tree[rson].lazy=tree[x].lazy;
	tree[x].lazy=-1;
}
	void update(__int128 li,__int128 ri,__int128 c,__int128 cur)
{
	if(li<=tree[cur].l&&tree[cur].r<=ri)
	{
		tree[cur].sum=c*(tree[cur].r-tree[cur].l+1);
		tree[cur].lazy=c;
		return;
	}
	if(tree[cur].lazy!=-1)
	{
		pushdown(cur);
	}
	__int128 mid=(tree[cur].l+tree[cur].r)/2;
	if(li<=mid)
	{
		update(li,ri,c,tree[cur].ls);
	}
	if(mid<ri)
	{
		update(li,ri,c,tree[cur].rs);
	}
	pushup(cur);
}
	__int128 query(__int128 li,__int128 ri,__int128 cur)
{
	if(li<=tree[cur].l&&tree[cur].r<=ri)
	{
		return tree[cur].sum;
	}
	if(tree[cur].lazy!=-1)
	{
		pushdown(cur);
	}
	__int128 tot=0,mid=(tree[cur].l+tree[cur].r)/2;
	if(li<=mid)
	{
		tot+=query(li,ri,tree[cur].ls);
	}
	if(mid<ri)
	{
		tot+=query(li,ri,tree[cur].rs);
	}
	return tot;
}
};
	inline std::string gstr()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie();
	std::string s;
	std::cin>>s;
	return s;
}
	inline char gch()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie();
	char c;
	std::cin>>c;
	return c;
}
	inline void pstr(std::string s)
{
	std::ios::sync_with_stdio(false);
	std::cout.tie();
	std::cout<<s;
}
	inline void pch(char c)
{
	std::ios::sync_with_stdio(false);
	std::cout.tie();
	std::cout<<c;
}
	inline auto getn(auto a)
{
	std::ios::sync_with_stdio(false);
	std::cin.tie();
	std::cin>>a;
	return a;
}
	inline void putn(auto a)
{
	std::ios::sync_with_stdio(false);
	std::cout.tie();
	std::cout<<a;
}
	auto scan(auto &o)
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cin>>o;
	return o;
}
	void print(auto x,auto o)
{
	std::ios::sync_with_stdio(false);
	std::cout.tie(0);
	std::cout<<x<<o;
}
	auto lowbit(auto x)
{
	return x&-x;
}
	hash<long long,vector<__int128>>g;
	hash<long long,hash<long long,__int128>>gr;
	auto readl(auto&x)
{
	for(auto i:x)
	{
		scan(i);
	}
}
	auto writel(auto x,auto con)
{
	for(auto i:x)
	{
		print(i,con);
	}
}
	auto gcd(auto a,auto b)
{
	if(b==0)
	{
		return a;
	}
	else
	{
		return gcd(b,a%b);
	}
}
	int lcm(auto a,auto b)
{
	return a*b/gcd(a,b);
}
	bool isprime(auto x)
{
	for(auto i=2;i*i<=x;++i)
	{
		if(x%i==0)
		{
			return false;
		}
	}
	return true;
}
	struct BIT
{
	lll n,ans;
	hash<ll,lll>tree;
	auto plus(auto x,auto k)
{
	for(auto i=x;i<=n;i+=lowbit(i))
	{
		tree[i]+=k;
	}
}
	auto search(auto beg,auto end)
{
	for(auto i=end;i;i-=lowbit(i))
	{
		ans+=tree[i];
	}
	for(auto i=beg-1;i;i-=lowbit(i))
	{
		ans-=tree[i];
	}
}
	auto update(auto pos,auto k)
{
	for(auto i=pos;i<=n;i+=lowbit(i))
	{
		tree[i]+=k;
	}
}
	auto query(auto pos)
{
	auto ret=0;
	for(auto i=pos;i;i-=lowbit(i))
	{
		ret+=tree[i];
	}
	return ret;
}
};
	auto prim(lll n,lll m)
{
	hash<ll,lll>dis;
	hash<ll,bool>vis;
	for(auto i=1;i<=n;++i)
	{
		dis[i]=INT128_MAX;
	}
	dis[1]=0;
	for(auto i=1;i<=n;++i)
	{
		lll minv=INT128_MAX,minn=-1;
		for(auto j=1;j<=n;++j)
		{
			if(!vis[j]&&dis[j]<minv)
			{
				minv=dis[j];
				minn=j;
			}
		}
		if(minn==-1)
		{
			return -1;
		}
		vis[minn]=true;
		for(auto j=head[minn];j;j=e[j].nxt)
		{
			auto v=e[j].to,w=e[j].wei;
			if(!vis[v]&&w<dis[v])
			{
				dis[v]=w;
			}
		}
	}
	auto sum=0;
	for(auto i=1;i<=n;++i)
	{
		sum+=dis[i];
	}
	return sum;
}
}
using namespace lhy;
main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	return 0;
}
原文