#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
int n,q;
vector<vector<int>> v;
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>q;
v.pb({});
v[0].resize(n);
for (int i=0;i<n;i++) cin>>v[0][i];
for (int k=1;k<=n;k++){
vector<int> b;
int i=0,j=n/2;
while (i<n/2 && j<n){
if (v.back()[i]<v.back()[j]) b.pb(v.back()[i++]);
else b.pb(v.back()[j++]);
}
while (i<n/2) b.pb(v.back()[i++]);
while (j<n) b.pb(v.back()[j++]);
v.pb(b);
bool ok=true;
for (int i=0;i<n/2;i++) ok&=(b[i]==i+1);
if (ok) break;
}
while (q--){
int t,i;
cin>>t>>i;
t=min(t,(int)v.size()-1);
cout<<v[t][i-1]<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
16412 KB |
Output is correct |
2 |
Correct |
174 ms |
13648 KB |
Output is correct |
3 |
Correct |
149 ms |
14960 KB |
Output is correct |
4 |
Correct |
133 ms |
17748 KB |
Output is correct |
5 |
Correct |
152 ms |
19280 KB |
Output is correct |
6 |
Correct |
140 ms |
17692 KB |
Output is correct |
7 |
Correct |
157 ms |
19280 KB |
Output is correct |
8 |
Correct |
144 ms |
17628 KB |
Output is correct |
9 |
Correct |
155 ms |
18008 KB |
Output is correct |
10 |
Correct |
211 ms |
17748 KB |
Output is correct |
11 |
Correct |
138 ms |
18280 KB |
Output is correct |
12 |
Correct |
123 ms |
16724 KB |
Output is correct |
13 |
Correct |
144 ms |
17512 KB |
Output is correct |
14 |
Correct |
149 ms |
18516 KB |
Output is correct |
15 |
Correct |
148 ms |
18072 KB |
Output is correct |
16 |
Correct |
5 ms |
8024 KB |
Output is correct |
17 |
Correct |
119 ms |
9812 KB |
Output is correct |
18 |
Correct |
126 ms |
16976 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
635 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
584 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
16412 KB |
Output is correct |
2 |
Correct |
174 ms |
13648 KB |
Output is correct |
3 |
Correct |
149 ms |
14960 KB |
Output is correct |
4 |
Correct |
133 ms |
17748 KB |
Output is correct |
5 |
Correct |
152 ms |
19280 KB |
Output is correct |
6 |
Correct |
140 ms |
17692 KB |
Output is correct |
7 |
Correct |
157 ms |
19280 KB |
Output is correct |
8 |
Correct |
144 ms |
17628 KB |
Output is correct |
9 |
Correct |
155 ms |
18008 KB |
Output is correct |
10 |
Correct |
211 ms |
17748 KB |
Output is correct |
11 |
Correct |
138 ms |
18280 KB |
Output is correct |
12 |
Correct |
123 ms |
16724 KB |
Output is correct |
13 |
Correct |
144 ms |
17512 KB |
Output is correct |
14 |
Correct |
149 ms |
18516 KB |
Output is correct |
15 |
Correct |
148 ms |
18072 KB |
Output is correct |
16 |
Correct |
5 ms |
8024 KB |
Output is correct |
17 |
Correct |
119 ms |
9812 KB |
Output is correct |
18 |
Correct |
126 ms |
16976 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Runtime error |
635 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |