#include <bits/stdc++.h>
using namespace std ;
const int MAX = 1e5 + 10 ;
int arr[MAX] ;
int n , q ;
vector<int>v ;
vector<int>ans[MAX] ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>q ;
v.resize(n) ;
for(auto &x : v)
cin>>x ;
ans[0] = v ;
int last = 0 ;
for(int k = 1 ; ; ++k)
{
vector<int>v2[2] ;
for(int i = n-1 ; i >= 0 ; --i)
v2[(i >= n/2)].push_back(ans[k-1][i]) ;
for(int i = 0 ; i < n ; ++i)
{
bool t = 0 ;
if((!v2[0].size()) || (v2[1].size() && v2[0].back() > v2[1].back()))
t = 1 ;
ans[k].push_back(v2[t].back()) ;
v2[t].pop_back() ;
}
last = k ;
if(ans[k] == ans[k-1])
break ;
}
assert(last <= n) ;
while(q--)
{
int t , idx ;
cin>>t>>idx ;
t = min(t , last) ;
cout<<ans[t][idx-1]<<"\n" ;
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
11084 KB |
Output is correct |
2 |
Correct |
158 ms |
8196 KB |
Output is correct |
3 |
Correct |
158 ms |
8908 KB |
Output is correct |
4 |
Correct |
154 ms |
7156 KB |
Output is correct |
5 |
Correct |
157 ms |
7836 KB |
Output is correct |
6 |
Correct |
155 ms |
7456 KB |
Output is correct |
7 |
Correct |
185 ms |
7956 KB |
Output is correct |
8 |
Correct |
148 ms |
7304 KB |
Output is correct |
9 |
Correct |
153 ms |
7148 KB |
Output is correct |
10 |
Correct |
153 ms |
7232 KB |
Output is correct |
11 |
Correct |
149 ms |
7244 KB |
Output is correct |
12 |
Correct |
142 ms |
6944 KB |
Output is correct |
13 |
Correct |
146 ms |
7072 KB |
Output is correct |
14 |
Correct |
158 ms |
7712 KB |
Output is correct |
15 |
Correct |
154 ms |
7224 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
143 ms |
7068 KB |
Output is correct |
18 |
Correct |
145 ms |
7052 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1793 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1795 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
193 ms |
11084 KB |
Output is correct |
2 |
Correct |
158 ms |
8196 KB |
Output is correct |
3 |
Correct |
158 ms |
8908 KB |
Output is correct |
4 |
Correct |
154 ms |
7156 KB |
Output is correct |
5 |
Correct |
157 ms |
7836 KB |
Output is correct |
6 |
Correct |
155 ms |
7456 KB |
Output is correct |
7 |
Correct |
185 ms |
7956 KB |
Output is correct |
8 |
Correct |
148 ms |
7304 KB |
Output is correct |
9 |
Correct |
153 ms |
7148 KB |
Output is correct |
10 |
Correct |
153 ms |
7232 KB |
Output is correct |
11 |
Correct |
149 ms |
7244 KB |
Output is correct |
12 |
Correct |
142 ms |
6944 KB |
Output is correct |
13 |
Correct |
146 ms |
7072 KB |
Output is correct |
14 |
Correct |
158 ms |
7712 KB |
Output is correct |
15 |
Correct |
154 ms |
7224 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
143 ms |
7068 KB |
Output is correct |
18 |
Correct |
145 ms |
7052 KB |
Output is correct |
19 |
Correct |
1 ms |
2644 KB |
Output is correct |
20 |
Correct |
1 ms |
2672 KB |
Output is correct |
21 |
Runtime error |
1793 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |