#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<limits.h>
#include<math.h>
#include<iomanip>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<cstring>
#include<sstream>
#pragma GCC target("popcnt")
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
typedef pair<ll,ll>point;
//#define x first
//#define y second
struct Query{
int i,t;
int index,ans;
};
int n,q;
vector<int>deck;
Query queries[1000000];
void shuffle(){
vector<int>d1,d2;
for(int i=0;i<n/2;i++)
d1.push_back(deck[i]);
for(int i=n/2;i<n;i++)
d2.push_back(deck[i]);
d1.push_back(1000000);
d2.push_back(1000000);
int i1=0,i2=0;
deck.clear();
while(deck.size()<n){
if(d1[i1]>d2[i2]){
deck.push_back(d2[i2++]);
}else if(d1[i1]<d2[i2]){
deck.push_back(d1[i1++]);
}
}
}
int get(int i){
return deck[i];
}
bool cmp1(Query&a,Query&b){
return a.t<b.t;
}
bool cmp2(Query&a,Query&b){
return a.index<b.index;
}
int main(){
ios::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
cin>>n>>q;
deck.resize(n);
for(int&i:deck)
cin>>i;
for(int i=0;i<q;i++){
cin>>queries[i].t>>queries[i].i;
queries[i].i--;
queries[i].index=i;
queries[i].t=min(queries[i].t,n);
}
sort(queries,queries+q,cmp1);
int cq=0;
for(int cs=0;cs<=n;cs++){
while(cq<q&&queries[cq].t==cs){
queries[cq].ans=get(queries[cq].i);
cq++;
}
shuffle();
}
sort(queries,queries+q,cmp2);
for(int i=0;i<q;i++)
cout<<queries[i].ans<<"\n";
return 0;
}
/*
6 3
1 5 6 2 3 4
1 2
0 4
1 5
2
2
5
6 6
2 1 5 4 6 3
0 1
1 1
0 3
1 3
0 6
10 6
2
2
5
4
3
3
*/
Compilation message
Main.cpp: In function 'void shuffle()':
Main.cpp:47:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | while(deck.size()<n){
| ~~~~~~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
19820 KB |
Output is correct |
2 |
Correct |
306 ms |
23776 KB |
Output is correct |
3 |
Correct |
299 ms |
22972 KB |
Output is correct |
4 |
Correct |
274 ms |
22352 KB |
Output is correct |
5 |
Correct |
308 ms |
23760 KB |
Output is correct |
6 |
Correct |
280 ms |
22608 KB |
Output is correct |
7 |
Correct |
307 ms |
23888 KB |
Output is correct |
8 |
Correct |
277 ms |
22608 KB |
Output is correct |
9 |
Correct |
287 ms |
22364 KB |
Output is correct |
10 |
Correct |
290 ms |
22864 KB |
Output is correct |
11 |
Correct |
277 ms |
22784 KB |
Output is correct |
12 |
Correct |
258 ms |
21972 KB |
Output is correct |
13 |
Correct |
282 ms |
22656 KB |
Output is correct |
14 |
Correct |
291 ms |
23224 KB |
Output is correct |
15 |
Correct |
284 ms |
23404 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
206 ms |
22236 KB |
Output is correct |
18 |
Correct |
238 ms |
22096 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3003 ms |
32896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3032 ms |
5940 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
19820 KB |
Output is correct |
2 |
Correct |
306 ms |
23776 KB |
Output is correct |
3 |
Correct |
299 ms |
22972 KB |
Output is correct |
4 |
Correct |
274 ms |
22352 KB |
Output is correct |
5 |
Correct |
308 ms |
23760 KB |
Output is correct |
6 |
Correct |
280 ms |
22608 KB |
Output is correct |
7 |
Correct |
307 ms |
23888 KB |
Output is correct |
8 |
Correct |
277 ms |
22608 KB |
Output is correct |
9 |
Correct |
287 ms |
22364 KB |
Output is correct |
10 |
Correct |
290 ms |
22864 KB |
Output is correct |
11 |
Correct |
277 ms |
22784 KB |
Output is correct |
12 |
Correct |
258 ms |
21972 KB |
Output is correct |
13 |
Correct |
282 ms |
22656 KB |
Output is correct |
14 |
Correct |
291 ms |
23224 KB |
Output is correct |
15 |
Correct |
284 ms |
23404 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
206 ms |
22236 KB |
Output is correct |
18 |
Correct |
238 ms |
22096 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
3003 ms |
32896 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |