Submission #914850

#TimeUsernameProblemLanguageResultExecution timeMemory
914850andrei_iorgulescuIntercastellar (JOI22_ho_t1)C++14
100 / 100
220 ms10836 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n,a[200005],v[200005],sp[200005]; int nr_pieces(int x) { if (x % 2 == 1) return 1; return 2 * nr_pieces(x / 2); } int kth(int x,int k) { if (x % 2 == 1) return x; if (k <= nr_pieces(x / 2)) return kth(x / 2,k); else return kth(x / 2,k - nr_pieces(x / 2)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) v[i] = nr_pieces(a[i]); for (int i = 1; i <= n; i++) sp[i] = v[i] + sp[i - 1]; int q; cin >> q; for (int i = 1; i <= q; i++) { int x; cin >> x; int st = 0,pas = 1 << 17; while (pas != 0) { if (st + pas <= n and sp[st + pas] < x) st += pas; pas /= 2; } cout << kth(a[st + 1],x - sp[st]) << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...