Submission #787120

#TimeUsernameProblemLanguageResultExecution timeMemory
787120stefanneaguIntercastellar (JOI22_ho_t1)C++17
25 / 100
87 ms5504 KiB
#include <iostream> #include <algorithm> using namespace std; const int nmax = 2e5 + 1; struct numar { int val, i; } ax[nmax]; bool cmp(numar a, numar b) { return a.val < b.val; } int check(int x) { int cnt = 0; while(x % 2 == 0) { cnt ++; x /= 2; } return cnt; } int ans[nmax], v[nmax]; int main() { int n; cin >> n; for(int i = 1; i <= n; i ++) { cin >> v[i]; } int q; cin >> q; for(int i = 1; i <= q; i ++) { cin >> ax[i].val; ax[i].i = i; } sort(ax + 1, ax + q + 1, cmp); int curr = 0, ult = 0, an = 1; for(int i = 1; i <= n; i ++) { if(an == q + 1) { break; } ult = curr; curr ++; ult ++; int x = check(v[i]); curr += (1 << x) - 1; if(ult <= ax[an].val && ax[an].val <= curr) { ans[ax[an].i] = v[i] / (1 << x); an ++; i --; curr -= (1 << x); ult --; } } for(int i = 1; i <= q; i ++) { cout << ans[i] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...