#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 1;
int col[M],sz[M];
queue<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);
while (!ver[v].empty())
{
int i=ver[v].front();
ver[v].pop();
col[i]=u;
ver[u].push(i);
sz[u]++;
sz[v]--;
}
}
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;
while (!ver[i].empty())
ver[i].pop();
ver[i].push(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 |
Runtime error |
23 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
30 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
23 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
29 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
24 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |