Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/detail/standard_policies.hpp>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #pragma comment(linker, "/stack:200000000")
- #pragma GCC optimize("Ofast")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC optimize("O3")
- #define F first
- #define S second
- #define pb push_back
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define endl '\n'
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
- const int N = 5e5 + 100;
- const int M = 30 + 5;
- const int B = 2100;
- const int add1 = 39;
- const ll per = 1e10;
- const ll INF = 1e10;
- const int MOD = 998244353;
- const int MOD1 = 1e9 + 7;
- const int rx[4] = {0, 1, -1, 0};
- const int ry[4] = {1, 0, 0, -1};
- const char rr[5]= {'5', 'N', 'E', 'S', 'W'};
- template <typename T> using ordered_set = tree <T, null_type, less< T >, rb_tree_tag,tree_order_statistics_node_update>;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- srand(time(0));
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #else
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- #endif
- ull kek = 1;
- vector < ull > st(39);
- for (int i = 0; i <= 38; i++) {
- st[i] = kek;
- kek *= 3;
- }
- // for (int i = 0; i <= 38; i++) cout << st[i] << endl;
- // cout << endl;
- int q;
- cin >> q;
- while (q--) {
- ull x;
- cin >> x;
- int pos = lower_bound(st.begin() , st.end() , x) - st.begin();
- ull ans = st[pos];
- ull now = 0;
- if (st[pos] > x) {
- for (int i = pos; i >= 0; i--) {
- if (now + st[i] <= x) now += st[i];
- }
- }
- if (abs(now - x) < abs(x - ans) && now >= x) ans = now;
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement