Submission #1221626

#TimeUsernameProblemLanguageResultExecution timeMemory
1221626minggaIntercastellar (JOI22_ho_t1)C++20
100 / 100
41 ms5444 KiB
#include "bits/stdc++.h"

using namespace std;

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define int long long
const int mod = 1e9 + 7;
const int inf = 2e18;
const int N = 2e5 + 7;
int n, q;
pair<int, int> d[N];

signed main() {
	cin.tie(0) -> sync_with_stdio(0);
	#define task ""
	if(fopen(task ".INP", "r")) {
		freopen(task ".INP", "r", stdin);
		freopen(task ".OUT", "w", stdout);
	}
	cin >> n;
	for(int i = 1; i <= n; i++) {
		int x; cin >> x;
		int cnt = 0;
		for(int j = 0; (1 << j) <= x; j++) {
			if(x >> j & 1) break;
			cnt++;
		}
		d[i] = {(1 << (cnt)), (x >> cnt)};
		// cerr << i << ' ' << d[i].fi << ' ' << d[i].se << ln;
	}
	cin >> q;
	int cur = 0;
	int id = 0;
	for(int i = 1; i <= q; i++) {
		int x; cin >> x;
		x -= cur;
		while(id < n and x > d[id].fi) x -= d[id].fi, cur += d[id++].fi;
		cout << d[id].se << ln;
	}
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

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