为啥 TLE 啊
查看原帖
为啥 TLE 啊
464004
ZepX_D楼主2024/10/24 20:08
#include <bits/stdc++.h>
#define fr first
#define se second
#define U unsigned
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define pLi pair<LL,int>
#define pLL pair<LL,LL>
#define __ __int128
#define ld long double
#define VE vector<LL>
#define db double
#define Ve vector<int>

using namespace std;

inline LL read()
{
	LL x = 0,f = 1;char ch = getchar();
	while(!isdigit(ch)) (ch == '-') && (f = -1),ch = getchar();
	while(isdigit(ch)) x = x*10+ch-48,ch = getchar();
	return x*f;
}

const int N = 1e5+5;
int a[N],b[N],val1[N],val2[N];
unordered_map < LL,bool > mp;

int main()
{
	int n = read(),m = read();
	printf("%d\n",n*m);
	for (int i = 1;i <= n;i++) val1[i] = val2[i] = m;
	for (int i = 1;i <= m;i++)
		a[i] = read(),b[i] = read(),printf("%d %d\n",a[i],b[i]),val1[a[i]]--,val2[b[i]]--,mp[((LL)a[i]<<30)+b[i]] = 1;
	queue < pii > q;
	for (int i = 1;i <= n;i++)
		if (val2[i]) q.push({val2[i],i});
	for (LL i = 1;i <= n;i++)
	{
		while(val1[i])
		{
			pii p = q.front();q.pop();
			if (mp[(i<<30)+p.se]) q.push(p);
			else
			{
				printf("%d %d\n",i,p.se),mp[(i<<30)+p.se] = 1,val1[i]--;
				if (p.fr > 1) q.push({p.fr-1,p.se});
			}
		}
	}
	return 0;
}
2024/10/24 20:08
加载中...