#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<20;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 |
34 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
5912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
630 ms |
14616 KB |
Output is correct |
2 |
Correct |
617 ms |
14528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
947 ms |
19912 KB |
Output is correct |
2 |
Correct |
832 ms |
18100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
447 ms |
13888 KB |
Output is correct |
2 |
Correct |
416 ms |
12380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
474 ms |
14656 KB |
Output is correct |
2 |
Correct |
498 ms |
12976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
721 ms |
21560 KB |
Output is correct |
2 |
Correct |
473 ms |
15344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
968 ms |
19800 KB |
Output is correct |
2 |
Correct |
898 ms |
23740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1157 ms |
28508 KB |
Output is correct |
2 |
Correct |
1198 ms |
24960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1513 ms |
34836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |