Submission #534538

#TimeUsernameProblemLanguageResultExecution timeMemory
534538balbitIntercastellar (JOI22_ho_t1)C++14
100 / 100
69 ms9160 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define f first
#define s second

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<" "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__)
template <typename T> void _do( T && x) {cerr<<x<<endl;}
template <typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT

const int maxn = 3e5+5;

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);

    bug(1,2);

    int n; cin>>n;
    vector<int> a(n);
    vector<int> cnt(n,1);
    REP(i,n) {
        cin>>a[i];
        cnt[i] = a[i] & -a[i];
        a[i] /= cnt[i];
    }
    int q; cin>>q;
    int prv = 1;
    int at = 0;
    while (q--) {
        ll x; cin>>x;
        ll df = x - prv;
        while (df) {
            int tk = min((ll)cnt[at],df);
            cnt[at] -= tk;
            df -= tk;
            if (cnt[at] == 0) ++at;
        }
        cout<<a[at]<<endl;
        prv = x;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...