#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n,q;
cin >> n >> q;
vector <int> v(n);
int mini = 200000;
vector <int> que[n*n];
for(int i = 0;i < n;i++){
cin >> v[i];
que[0].push_back(v[i]);
if(i < n/2){
mini = min(mini,v[i]);
}
}
int num = 1;
while(num < n*n){
vector<int> v1(n/2);
vector<int> v2(n/2);
for(int i = 0;i < n/2;i++){
v1[i] = v[i];
v2[i] = v[i+n/2];
}
int ind1 = 0;
int ind2 = 0;
while(ind1 < n/2 && ind2 < n/2){
if(v1[ind1] < v2[ind2]){
v[ind1+ind2] = v1[ind1];
ind1++;
}else{
v[ind1+ind2] = v2[ind2];
ind2++;
}
}
if(ind1 < n/2){
for(int i = ind1;i < n/2;i++){
v[i+ind2] = v1[i];
}
}else{
for(int i = ind2;i < n/2;i++){
v[i+ind1] = v2[i];
}
}
bool same = true;
for(int i = 0;i < n;i++){
que[num].push_back(v[i]);
if(que[num][i] != que[num-1][i]){
same = false;
}
}
num++;
if(!same){
break;
}
}
for(int i = 0;i < q;i++){
int a,b;
cin >> a >> b;
if(a >= num){
cout << que[num-1][b-1] << "\n";
}else {
cout << que[a][b - 1] << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
163 ms |
29780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
327 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
254 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
163 ms |
29780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |