Submission #1168832

#TimeUsernameProblemLanguageResultExecution timeMemory
1168832CrabCNHIntercastellar (JOI22_ho_t1)C++20
100 / 100
46 ms5448 KiB
#include <bits/stdc++.h> #define task "BriantheCrab" #define int long long #define pii pair <int, int> #define fi first #define se second #define szf sizeof #define sz(s) (int)((s).size()) using namespace std; template <class T> void mini (T &t, T f) {if (t > f) t = f;} template <class T> void maxi (T &t, T f) {if (t < f) t = f;} const int maxN = 2e5 + 5; const int inf = 1e18 + 7; const int mod = 1e9 + 7; int a[maxN], d[maxN]; void solve () { int n; cin >> n; for (int i = 1; i <= n; i ++) { int x; cin >> x; d[i] = d[i - 1]; int cur = 0; while (x % 2 == 0) { x /= 2; cur++; } d[i] += (1 << cur); a[i] = x; } // for (int i = 1; i <= n; i ++) { // cout << d[i] << ' '; // } //cout << '\n'; int q; cin >> q; while (q --) { int x; cin >> x; int l = 1, r = n, pos = -1; while (true) { if (l > r) { break; } int mid = (l + r) >> 1; //cout << l << ' ' << r << ' ' << mid << ' ' << d[mid] << '\n'; if (d[mid] >= x) { pos = mid; r = mid - 1; } else { l = mid + 1; } } //cout << pos << ' '; cout << a[pos] << '\n'; } } signed main () { cin.tie (nullptr) -> sync_with_stdio (false); if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } int t = 1; //cin >> t; while (t --) { solve (); } return 0; } // thfdgb

Compilation message (stderr)

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