Submission #949051

#TimeUsernameProblemLanguageResultExecution timeMemory
949051TAhmed33Abracadabra (CEOI22_abracadabra)C++98
10 / 100
1498 ms15564 KiB
#include <bits/stdc++.h>
using namespace std;
int dd[1002][1001];
int n, q;
int main () {
	cin >> n >> q;
	for (int i = 1; i <= n; i++) cin >> dd[0][i];	
	for (int i = 1; i <= n; i++) {
		deque <int> a, b;
		for (int j = 1; j <= n / 2; j++) a.push_back(dd[i - 1][j]);
		for (int j = n / 2 + 1; j <= n; j++) b.push_back(dd[i - 1][j]);
		int c = 0;
		while (!a.empty() && !b.empty()) {
			if (a.front() < b.front()) {
				dd[i][++c] = a.front(); a.pop_front();
			} else {
				dd[i][++c] = b.front(); b.pop_front();
			}
		}
		while (!a.empty()) dd[i][++c] = a.front(), a.pop_front();
		while (!b.empty()) dd[i][++c] = b.front(), b.pop_front();
	}
	while (q--) {
		int x, y; cin >> x >> y;
		x = min(x, n);
		cout << dd[x][y] << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...