This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q; cin >> n >> q;
vector<int> v(n);
for(int &x: v) cin >> x, x--;
vector<tuple<int, int, int>> queries;
for(int i = 0; i < q; i++){
int t, I; cin >> t >> I; I--;
queries.pb({t, I, i});
}
sort(queries.begin(), queries.end());
vector<int> ans(q);
auto it = queries.begin();
int c = 0;
while(it != queries.end() && get<0>(*it) == 0) ans[get<2>(*it)] = v[get<1>(*it)], it++;
while(1){
auto _v = v;
merge(_v.begin(), _v.begin()+n/2, _v.begin()+n/2, _v.begin()+n, v.begin());
c++;
while(it != queries.end() && get<0>(*it) <= c) ans[get<2>(*it)] = v[get<1>(*it)], it++;
if(v == _v) break;
}
while(it != queries.end()) ans[get<2>(*it)] = v[get<1>(*it)], it++;
for(int x: ans) cout << x+1 << "\n";
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |