Submission #1018683

# Submission time Handle Problem Language Result Execution time Memory
1018683 2024-07-10T08:27:25 Z vjudge1 Pictionary (COCI18_pictionary) C++17
140 / 140
1331 ms 36500 KB
#include <bits/stdc++.h>

using namespace std;

const int M = 1e5 + 1;

int col[M],sz[M];
vector<int> ver[M];

void add(int x,int y)
{
	int u=col[x],v=col[y];
	if (u==v)
		return;
	if (sz[u]<sz[v])
		swap(u,v);
	for (int i:ver[v])
	{
		col[i]=u;
		ver[u].push_back(i);
		sz[u]++;
	}
	ver[v].clear();
	sz[v]=0;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);

	int n,m,q;
	cin>>n>>m>>q;
	map<pair<int,int>,int> s,e;
	unordered_map<int,vector<pair<int,int>>> mid,mid1;
	vector<pair<int,int>> vec;
	while (q--)
	{
		int a,b;
		cin>>a>>b;
		s[{a,b}]=1,e[{a,b}]=m+1;
		mid[(m+2)/2].push_back({a,b});
		vec.push_back({a,b});
	}
	for (int qw=0;qw<18;qw++)
	{
		for (int i=1;i<=n;i++)
			col[i]=i,sz[i]=1,ver[i]={i};
		for (int i=m;i>=1;i--)
		{
			for (int j=i+i;j<=n;j+=i)
				add(i,j);
			for (auto p:mid[i])
			{
				if (col[p.first]==col[p.second])
					s[p]=i;
				else
					e[p]=i;
				mid1[(s[p]+e[p])/2].push_back(p);
			}
		}
		mid=mid1;
		mid1.clear();
	}
	for (auto i:vec)
		cout<<m+1-s[i]<<'\n';
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 5968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 553 ms 15084 KB Output is correct
2 Correct 582 ms 15108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 907 ms 20896 KB Output is correct
2 Correct 786 ms 18872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 419 ms 14372 KB Output is correct
2 Correct 384 ms 12968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 437 ms 15304 KB Output is correct
2 Correct 454 ms 13576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 22580 KB Output is correct
2 Correct 441 ms 15824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 949 ms 20888 KB Output is correct
2 Correct 836 ms 25020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1014 ms 29612 KB Output is correct
2 Correct 985 ms 25884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1331 ms 36500 KB Output is correct
2 Correct 1213 ms 29164 KB Output is correct