Submission #559464

#TimeUsernameProblemLanguageResultExecution timeMemory
559464TrunktyBrunhilda’s Birthday (BOI13_brunhilda)C++14
20 / 100
414 ms136216 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define DEBUG
#ifdef DEBUG
  #define debug(x) cout << #x << ": " << x << endl
#else
  #define debug(x)
#endif

int m,q;
vector<int> upd[1000005];
int cnt[1000005];
int curr[1000005];
int ans[1000005],lp=0,maxi=2e9;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> m >> q;
	for(int i=1;i<=m;i++){
		int a;
		cin >> a;
		for(int j=a;j<=1e6;j+=a){
			upd[j].push_back(a);
		}
		cnt[0]++;
	}
	for(int i=1;i<=1e6;i++){
		for(int j:upd[i]){
			cnt[curr[j]]--;
			curr[j] = i;
			cnt[curr[j]]++;
		}
		while(lp!=i and !cnt[lp]){
			lp++;
		}
		if(lp==i){
			maxi = i;
			break;
		}
		ans[i] = ans[lp]+1;
	}
	for(int i=1;i<=q;i++){
		int a;
		cin >> a;
		if(a<maxi){
			cout << ans[a] << "\n";
		}
		else{
			cout << "oo" << "\n";
		}
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...