Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define all(a) a.begin(), a.end()
- #define mp make_pair
- using namespace std;
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<ll, ll> pll;
- typedef double ld;
- typedef unsigned int uint;
- typedef unsigned long long ull;
- typedef vector<vector<int> > vvi;
- typedef vector<vector<long long> > vvll;
- const int INF = 1e9;
- vector<ll> cnt;
- vector<ll> lvlcnt;
- int n, m;
- ll ask (ll x)
- {
- ll cur = 0;
- for (int i = n - 1; i > -1; --i)
- {
- if (cnt[i] != -INF)
- cur += (x - 1) / cnt[i] + 1;
- }
- return cur;
- }
- int main()
- {
- //freopen ("input.txt","r",stdin);
- //freopen ("output.txt","w",stdout);
- ios :: sync_with_stdio (false);
- cin >> n >> m;
- cnt.resize (n);
- lvlcnt.resize (n);
- cin >> cnt[0];
- lvlcnt[0] = cnt[0];
- for(int i = 1; i < n; ++i)
- {
- int val;
- cin >> val;
- lvlcnt[i] = val;
- cnt[i] = cnt[i - 1] * val;
- }
- for (int i = 1; i < n; ++i)
- {
- if (log10(lvlcnt[i]) + log10(cnt[i - 1]) >= 14 || cnt[i - 1] == -INF)
- cnt[i] = -INF;
- else
- cnt[i] = cnt[i - 1] * lvlcnt[i];
- }
- for(int i = 0; i < m; ++i)
- {
- int x;
- cin >> x;
- cout << ask (x) << '\n';
- }
- //for(int i = 1; i <= n; ++i)
- // cout << i << ':' << level_cnt[i] << ':' << cnt[i] <<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement