Submission #1019367

# Submission time Handle Problem Language Result Execution time Memory
1019367 2024-07-10T18:22:29 Z underwaterkillerwhale Intercastellar (JOI22_ho_t1) C++17
100 / 100
291 ms 70312 KB
#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r)
{
    return uniform_int_distribution<ll> (l, r)(rd);
}

const int N  = 2e5 + 7;
const int Mod =1e9 + 7;
const int szBL = 916;
const ll INF = 1e18;
const int BASE = 137;

struct Data {
    ll a, b, c;
};

int n, Q;
ll a[N];
ll dp[N];
vector<ll> Val, g;

void solution () {
    cin >> n;
    rep (i, 1, n) {
        cin >> a[i];
        ll X = a[i];
        while (X > 0 && X % 2 == 0) {
            Val.push_back(X);
            X /= 2;
        }
        Val.push_back(X);
    }
    sort (ALL(Val));
    Val.resize(unique(ALL(Val)) - Val.begin());
    g.resize(SZ(Val) + 1, 0);
//    iter (&id, Val) cout << id <<"\n";
    rep (i, 0, SZ(Val) - 1) {
        ll cur = Val[i];
        if (cur & 1) g[i] = 1;
        else {
            g[i] = g[lower_bound(ALL(Val), cur / 2) - Val.begin()] * 2;
//            cout << cur<<" "<<g[5]<<" "<<lower_bound(ALL(Val), cur / 2) - Val.begin()<<"\n";
        }
    }
    rep (i, 1, n) {
        dp[i] = dp[i - 1] + g[lower_bound(ALL(Val), a[i]) - Val.begin()];
//        cout << g[lower_bound(ALL(Val), a[i]) - Val.begin()]<<","<<dp[i] <<" ";
    }
//    cout<<"\n";
//    return;
    int ptr = 0;
    cin >> Q;
    rep (i, 1, Q) {
        ll X;
        cin >> X;
        while (ptr < n - 1 && dp[ptr + 1] < X) ++ptr;
        ll cur = a[ptr + 1];
        ll delta = X - dp[ptr];
        while (cur > 0 && cur % 2 == 0) {
            cur /= 2;
        }
        cout << cur <<"\n";
    }

}

#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    file ("c");
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
1 2
*/

Compilation message

Main.cpp: In function 'void solution()':
Main.cpp:75:12: warning: unused variable 'delta' [-Wunused-variable]
   75 |         ll delta = X - dp[ptr];
      |            ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2452 KB Output is correct
3 Correct 25 ms 8188 KB Output is correct
4 Correct 20 ms 3800 KB Output is correct
5 Correct 41 ms 8660 KB Output is correct
6 Correct 30 ms 8400 KB Output is correct
7 Correct 50 ms 8404 KB Output is correct
8 Correct 44 ms 12240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2556 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2516 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2908 KB Output is correct
14 Correct 2 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2452 KB Output is correct
3 Correct 25 ms 8188 KB Output is correct
4 Correct 20 ms 3800 KB Output is correct
5 Correct 41 ms 8660 KB Output is correct
6 Correct 30 ms 8400 KB Output is correct
7 Correct 50 ms 8404 KB Output is correct
8 Correct 44 ms 12240 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2556 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2516 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 2 ms 2908 KB Output is correct
21 Correct 2 ms 2908 KB Output is correct
22 Correct 2 ms 2904 KB Output is correct
23 Correct 25 ms 5972 KB Output is correct
24 Correct 70 ms 11116 KB Output is correct
25 Correct 112 ms 15240 KB Output is correct
26 Correct 183 ms 27048 KB Output is correct
27 Correct 218 ms 38024 KB Output is correct
28 Correct 291 ms 40876 KB Output is correct
29 Correct 246 ms 70312 KB Output is correct
30 Correct 53 ms 10428 KB Output is correct
31 Correct 283 ms 45992 KB Output is correct