제출 #1129167

#제출 시각아이디문제언어결과실행 시간메모리
1129167yumemysteryIntercastellar (JOI22_ho_t1)C++20
35 / 100
2094 ms840 KiB
#include <iostream>
#include <cmath>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    short n;
    cin >> n;
    unsigned long long A[n]; //len
    unsigned long long total_castella[n];
    for (int i=0; i<n; i++) {
        cin >> A[i];

        unsigned long long tmp = A[i];

 
        while (tmp%2 == 0) tmp/=2;
        
        total_castella[i] = A[i]/tmp;

        A[i] = tmp;
        
        if (i>0) total_castella[i]+=total_castella[i-1];  
    }

    short Q;
    cin >> Q;

    

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

        int left = 0;
        int right = n-1;
        int ans = 0;

        while (left<=right) {
            int mid = left+(right-left)/2;

            if (total_castella[mid] >= x) {
                ans = mid;
                right = mid-1;
            }
            else left = mid+1;
        }
        cout << A[ans] << "\n";
    }

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...