This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e9+500;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n,m,q;
vector<int> a;
bool f1 = 0;
void move() {
if(f1) return;
vector<int> tmp(1, 0);
int i = 1, j = n / 2 + 1;
while(i <= n / 2 && j <= n) {
if(a[i] < a[j]) {
tmp.pb(a[i]);
i++;
}
else {
tmp.pb(a[j]);
j++;
}
}
while(i <= n / 2) {
tmp.pb(a[i]);
i++;
}
while(j <= n) {
tmp.pb(a[j]);
j++;
}
if(tmp == a) f1 = 1;;
a = tmp;
return;
}
inline void solve() {
cin>>n>>q;
a.resize(n + 1);
for(int i = 1; i<=n; i++) cin >> a[i];
vector<array<int,3> > qu;
qu.resize(q);
REP(i, q) {
cin >> qu[i][0] >> qu[i][1];
qu[i][2] = i;
}
sort(all(qu));
vector<int> res(q);
int t = 0;
for(auto &c : qu) {
while(t < c[0]) {
if(f1) {
t = c[0];
break;
}
move();
t++;
}
res[c[2]] = a[c[1]];
}
REP(i, q) cout << res[i] << "\n";
}
signed main() {
fastio();
int test = 1;
//cin>>test;
while(test--) {
solve();
}
}
# | 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... |