Submission #917091

# Submission time Handle Problem Language Result Execution time Memory
917091 2024-01-27T06:52:12 Z LiuBruh Intercastellar (JOI22_ho_t1) C++17
100 / 100
61 ms 9332 KB
/***
 * ALL
*/
#include <bits/stdc++.h>

#define int long long
#define sz(v) (int)v.size()
using namespace std;

const int maxn = (int)2e5 + 5;
const int INF = (int)1e18 + 5;

int n, q;
queue<int> ar, que;

pair<int, int> f(int x) {
    // cout << "test " << x << endl;
    int cnt = 1, num = x;
    while (num % 2 == 0) {
        num /= 2;
        cnt *= 2;
    }
    return {num, cnt};
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;  cin >> x;
        ar.push(x);
    }
    cin >> q;
    for (int i = 1; i <= q; i++) {
        int x;  cin >> x;
        que.push(x);
    }

    int cnt = 0, lstnum = -1;
    while (!que.empty()) {
        int pos = que.front();  que.pop();
        while (cnt < pos) {
            // cout << "grab " << ar.front() << endl;
            auto [num, many] = f(ar.front());  ar.pop();
            cnt += many;
            // cout << "pos " << pos << '\t' << "cnt " << cnt << endl << endl;
            if (cnt >= pos) {
                lstnum = num;
            }
        }
        cout << lstnum << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 15 ms 2928 KB Output is correct
4 Correct 20 ms 3420 KB Output is correct
5 Correct 34 ms 5712 KB Output is correct
6 Correct 20 ms 3704 KB Output is correct
7 Correct 34 ms 5720 KB Output is correct
8 Correct 35 ms 5752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 15 ms 2928 KB Output is correct
4 Correct 20 ms 3420 KB Output is correct
5 Correct 34 ms 5712 KB Output is correct
6 Correct 20 ms 3704 KB Output is correct
7 Correct 34 ms 5720 KB Output is correct
8 Correct 35 ms 5752 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 472 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 18 ms 3932 KB Output is correct
24 Correct 25 ms 4948 KB Output is correct
25 Correct 47 ms 9036 KB Output is correct
26 Correct 32 ms 5456 KB Output is correct
27 Correct 33 ms 5132 KB Output is correct
28 Correct 53 ms 9296 KB Output is correct
29 Correct 52 ms 8892 KB Output is correct
30 Correct 26 ms 4944 KB Output is correct
31 Correct 61 ms 9332 KB Output is correct