Submission #527994

#TimeUsernameProblemLanguageResultExecution timeMemory
527994amukkalirIntercastellar (JOI22_ho_t1)C++17
100 / 100
100 ms8920 KiB
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll; 

#define prn printf
#define scn scanf

const int nax = 2e5; 
ll p[nax+5]; //jumlahnya 
ll v[nax+5]; // value nya 
int n; 

ll binser(ll x) {
    ll lo = 1, hi = n; 
    ll ret = lo; 

    while(lo <= hi) {
        int mid = (lo+hi)>>1; 
        if(x <= p[mid]) {
            ret = mid; 
            hi = mid-1; 
        } else lo = mid+1; 
    }
    return ret; 
}

signed main () {
    scn("%d", &n); 
    for(int i=1; i<=n; i++) {
        ll a; scn("%lld", &a); 
        int cnt = 0; 
        while(a%2==0) {
            cnt++; 
            a /= 2; 
        }
        p[i] = 1ll<<cnt; 
        p[i] += p[i-1]; 
        v[i] = a; 

        //cerr << i << " " << p[i] << " " << v[i] << endl; 
    }
    int q; 
    scn("%d", &q); 
    
    while(q--) {
        ll x; scn("%lld", &x); 
//cerr << x << " " << binser(x) << endl; 
        prn("%lld\n", v[binser(x)]); 
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scn("%d", &n);
      |        ^
Main.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         ll a; scn("%lld", &a);
      |                  ^
Main.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scn("%d", &q);
      |        ^
Main.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         ll x; scn("%lld", &x);
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...