#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)2e5 + 10;
void shuffle(vector<int> &P){
queue<int> A, B;
for(int i = 0 ; i < P.size(); i ++ ){
if(i < P.size() / 2) A.push(P[i]);
else B.push(P[i]);
}
vector<int> nex;
while(!A.empty() || !B.empty()){
if(A.empty()){
nex.push_back(B.front());
B.pop();
}
else if(B.empty()){
nex.push_back(A.front());
A.pop();
}
else {
if(A.front() < B.front()){
nex.push_back(A.front());
A.pop();
}
else{
nex.push_back(B.front());
B.pop();
}
}
}
swap(P, nex);
}
vector<pii> qq[N]; // {index, idx}
int res[N];
int main(){
fastIO;
//freopen("in.txt", "r", stdin);
int n, q;
cin >> n >> q;
vector<int> P(n);
for(int i = 0 ; i < n; i ++ ){
cin >> P[i];
}
int t, id;
for(int iq = 1; iq <= q; iq ++ ){
cin >> t >> id;
t=min(t,n);
qq[t].push_back(mp(id, iq));
}
for(int i = 0 ; i <= n; i ++ ){
if(i) shuffle(P);
for(auto x : qq[i]){
res[x.se] = P[x.fi-1];
}
}
for(int iq = 1; iq <= q; iq ++ ){
cout << res[iq] << "\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'void shuffle(std::vector<int>&)':
Main.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i = 0 ; i < P.size(); i ++ ){
| ~~^~~~~~~~~~
Main.cpp:18:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if(i < P.size() / 2) A.push(P[i]);
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
139 ms |
39884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
31700 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
11508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
139 ms |
39884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |