/***********************************************
* auth: tapilyoca *
* date: 07/07/2025 at 22:42:20 *
* dots: https://github.com/tapilyoca/dotilyoca *
***********************************************/
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
template<typename T>
using vec = vector<T>;
using ll = long long;
using vll = vec<ll>;
using vvll = vec<vll>;
using pll = pair<ll,ll>;
using str = string;
#define pb push_back
#define dbg(x) if(1) cerr << #x << ": " << x << endl;
/***********************************************/
vll riffle(vll &at) {
vll a, b;
ll n = at.size();
for(int i = 0; i < n/2; i++) {
a.pb(at[i]);
}
for(int j = n/2; j < n; j++) {
b.pb(at[j]);
}
vll out;
ll lp = 0, rp = 0;
while(lp != n/2 and rp != n/2) {
if(a[lp] < b[rp]) {
out.pb(a[lp]);
lp++;
} else {
out.pb(b[rp]);
rp++;
}
}
for(int i = lp; i < n/2; i++) out.pb(a[i]);
for(int i = rp; i < n/2; i++) out.pb(b[i]);
return out;
}
void solve() {
ll n, q;
cin >> n >> q;
vvll state(n+1, vll(n,0));
for(int i = 0; i < n; i++) {
cin >> state[0][i];
}
for(int i = 1; i <= n; i++) {
state[i] = riffle(state[i-1]);
}
while(q--) {
ll t, x;
cin >> t >> x;
x--;
t = min(n,t);
cout << state[t][x] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while(t--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |