Submission #916624

# Submission time Handle Problem Language Result Execution time Memory
916624 2024-01-26T07:28:54 Z tuannm Intercastellar (JOI22_ho_t1) C++17
100 / 100
66 ms 10836 KB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 2e5 + 1;
const string NAME = "";
const int lim = 2147483647;
//const unsigned int lim = 4294967295;
//const long long lim = 9223372036854775807;
//const unsigned long long lim = 18446744073709551615;
const int mset = 0x3f;
const double pi = acos(-1);
int n, q;
ll a[N];
long long sum[N];

void inp(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i].fi;
        a[i].se = 1;
        while(a[i].fi % 2 == 0){
            a[i].se *= 2;
            a[i].fi /= 2;
        }
        sum[i] = sum[i - 1] + a[i].se;
    }
    cin >> q;
}

void solve(){
    while(q--){
        long long x;
        cin >> x;
        int l = 1, r = n, ans = n;
        while(l <= r){
            int mid = (l + r) / 2;
            if(sum[mid] >= x){
                ans = mid;
                r = mid - 1;
            }
            else l = mid + 1;
        }
        cout << a[ans].fi << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    solve();
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 16 ms 5728 KB Output is correct
4 Correct 27 ms 6236 KB Output is correct
5 Correct 40 ms 7052 KB Output is correct
6 Correct 23 ms 5724 KB Output is correct
7 Correct 45 ms 7264 KB Output is correct
8 Correct 39 ms 7260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 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 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 16 ms 5728 KB Output is correct
4 Correct 27 ms 6236 KB Output is correct
5 Correct 40 ms 7052 KB Output is correct
6 Correct 23 ms 5724 KB Output is correct
7 Correct 45 ms 7264 KB Output is correct
8 Correct 39 ms 7260 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 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 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 22 ms 4736 KB Output is correct
24 Correct 28 ms 7248 KB Output is correct
25 Correct 65 ms 10580 KB Output is correct
26 Correct 39 ms 7944 KB Output is correct
27 Correct 32 ms 7504 KB Output is correct
28 Correct 66 ms 10836 KB Output is correct
29 Correct 57 ms 10320 KB Output is correct
30 Correct 32 ms 5712 KB Output is correct
31 Correct 59 ms 10836 KB Output is correct