Submission #816544

# Submission time Handle Problem Language Result Execution time Memory
816544 2023-08-09T05:35:54 Z vjudge1 Intercastellar (JOI22_ho_t1) C++17
100 / 100
71 ms 9228 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
  #include "/home/trucmai/.vim/tools.h"
  #define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
  #else
  #define debug(x...)
#endif

void open(){
  if(fopen("i.inp","r")){
    freopen("i.inp","r",stdin);
    freopen("o.out","w",stdout);
  }
}

#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "

const int MN = 1e6 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,q,a[MN],len[MN],cnt;
void solve(){
  cin>>n;
  for(ll i = 1;i <= n;++i){
    cnt = 1;
    cin>>a[i]; 
    if(a[i] % 2 == 0){
      while(a[i] % 2 == 0){
        a[i] /= 2;
        cnt *= 2;
      }
    }
    len[i] = len[i-1] + cnt;
  }
  cin>>q;
  while(q--){
    ll x; cin>>x;
    ll l = 1,r = n,res = -1;
    while(l <= r){ 
      ll m = (r+l) >> 1; 
      if(len[m] >= x){
        r = m - 1; 
        res = a[m];
      }else l = m + 1;
    }
    cout<<res<<endl;
  }
}

signed main(){
  cin.tie(0) -> sync_with_stdio(0);
  open();
  ll t = 1; //cin>>t;
  while(t--) solve(); 
  
  #ifdef LOCAL
    cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}

Compilation message

Main.cpp: In function 'void open()':
Main.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("i.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("o.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 16 ms 4012 KB Output is correct
4 Correct 26 ms 2344 KB Output is correct
5 Correct 39 ms 5460 KB Output is correct
6 Correct 23 ms 4040 KB Output is correct
7 Correct 38 ms 5548 KB Output is correct
8 Correct 38 ms 5580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 356 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 16 ms 4012 KB Output is correct
4 Correct 26 ms 2344 KB Output is correct
5 Correct 39 ms 5460 KB Output is correct
6 Correct 23 ms 4040 KB Output is correct
7 Correct 38 ms 5548 KB Output is correct
8 Correct 38 ms 5580 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 356 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 22 ms 3056 KB Output is correct
24 Correct 27 ms 5220 KB Output is correct
25 Correct 52 ms 8696 KB Output is correct
26 Correct 35 ms 5580 KB Output is correct
27 Correct 33 ms 5548 KB Output is correct
28 Correct 71 ms 9228 KB Output is correct
29 Correct 66 ms 8692 KB Output is correct
30 Correct 29 ms 3660 KB Output is correct
31 Correct 61 ms 9156 KB Output is correct