#include <bits/stdc++.h>
using namespace std;
// #undef _GLIBCXX_DEBUG // disable run-time bound checking, etc
// #pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("bmi,bmi2,lzcnt,popcnt") // bit manipulation
// #pragma GCC target("movbe") // byte swap
// #pragma GCC target("aes,pclmul,rdrnd") // encryption
// #pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD
// #include <bits/extc++.h>
// using namespace __gnu_pbds;
// template<class T>using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// template<class T>using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define ll long long
#define INF (ll)1e9+7
#define fo(i, n) for(int i=0;i<(int)n;i++)
#define Fo(i, k, n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x) cout << #x << " = " << x << endl;
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LSOne(S) ((S) & (-S))
#define sp(x, y) fixed<<setprecision(y)<<x
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+)
inline int readint(){ int v = 0; char c; while((c = getchar()) != EOF && c != ' ' && c != '\n'){ v *= 10; v += c - '0'; } return v; }
inline int readintsigned() { int v = 0; int sign = 1; char c = getchar(); if (c == '-') { sign = -1; } else { v += c - '0'; } while ((c = getchar()) != EOF && c != ' ' && c != '\n') { v *= 10; v += c - '0'; } return v * sign; }
inline string readstring() { string s; char c; while ((c = getchar()) != EOF && c != '\n' && c != ' ') { s.push_back(c); } return s; }
template <class result_t=std::chrono::milliseconds,class clock_t=std::chrono::steady_clock,class duration_t = std::chrono::milliseconds>
auto since(std::chrono::time_point<clock_t, duration_t> const& start){return std::chrono::duration_cast<result_t>(clock_t::now() - start);}
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vpii> vvpii;
typedef vector<vpl> vvpl;
struct Node{ // borde testa att bara ha med noder som behövs
int lo, hi, val = INF, rset = INF;
Node *lnode, *rnode;
Node(int lo, int hi) : lo(lo), hi(hi){
if(hi-lo != 1){
int mid = (hi+lo) / 2;
lnode = new Node(lo, mid);
rnode = new Node(mid, hi);
}
}
void update(int l, int r, int x){
if(hi <= l || r <= lo) return;
if(hi <= r && l <= lo) {
rset = min(rset, x);
val = min(val, rset);
return;
}
push();
lnode->update(l, r, x); rnode->update(l, r, x);
}
int query(int l, int r){
if(hi <= l || r <= lo) return 0;
if(hi <= r && l <= lo) {
return val = min(val, rset);
}
push();
return max(lnode->query(l, r), rnode->query(l, r));
}
void push(){
if(rset != INF){
val = min(val, rset);
lnode->rset = min(lnode->rset, rset);
rnode->rset = min(rnode->rset, rset);
rset = INF;
}
}
};
int main() {
// cout << fixed << setprecision(20);
// auto start = std::chrono::steady_clock::now(); // since(start).count()
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit); // remove if to endof file
int n, q, val;
cin >> n >> q;
vi v;
fo(i, n){
cin >> val;
v.pb(val);
}
int siz = 10000;
vi biggest(siz+1, 0);
fo(i, v.size()){
for(int j = 0; j<=siz; j+=v[i]) biggest[j] = max(biggest[j], v[i]);
}
Node st(0, siz+2);
st.update(0, 1, 0);
fo(i, siz+1){
if(biggest[i] == 0) continue;
st.update(i+1, i+biggest[i], st.query(i, i+1)+1);
}
while(q--){
cin >> val;
int ans = st.query(val, val+1);
if(ans > 1e9) cout << "oo\n";
else cout << ans << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1236 KB |
Output is correct |
2 |
Correct |
4 ms |
1216 KB |
Output is correct |
3 |
Correct |
3 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1360 KB |
Output is correct |
5 |
Correct |
2 ms |
1216 KB |
Output is correct |
6 |
Correct |
2 ms |
1236 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1236 KB |
Output is correct |
9 |
Correct |
3 ms |
1236 KB |
Output is correct |
10 |
Correct |
4 ms |
1236 KB |
Output is correct |
11 |
Correct |
5 ms |
1236 KB |
Output is correct |
12 |
Correct |
2 ms |
1236 KB |
Output is correct |
13 |
Correct |
5 ms |
1224 KB |
Output is correct |
14 |
Correct |
7 ms |
1364 KB |
Output is correct |
15 |
Correct |
3 ms |
1236 KB |
Output is correct |
16 |
Correct |
3 ms |
1212 KB |
Output is correct |
17 |
Correct |
5 ms |
1364 KB |
Output is correct |
18 |
Correct |
4 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1364 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
2348 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
2040 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
1232 KB |
Output isn't correct |
5 |
Incorrect |
9 ms |
1868 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
1236 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
1364 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
1236 KB |
Output isn't correct |
9 |
Incorrect |
9 ms |
2004 KB |
Output isn't correct |
10 |
Incorrect |
10 ms |
1992 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
1624 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
1220 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
1236 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
1252 KB |
Output isn't correct |
15 |
Incorrect |
7 ms |
1744 KB |
Output isn't correct |
16 |
Incorrect |
10 ms |
2260 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
1236 KB |
Output isn't correct |
18 |
Incorrect |
13 ms |
2388 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
2100 KB |
Output isn't correct |
2 |
Incorrect |
13 ms |
2008 KB |
Output isn't correct |
3 |
Incorrect |
18 ms |
2352 KB |
Output isn't correct |
4 |
Incorrect |
19 ms |
2164 KB |
Output isn't correct |
5 |
Incorrect |
26 ms |
3328 KB |
Output isn't correct |
6 |
Incorrect |
19 ms |
2240 KB |
Output isn't correct |
7 |
Incorrect |
23 ms |
2960 KB |
Output isn't correct |
8 |
Incorrect |
15 ms |
2136 KB |
Output isn't correct |
9 |
Incorrect |
22 ms |
2128 KB |
Output isn't correct |
10 |
Incorrect |
7 ms |
1364 KB |
Output isn't correct |
11 |
Incorrect |
7 ms |
1532 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
1560 KB |
Output isn't correct |
13 |
Incorrect |
23 ms |
2436 KB |
Output isn't correct |
14 |
Incorrect |
19 ms |
2092 KB |
Output isn't correct |
15 |
Incorrect |
11 ms |
1492 KB |
Output isn't correct |
16 |
Incorrect |
9 ms |
1484 KB |
Output isn't correct |
17 |
Incorrect |
9 ms |
1868 KB |
Output isn't correct |
18 |
Incorrect |
13 ms |
2020 KB |
Output isn't correct |
19 |
Incorrect |
6 ms |
1544 KB |
Output isn't correct |
20 |
Incorrect |
17 ms |
2332 KB |
Output isn't correct |
21 |
Incorrect |
19 ms |
2180 KB |
Output isn't correct |
22 |
Incorrect |
29 ms |
3256 KB |
Output isn't correct |
23 |
Incorrect |
25 ms |
2548 KB |
Output isn't correct |
24 |
Incorrect |
18 ms |
2120 KB |
Output isn't correct |
25 |
Incorrect |
21 ms |
2120 KB |
Output isn't correct |
26 |
Incorrect |
24 ms |
2120 KB |
Output isn't correct |
27 |
Incorrect |
21 ms |
2892 KB |
Output isn't correct |
28 |
Incorrect |
18 ms |
2192 KB |
Output isn't correct |
29 |
Incorrect |
29 ms |
3356 KB |
Output isn't correct |
30 |
Incorrect |
26 ms |
2948 KB |
Output isn't correct |
31 |
Incorrect |
17 ms |
2168 KB |
Output isn't correct |
32 |
Incorrect |
21 ms |
2108 KB |
Output isn't correct |
33 |
Incorrect |
17 ms |
2140 KB |
Output isn't correct |
34 |
Incorrect |
26 ms |
2832 KB |
Output isn't correct |
35 |
Incorrect |
18 ms |
2260 KB |
Output isn't correct |
36 |
Incorrect |
28 ms |
3204 KB |
Output isn't correct |
37 |
Incorrect |
28 ms |
3364 KB |
Output isn't correct |
38 |
Incorrect |
20 ms |
2376 KB |
Output isn't correct |
39 |
Incorrect |
19 ms |
2268 KB |
Output isn't correct |
40 |
Incorrect |
20 ms |
2232 KB |
Output isn't correct |
41 |
Incorrect |
24 ms |
2880 KB |
Output isn't correct |
42 |
Incorrect |
22 ms |
2208 KB |
Output isn't correct |