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>
using namespace std;
int N, Q;
vector<int> A;
vector<array<int, 3>> query;
int ans[1000005];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> N >> Q; A.resize(N);
for(int l = 0; l < N; l++)
cin >> A[l];
for(int l = 0; l < Q; l++) {
int t, i; cin >> t >> i;
query.push_back({t, l, --i});
}
sort(query.begin(), query.end());
bool ok = false; int cur = 0, cnt = 1;
while(cur < Q && query[cur][0] == 0) {
ans[query[cur][1]] = A[query[cur][2]];
cur++;
}
while(!ok) {
ok = true;
vector<int> B;
int i = 0, j = N / 2;
while(B.size() < N) {
if(i == N / 2)
B.push_back(A[j++]);
else if(j == N) B.push_back(A[i++]);
else {
if(A[i] < A[j])
B.push_back(A[i++]);
else {
B.push_back(A[j++]);
ok = false;
}
}
}
swap(A, B);
while(cur < Q && (query[cur][0] == cnt || ok == true)) {
ans[query[cur][1]] = A[query[cur][2]];
cur++;
}
cnt++;
}
for(int l = 0; l < Q; l++)
cout << ans[l] << "\n";
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:30:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | while(B.size() < 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... |