제출 #1335418

#제출 시각아이디문제언어결과실행 시간메모리
1335418franuchAbracadabra (CEOI22_abracadabra)C++20
0 / 100
3096 ms35972 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define vc vector
#define st first
#define nd second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)a.size()
#define pub push_back
#define pob pop_back

struct Que {
	ll t, i, id;
};

ll n, q;
vc<ll> a;
vc<Que> ques;

void input() {
	cin >> n >> q;
	a.resize(n);
	for (ll &ai : a)
		cin >> ai;
	ques.resize(q);
	for (ll i = 0; i < q; i++) {
		auto &que = ques[i];
		cin >> que.t >> que.i;
		que.i--;
		que.id = i;
	}
}

void apply() {
	vc<ll> p, q;
	for (ll i = n - 1; i >= n / 2; i--)
		p.pub(a[i]);
	for (ll i = n / 2 - 1; i >= 0; i--)
		q.pub(a[i]);
	a.clear();
	a.reserve(n);
	while (not p.empty() or not q.empty()) {
		if (p.empty())
			a.pub(q.back()), q.pob();
		else if (q.empty())
			a.pub(p.back()), p.pob();
		else if (p.back() <= q.back())
			a.pub(p.back()), p.pob();
		else
			a.pub(q.back()), q.pob();
	}
}

void sweep() {
	vc<ll> res(q);
	sort(all(ques), [](auto &p, auto &q) {
		return p.t < q.t;
	});
	ll cnt = 0;
	for (auto &que : ques) {
		while (cnt < que.t) {
			apply();
			cnt++;
		}
		res[que.id] = a[que.i];
	}
	for (ll x : res)
		cout << x << "\n";
}

void program() {
	input();
	sweep();
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	program();
	return 0;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...