Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define all(a) a.begin(), a.end()
  4. #define mp make_pair
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9. typedef pair<int, int> pii;
  10. typedef pair<ll, ll> pll;
  11. typedef double ld;
  12. typedef unsigned int uint;
  13. typedef unsigned long long ull;
  14. typedef vector<vector<int> > vvi;
  15. typedef vector<vector<long long> > vvll;
  16. const int INF = 1e9;
  17.  
  18. vector<ll> cnt;
  19. vector<ll> lvlcnt;
  20. int n, m;
  21.  
  22. ll ask (ll x)
  23. {
  24. ll cur = 0;
  25. for (int i = n - 1; i > -1; --i)
  26. {
  27. if (cnt[i] != -INF)
  28. cur += (x - 1) / cnt[i] + 1;
  29. }
  30. return cur;
  31. }
  32.  
  33. int main()
  34. {
  35. //freopen ("input.txt","r",stdin);
  36. //freopen ("output.txt","w",stdout);
  37.  
  38. ios :: sync_with_stdio (false);
  39. cin >> n >> m;
  40. cnt.resize (n);
  41. lvlcnt.resize (n);
  42. cin >> cnt[0];
  43. lvlcnt[0] = cnt[0];
  44. for(int i = 1; i < n; ++i)
  45. {
  46. int val;
  47. cin >> val;
  48. lvlcnt[i] = val;
  49. cnt[i] = cnt[i - 1] * val;
  50. }
  51. for (int i = 1; i < n; ++i)
  52. {
  53. if (log10(lvlcnt[i]) + log10(cnt[i - 1]) >= 14 || cnt[i - 1] == -INF)
  54. cnt[i] = -INF;
  55. else
  56. cnt[i] = cnt[i - 1] * lvlcnt[i];
  57. }
  58. for(int i = 0; i < m; ++i)
  59. {
  60. int x;
  61. cin >> x;
  62. cout << ask (x) << '\n';
  63. }
  64.  
  65. //for(int i = 1; i <= n; ++i)
  66. // cout << i << ':' << level_cnt[i] << ':' << cnt[i] <<'\n';
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement