Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #include <ext/pb_ds/detail/standard_policies.hpp>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/tree_policy.hpp>
  6.  
  7. #pragma comment(linker, "/stack:200000000")
  8. #pragma GCC optimize("Ofast")
  9. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  10. #pragma GCC optimize("unroll-loops")
  11. #pragma GCC optimize("O3")
  12.  
  13. #define F first
  14. #define S second
  15. #define pb push_back
  16. #define ll long long
  17. #define ld long double
  18. #define ull unsigned long long
  19. #define endl '\n'
  20.  
  21. using namespace std;
  22. using namespace __gnu_pbds;
  23.  
  24.  
  25. mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
  26.  
  27.  
  28. const int N = 5e5 + 100;
  29. const int M = 30 + 5;
  30. const int B = 2100;
  31. const int add1 = 39;
  32. const ll per = 1e10;
  33. const ll INF = 1e10;
  34. const int MOD = 998244353;
  35. const int MOD1 = 1e9 + 7;
  36. const int rx[4] = {0, 1, -1, 0};
  37. const int ry[4] = {1, 0, 0, -1};
  38. const char rr[5]= {'5', 'N', 'E', 'S', 'W'};
  39. template <typename T> using ordered_set = tree <T, null_type, less< T >, rb_tree_tag,tree_order_statistics_node_update>;
  40.  
  41. int main() {
  42. ios_base::sync_with_stdio(0);
  43. cin.tie(0);
  44. cout.tie(0);
  45. srand(time(0));
  46. #ifdef LOCAL
  47. freopen("input.txt", "r", stdin);
  48. freopen("output.txt", "w", stdout);
  49. #else
  50. //freopen("input.txt", "r", stdin);
  51. //freopen("output.txt", "w", stdout);
  52. #endif
  53. ull kek = 1;
  54. vector < ull > st(39);
  55. for (int i = 0; i <= 38; i++) {
  56. st[i] = kek;
  57. kek *= 3;
  58. }
  59. // for (int i = 0; i <= 38; i++) cout << st[i] << endl;
  60. // cout << endl;
  61. int q;
  62. cin >> q;
  63. while (q--) {
  64. ull x;
  65. cin >> x;
  66. int pos = lower_bound(st.begin() , st.end() , x) - st.begin();
  67. ull ans = st[pos];
  68. ull now = 0;
  69. if (st[pos] > x) {
  70. for (int i = pos; i >= 0; i--) {
  71. if (now + st[i] <= x) now += st[i];
  72. }
  73. }
  74. if (abs(now - x) < abs(x - ans) && now >= x) ans = now;
  75. cout << ans << endl;
  76. }
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement