Submission #914850

# Submission time Handle Problem Language Result Execution time Memory
914850 2024-01-22T18:29:04 Z andrei_iorgulescu Intercastellar (JOI22_ho_t1) C++14
100 / 100
220 ms 10836 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int n,a[200005],v[200005],sp[200005];

int nr_pieces(int x)
{
    if (x % 2 == 1)
        return 1;
    return 2 * nr_pieces(x / 2);
}

int kth(int x,int k)
{
    if (x % 2 == 1)
        return x;
    if (k <= nr_pieces(x / 2))
        return kth(x / 2,k);
    else
        return kth(x / 2,k - nr_pieces(x / 2));
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        v[i] = nr_pieces(a[i]);
    for (int i = 1; i <= n; i++)
        sp[i] = v[i] + sp[i - 1];
    int q;
    cin >> q;
    for (int i = 1; i <= q; i++)
    {
        int x;
        cin >> x;
        int st = 0,pas = 1 << 17;
        while (pas != 0)
        {
            if (st + pas <= n and sp[st + pas] < x)
                st += pas;
            pas /= 2;
        }
        cout << kth(a[st + 1],x - sp[st]) << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 18 ms 5724 KB Output is correct
4 Correct 34 ms 5892 KB Output is correct
5 Correct 51 ms 7232 KB Output is correct
6 Correct 29 ms 5976 KB Output is correct
7 Correct 53 ms 7164 KB Output is correct
8 Correct 53 ms 7124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4572 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 18 ms 5724 KB Output is correct
4 Correct 34 ms 5892 KB Output is correct
5 Correct 51 ms 7232 KB Output is correct
6 Correct 29 ms 5976 KB Output is correct
7 Correct 53 ms 7164 KB Output is correct
8 Correct 53 ms 7124 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4572 KB Output is correct
21 Correct 2 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 29 ms 7064 KB Output is correct
24 Correct 31 ms 7260 KB Output is correct
25 Correct 65 ms 10484 KB Output is correct
26 Correct 69 ms 7956 KB Output is correct
27 Correct 62 ms 7508 KB Output is correct
28 Correct 130 ms 10836 KB Output is correct
29 Correct 220 ms 10408 KB Output is correct
30 Correct 104 ms 7720 KB Output is correct
31 Correct 158 ms 10836 KB Output is correct