제출 #1349280

#제출 시각아이디문제언어결과실행 시간메모리
1349280TobOGLEDALA (COI15_ogledala)C++20
100 / 100
1632 ms19996 KiB
#include <bits/stdc++.h>

#define F first
#define S second
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef unordered_map <ll, ll> um;

const int N = 1e5 + 7;

ll m;
int n, q;
ll a[N], b[N], d[N], h[N];
int w[N];
map <pll, ll> s;
um f;

ll calc(ll x, ll y) {
	if (f.find(x) != f.end()) return f[x];
	if (x <= y) return f[x] = (x == y);
	return f[x] = calc((x-1)/2, y)+calc(x/2, y);
}

ll find(ll x, ll y, ll d) {
	if (x == y) return (x+1)/2;
	ll dd = calc((x-1)/2, y);
	if (dd <= d) return (x-1)/2+1+find(x/2, y, d-dd);
	return find((x-1)/2, y, d);
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> m >> n >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[n+1] = m+1;
	for (int i = 0; i < q; i++) cin >> b[i];
	for (int i = 1; i <= n+1; i++) s[{a[i]-a[i-1]-1, -i+1}]++;
	ll cur = n;
	int qc = 0;
	while (qc < q && b[qc] <= n) qc++;
	while (sz(s)) {
		auto p = --s.end();
		pll x = p->F;
		ll c = p->S;
		s.erase(p);
		while (qc < q && b[qc] <= cur+c) {
			d[qc] = b[qc]-cur-1;
			h[qc] = x.F;
			w[qc] = -x.S;
			qc++;
		}
		cur += c;
		if (x.F > 2) s[{(x.F-1)/2, x.S}] += c;
		if (x.F) s[{x.F/2, x.S}] += c;
	}
	
	for (int i = 0; i < q; i++) {
		f.clear();
		if (b[i] <= n) cout << a[b[i]] << "\n";
		else cout << a[w[i]]+find(a[w[i]+1]-a[w[i]]-1, h[i], d[i]) << "\n";
	}

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