Submission #318091

#TimeUsernameProblemLanguageResultExecution timeMemory
318091shivensinha4Brunhilda’s Birthday (BOI13_brunhilda)C++17
0 / 100
5 ms1644 KiB
#include "bits/stdc++.h" using namespace std; #define for_(i, s, e) for (int i = s; i < (int) e; i++) #define for__(i, s, e) for (ll i = s; i < e; i++) typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; #define endl '\n' const int MXV = 1e1; vi qrs[MXV+2]; int qrAns[MXV+2], spf[MXV+2], done[MXV+2]; bool inc[MXV+2]; void pre() { memset(spf, -1, sizeof(spf)); for__(i, 2, MXV+1) if (spf[i] == -1) { spf[i] = i; for (ll j = i*i; j <= MXV; j += i) spf[j] = i; } } int main() { #ifdef shiven freopen("test.in", "r", stdin); #endif pre(); ios_base::sync_with_stdio(false); cin.tie(0); int m, q; cin >> m >> q; int mxp = -1; for_(i, 0, m) { int p; cin >> p; inc[p] = true; mxp = max(mxp, p); } // vector<ii> last; // {val, nxt} // last.push_back({0, mxp}); // int pt = 0; // for_(i, 1, MXV+1) { // if (pt < last.size() and last[pt].second == i) pt++; // if (pt < last.size()) ans[i] = ans[last[pt].first]+1; // for (int f = fac[i].size()-1; f >= 0; f--) { // int nxt = i+fac[i][f]; // if (ans[i] and last.back().second < nxt) last.push_back({i, nxt}); // if (nxt <= MXV) fac[nxt].push_back(fac[i][f]); // fac[i].pop_back(); // } // } for_(i, 0, q) { int k; cin >> k; qrs[k].push_back(i); } int pt = 0; vi fac; vector<ii> last; last.push_back({0, mxp}); for_(i, 1, MXV+1) { int ans = 0; if (pt < last.size() and last[pt].second == i) pt++; if (pt < last.size()) ans = last[pt].first+1; int k = i; while (spf[k] != -1) { if (inc[spf[k]] and done[spf[k]] != i) { done[spf[k]] = i; fac.push_back(spf[k]); } k /= spf[k]; } for (int f = fac.size()-1; f >= 0; f--) { int nxt = i+fac[f]; if (ans and last.back().second < nxt) last.push_back({ans, nxt}); fac.pop_back(); } // cout << i << ": " << ans << endl; for (int j: qrs[i]) qrAns[j] = ans; } for_(i, 0, q) { if (!qrAns[i]) cout << "oo"; else cout << qrAns[i]; cout << endl; } return 0; }

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:69:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   if (pt < last.size() and last[pt].second == i) pt++;
      |       ~~~^~~~~~~~~~~~~
brunhilda.cpp:70:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   if (pt < last.size()) ans = last[pt].first+1;
      |       ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...