Submission #801866

#TimeUsernameProblemLanguageResultExecution timeMemory
801866vjudge1Intercastellar (JOI22_ho_t1)C++14
100 / 100
82 ms9224 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const int N = 2e5 ;
ll n, q, pref[N + 10] ;
vector<pair<ll, ll>> v ;
main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n ;
    v.push_back({0, 0}) ;
    for(ll i = 1 ; i <= n ; i++)
    {
        ll a, kol = 0 ;
        cin >> a ;
        while(!(a & 1))
        {
            kol++ ;
            a >>= 1 ;
        }
        v.push_back({(1 << kol), a}) ;
    }
    cin >> q ;
    for(int i = 1 ; i < v.size() ; i++)
        pref[i] = pref[i - 1] + v[i].fi ;
    while(q--)
    {
        ll x, l = 0, r = v.size() ;
        cin >> x ;
        while(l + 1 < r)
        {
            int mid = (l + r) >> 1 ;
            if(pref[mid] < x)
                l = mid ;
            else
                r = mid ;
        }
        cout << v[r].se << '\n' ;
    }
    return 0 ;
}

Compilation message (stderr)

Main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 1 ; i < v.size() ; i++)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...