Submission #1247837

#TimeUsernameProblemLanguageResultExecution timeMemory
1247837Bui_Quoc_CuongIntercastellar (JOI22_ho_t1)C++20
100 / 100
44 ms5444 KiB
#include <bits/stdc++.h> using namespace std; // #define int long long typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; template<class T> bool minimize(T &a, const T &b) { if (a > b) return a = b, true; return false; } template<class T> bool maximize(T &a, const T &b) { if (a < b) return a = b, true; return false; } #define FOR(i, a, b) for (int i = a; i <= (int)b; i++) #define FORD(i, a, b) for (int i = a; i >= (int)b; i--) #define MASK(i) (1LL << (i)) #define BIT(S, i) (((S) >> (i)) & 1) #define mp make_pair #define pb push_back #define fi first #define se second #define all(x) x.begin(), x.end() const int N = 5e5 + 5; int n, q; int a[N]; void init(void) { cin >> n; FOR(i, 1, n) cin >> a[i]; cin >> q; } long long pre[N]; int b[N]; long long pw2[N]; void process(void) { pw2[0] = 1; FOR(i, 1, 32) pw2[i] = 1LL * pw2[i - 1] * 2; FOR(i, 1, n) { int cnt = 0; while (a[i] % 2 == 0) { cnt++; a[i] /= 2; } pre[i] = pre[i - 1] + pw2[cnt]; b[i] = a[i]; } // FOR(i, 1, n) cout << pre[i] << " "; // FOR(i, 1, n) cout << b[i] << " "; while (q--) { long long X; cin >> X; int l = 1, r = n, ans = 0; while (l <= r) { int mid = (l + r) >> 1; if (pre[mid] < X) ans = mid, l = mid + 1; else r = mid - 1; } cout << b[ans + 1] << "\n"; } } signed main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); #define taskname "kieuoanh" if (fopen(taskname".inp", "r")) { freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } init(); process(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(taskname".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...