#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e7+4,MAXQ=112345,INF=1123456789;
int p[MAXQ],r[MAXQ],resp;
pair<int,int> query[MAXQ];
vector<int> seg,e,d;
vector<int> fat[MAXN];
map<int,int> mpa;
int create()
{
seg.push_back(INF);
e.push_back(0);
d.push_back(0);
return seg.size()-1;
}
void update(int cur,int ini,int fim,int id,int val)
{
if(ini>id || fim<id)return;
if(ini==fim)
{
seg[cur]=val;
return;
}
int m=(ini+fim)/2;
if(id<=m)
{
if(e[cur]==0)
{
int aux=create();
e[cur]=aux;
}
update(e[cur],ini,m,id,val);
}
else
{
if(d[cur]==0)
{
int aux=create();
d[cur]=aux;
}
update(d[cur],m+1,fim,id,val);
}
seg[cur]=min(seg[e[cur]],seg[d[cur]]);
}
int main()
{
create();create();
int m,q;
scanf("%d %d",&m,&q);
int mp=0;
for(int i=0;i<m;i++)
{
scanf("%d",&p[i]);
mp=max(mp,p[i]);
mpa[p[i]]=i;
}
int mq=0;
for(int i=0;i<q;i++)
{
scanf("%d",&r[i]);mq=max(mq,r[i]);
query[i]=make_pair(r[i],i);
r[i]=INF;
}
sort(query,query+q);
for(int i=0;i<m;i++)for(int j=p[i];j<=mq;j+=p[i])fat[j].push_back(mp[p[i]]);
int atu=0;
for(int i=1;i<=mq;i++)
{
if(i>=mp)
{
resp=INF;
for(int j=0;j<fat[i].size();j++)
{
//printf("%d %d %d\n",i,fat[i][j],resp[i]);
update(1,1,MAXN,fat[i][j],resp);
}
resp=seg[1]+1;
}
for(int j=0;j<fat[i].size();j++)
{
//printf("%d %d %d\n",i,fat[i][j],resp[i]);
update(1,1,MAXN,fat[i][j],resp);
}
if(i==query[atu].first)
{
r[query[atu].second]=resp;
atu++;
}
}
for(int i=0;i<q;i++)
{
if(r[i]<INF)printf("%d\n",r[i]+1);
else printf("oo\n");
}
//for(int i=0;i<7;i++)printf("%d ",resp[i]);
//printf("\n");
return 0;
}
Compilation message
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:65:78: error: invalid types 'int[int]' for array subscript
for(int i=0;i<m;i++)for(int j=p[i];j<=mq;j+=p[i])fat[j].push_back(mp[p[i]]);
^
brunhilda.cpp:72:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<fat[i].size();j++)
~^~~~~~~~~~~~~~
brunhilda.cpp:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<fat[i].size();j++)
~^~~~~~~~~~~~~~
brunhilda.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&m,&q);
~~~~~^~~~~~~~~~~~~~~
brunhilda.cpp:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&p[i]);
~~~~~^~~~~~~~~~~~
brunhilda.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&r[i]);mq=max(mq,r[i]);
~~~~~^~~~~~~~~~~~