Submission #1349252

#TimeUsernameProblemLanguageResultExecution timeMemory
1349252NikoBaoticOGLEDALA (COI15_ogledala)C++20
0 / 100
2 ms344 KiB
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

#define all(x) x.begin(), x.end()
#define sz(x) ((int) ((x).size()))
#define pb push_back
#define F first
#define S second
#define FIO ios_base::sync_with_stdio(false); cin.tie(0)

const int N = 3e5 + 10;

int n, m, q;
ll a[N];
ll cur;
set<pair<pii, pii>> s;
ll b[N];

void add(ll val, ll pos, ll dep, ll cnt) {
	if (val == 0) return;
	auto iter = s.lower_bound({{val, pos}, {dep, cnt}});
	if (!(iter == s.end() or iter->F.F != val or iter->F.S != pos or iter->S.F != dep)) {
		cnt += iter->S.S;
		s.erase(iter);
	}
	s.insert({{val, pos}, {dep, cnt}});
}

ll find(ll val, ll dep, ll x, ll cnt) {
	if (dep == 0) return 0;
	//cout << "VAL: " << val << " DEP: " << dep << " X: " << x << " CNT: " << cnt << endl;

	//ll cntL = (((val - (1LL << dep) - 1) % (1LL << dep))) / 2;
	//cout << "CNTL: " << cntL << endl;

	//if (!t) cntL = (1LL << (dep - 1)) - cntL;
	//cout << "CNTL: " << cntL << endl;

	if (x <= cnt / 2) {
		//cout << "L" << endl;
		return find((val - 1) / 2, dep - 1, x, cnt / 2);
	} else {
		//cout << "R" << endl;
		//cout << "HERE " << 
		return find(val / 2, dep - 1, x - cnt, (cnt + 1) / 2) + (val - 1) / 2 + 1;
	}
}

int main() {
	FIO;

	cin >> m >> n >> q;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	a[0] = 0;
	a[n + 1] = m + 1;

	for (int i = 0; i <= n; i++) {
		b[i] = a[i + 1] - a[i] - 1;
		add(-b[i], i, 0, 1);
	}
	
	cur = n;

	for (int i = 0; i < q; i++) {
		ll t;
		cin >> t;

		if (t <= n) {
			cout << a[t] << '\n';
		} else {
			while (sz(s) and t > cur + s.begin()->S.S) {
				ll cnt = s.begin()->S.S;
				ll dep = s.begin()->S.F;
				ll pos = s.begin()->F.S;
				ll val = -s.begin()->F.F;

				s.erase(s.begin());

				if (val % 2 == 0) {
					add(-(val / 2), pos, dep + 1, cnt);
					add(-((val - 1) / 2), pos, dep + 1, cnt);
				} else {
					add(-(val / 2), pos, dep + 1, cnt * 2);
				}

				//cout << "RASP val: "  << val << " " << pos << " cnt: " << cnt << endl;
				cur += cnt;
			}
			//cout << "CUR IS " << cur << endl;

			ll dep = s.begin()->S.F;
			ll ind = s.begin()->F.S;
			ll val = -s.begin()->F.F;
			ll cnt = s.begin()->S.S;
			//cout << "RAZ AT " << ind  << " " << a[ind] << " " << val << " CNT: " << cnt << endl;
			//cout << "RET " << find(b[ind], dep, t - cur, cnt) << endl;

			//cout << "ANS:" << endl;
			cout << a[ind] + find(b[ind], dep, t - cur, cnt) + (val + 1) / 2 << '\n';
		}
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...