Submission #1324255

#TimeUsernameProblemLanguageResultExecution timeMemory
1324255sh_qaxxorov_571Intercastellar (JOI22_ho_t1)C++20
100 / 100
48 ms5348 KiB
#include <iostream>
#include <vector>

using namespace std;

/**
 * JOI 2021/2022 Final Round - Castella
 * Vaqt murakkabligi: O(N + Q)
 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    vector<long long> odd_val(N);
    vector<long long> prefix_count(N + 1, 0);

    for (int i = 0; i < N; i++) {
        long long a;
        cin >> a;
        
        long long count = 1;
        while (a % 2 == 0) {
            a /= 2;
            count *= 2;
        }
        // a endi toq son (odd_i), count esa 2^p_i
        odd_val[i] = a;
        prefix_count[i + 1] = prefix_count[i] + count;
    }

    int Q;
    cin >> Q;
    int current_idx = 0;

    for (int j = 0; j < Q; j++) {
        long long x;
        cin >> x;

        // X_j tartib bilan o'sib borishi sababli current_idx ni faqat oldinga suramiz
        while (prefix_count[current_idx + 1] < x) {
            current_idx++;
        }
        
        cout << odd_val[current_idx] << "\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...