Submission #674133

# Submission time Handle Problem Language Result Execution time Memory
674133 2022-12-23T09:53:20 Z Giantpizzahead Intercastellar (JOI22_ho_t1) C++17
100 / 100
74 ms 8416 KB
/*
JOI 2022 Problem 1

Solution: Sweep from left to right, sorting the queries and processing them in order.
The operations in the statement can be done using some basic math.
*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define debug if (true) cerr
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

void solve() {
    int N; cin >> N;
    vi A(N);
    rep(i, 0, N) cin >> A[i];
    int Q; cin >> Q;
    vector<ll> X(Q);
    rep(i, 0, Q) cin >> X[i];

    ll piecesSoFar = 0;
    int currQ = 0;
    rep(i, 0, N) {
        ll currSize = A[i];
        ll currPieces = 1;
        while (currSize % 2 == 0) {
            currSize /= 2;
            currPieces *= 2;
        }
        // Answer all queries in this range
        piecesSoFar += currPieces;
        while (currQ != Q && X[currQ] <= piecesSoFar) {
            cout << currSize << '\n';
            currQ++;
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 16 ms 2004 KB Output is correct
4 Correct 23 ms 2964 KB Output is correct
5 Correct 41 ms 4692 KB Output is correct
6 Correct 22 ms 2832 KB Output is correct
7 Correct 48 ms 4700 KB Output is correct
8 Correct 45 ms 4824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 16 ms 2004 KB Output is correct
4 Correct 23 ms 2964 KB Output is correct
5 Correct 41 ms 4692 KB Output is correct
6 Correct 22 ms 2832 KB Output is correct
7 Correct 48 ms 4700 KB Output is correct
8 Correct 45 ms 4824 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 25 ms 3612 KB Output is correct
24 Correct 30 ms 4172 KB Output is correct
25 Correct 55 ms 8012 KB Output is correct
26 Correct 40 ms 4912 KB Output is correct
27 Correct 44 ms 4568 KB Output is correct
28 Correct 74 ms 8416 KB Output is correct
29 Correct 69 ms 7876 KB Output is correct
30 Correct 33 ms 4568 KB Output is correct
31 Correct 72 ms 8380 KB Output is correct