Submission #871125

#TimeUsernameProblemLanguageResultExecution timeMemory
871125Marco_EscandonIntercastellar (JOI22_ho_t1)C++11
100 / 100
445 ms10836 KiB
#include<bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 struct st{
    vector<ll> abi;
    void update(ll a,ll b)
    {
        for(a; a<abi.size(); a+=(a&-a))
        {
            abi[a]+=b;
        }
    }
    ll query(ll a)
    {
        ll s=0;
        for(a; a>0; a-=(a&-a))
        {
            s+=abi[a];
        }
        return s;
    }
    st(ll n)
    {
        abi.resize(n*2);
    }
 };
 int main()
 {
    ll n;
    cin>>n;
    ll cad[n+1];
    st asd(n+1);
    for(int i=1; i<=n; i++)
    {
        cin>>cad[i];
        ll temp=0;
        while(cad[i]%2==0)
        {
            cad[i]/=2;
            temp++;
        }
        asd.update(i,pow(2,temp));
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll a=0, b=n+1;
        ll en;
        cin>>en;
        //cout<<asd.query(en)<<" ";
        while(abs(a-b)!=1)
        {
            ll m=(a+b)/2;
            if(asd.query(m)>=en)
                b=m;
            else a=m;
        }
        cout<<cad[b]<<"\n";
    }

 }

Compilation message (stderr)

Main.cpp: In member function 'void st::update(ll, ll)':
Main.cpp:8:13: warning: statement has no effect [-Wunused-value]
    8 |         for(a; a<abi.size(); a+=(a&-a))
      |             ^
Main.cpp:8:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |         for(a; a<abi.size(); a+=(a&-a))
      |                ~^~~~~~~~~~~
Main.cpp: In member function 'll st::query(ll)':
Main.cpp:16:13: warning: statement has no effect [-Wunused-value]
   16 |         for(a; a>0; a-=(a&-a))
      |             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...