#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;
const int maxn = 1e7 + 1;
int m, qs;
int dp[maxn];
vt<int> primes, ans;
vt<pi> queries;
int evs[maxn];
vt<pi> q;
main() {
cin.tie(0)->sync_with_stdio(0);
cin >> m >> qs;
primes.resize(m);
F0R (i, m) cin >> primes[i];
sort(all(primes));
memset(evs, -1, sizeof(evs));
for (int p : primes) {
int x = p;
while (x < maxn) {
evs[x] = p;
x += p;;
}
}
queries.resize(qs);
F0R (i, qs) cin >> queries[i].f, queries[i].s = i;
sort(all(queries));
reverse(all(queries));
ans.resize(qs, -1);
q.reserve(maxn);
int front = 0;
q.pb({0, primes.back()});
FOR (i, 1, maxn) {
if (evs[i] != -1) q.pb({i, evs[i]});
while (q[front].f + q[front].s <= i) front++;
if (q[front].f == i) break;
dp[i] = dp[q[front].f] + 1;
while (size(queries) && queries.back().f == i) {
ans[queries.back().s] = dp[i];
queries.pop_back();
}
if (!size(queries)) break;
}
F0R (i, qs) {
if (ans[i] == -1) cout << "oo\n";
else cout << ans[i] << endl;
}
}
Compilation message
brunhilda.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
33 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
39516 KB |
Output is correct |
2 |
Correct |
23 ms |
39516 KB |
Output is correct |
3 |
Correct |
22 ms |
39516 KB |
Output is correct |
4 |
Correct |
17 ms |
39768 KB |
Output is correct |
5 |
Correct |
22 ms |
39620 KB |
Output is correct |
6 |
Correct |
19 ms |
39516 KB |
Output is correct |
7 |
Correct |
22 ms |
39512 KB |
Output is correct |
8 |
Correct |
24 ms |
39516 KB |
Output is correct |
9 |
Correct |
29 ms |
39860 KB |
Output is correct |
10 |
Correct |
33 ms |
39532 KB |
Output is correct |
11 |
Correct |
33 ms |
39564 KB |
Output is correct |
12 |
Correct |
22 ms |
39512 KB |
Output is correct |
13 |
Correct |
54 ms |
39516 KB |
Output is correct |
14 |
Correct |
69 ms |
40004 KB |
Output is correct |
15 |
Correct |
26 ms |
39512 KB |
Output is correct |
16 |
Correct |
23 ms |
39516 KB |
Output is correct |
17 |
Correct |
24 ms |
39760 KB |
Output is correct |
18 |
Correct |
16 ms |
39604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
91476 KB |
Output is correct |
2 |
Correct |
81 ms |
91476 KB |
Output is correct |
3 |
Correct |
105 ms |
93520 KB |
Output is correct |
4 |
Correct |
90 ms |
103760 KB |
Output is correct |
5 |
Correct |
65 ms |
66820 KB |
Output is correct |
6 |
Correct |
45 ms |
69324 KB |
Output is correct |
7 |
Correct |
72 ms |
91476 KB |
Output is correct |
8 |
Correct |
56 ms |
64848 KB |
Output is correct |
9 |
Correct |
73 ms |
68564 KB |
Output is correct |
10 |
Correct |
98 ms |
93376 KB |
Output is correct |
11 |
Correct |
140 ms |
152148 KB |
Output is correct |
12 |
Correct |
107 ms |
123988 KB |
Output is correct |
13 |
Correct |
70 ms |
97272 KB |
Output is correct |
14 |
Correct |
95 ms |
103504 KB |
Output is correct |
15 |
Correct |
78 ms |
75384 KB |
Output is correct |
16 |
Correct |
81 ms |
91656 KB |
Output is correct |
17 |
Correct |
128 ms |
149192 KB |
Output is correct |
18 |
Correct |
128 ms |
147764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
152144 KB |
Output is correct |
2 |
Correct |
156 ms |
153092 KB |
Output is correct |
3 |
Correct |
123 ms |
120688 KB |
Output is correct |
4 |
Correct |
129 ms |
142660 KB |
Output is correct |
5 |
Correct |
105 ms |
100432 KB |
Output is correct |
6 |
Correct |
134 ms |
149844 KB |
Output is correct |
7 |
Correct |
112 ms |
108884 KB |
Output is correct |
8 |
Correct |
137 ms |
152152 KB |
Output is correct |
9 |
Correct |
142 ms |
152408 KB |
Output is correct |
10 |
Correct |
135 ms |
133200 KB |
Output is correct |
11 |
Correct |
123 ms |
125484 KB |
Output is correct |
12 |
Correct |
148 ms |
148052 KB |
Output is correct |
13 |
Correct |
118 ms |
98388 KB |
Output is correct |
14 |
Correct |
105 ms |
106956 KB |
Output is correct |
15 |
Correct |
133 ms |
151364 KB |
Output is correct |
16 |
Correct |
134 ms |
151892 KB |
Output is correct |
17 |
Correct |
124 ms |
143440 KB |
Output is correct |
18 |
Correct |
144 ms |
153088 KB |
Output is correct |
19 |
Correct |
79 ms |
111956 KB |
Output is correct |
20 |
Correct |
124 ms |
120656 KB |
Output is correct |
21 |
Correct |
139 ms |
151496 KB |
Output is correct |
22 |
Correct |
163 ms |
155476 KB |
Output is correct |
23 |
Correct |
115 ms |
102736 KB |
Output is correct |
24 |
Correct |
107 ms |
95312 KB |
Output is correct |
25 |
Correct |
134 ms |
140312 KB |
Output is correct |
26 |
Correct |
134 ms |
142676 KB |
Output is correct |
27 |
Correct |
171 ms |
121500 KB |
Output is correct |
28 |
Correct |
101 ms |
108492 KB |
Output is correct |
29 |
Correct |
149 ms |
149076 KB |
Output is correct |
30 |
Correct |
136 ms |
145744 KB |
Output is correct |
31 |
Correct |
125 ms |
110328 KB |
Output is correct |
32 |
Correct |
127 ms |
117928 KB |
Output is correct |
33 |
Correct |
72 ms |
88832 KB |
Output is correct |
34 |
Correct |
108 ms |
108880 KB |
Output is correct |
35 |
Correct |
97 ms |
109780 KB |
Output is correct |
36 |
Correct |
169 ms |
155220 KB |
Output is correct |
37 |
Correct |
107 ms |
100428 KB |
Output is correct |
38 |
Correct |
139 ms |
149844 KB |
Output is correct |
39 |
Correct |
110 ms |
99152 KB |
Output is correct |
40 |
Correct |
138 ms |
146676 KB |
Output is correct |
41 |
Correct |
93 ms |
113352 KB |
Output is correct |
42 |
Correct |
127 ms |
153936 KB |
Output is correct |