#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(ll i=a,ceoi=b;i<ceoi;i++)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define imp(v) for(auto kdjfhg:v)cout<<kdjfhg<<" ";cout<<"\n"
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
vector<ll> f(vector<ll>a){
vector<ll>l,r;
ll n=SZ(a);
fore(i,0,n/2)l.pb(a[i]);
fore(i,n/2,n)r.pb(a[i]);
vector<ll>b;
reverse(ALL(l)); reverse(ALL(r));
while(SZ(l)+SZ(r)){
if(!SZ(r)||(SZ(l)&&l.back()<r.back()))b.pb(l.back()),l.pop_back();
else b.pb(r.back()),r.pop_back();
}
return b;
}
int main(){FIN;
ll n,q; cin>>n>>q;
vector<ll>a(n);
fore(i,0,n)cin>>a[i],a[i]--;
vector<vector<ll>>b={a};
while(1){
auto a_=f(a);
if(a_==a)break;
a=a_;
b.pb(a);
}
assert(SZ(b)<=n+5);
while(q--){
ll t,i; cin>>t>>i; i--;
t=min(t,(ll)SZ(b)-1);
cout<<b[t][i]+1<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
19792 KB |
Output is correct |
2 |
Correct |
166 ms |
13668 KB |
Output is correct |
3 |
Correct |
158 ms |
15148 KB |
Output is correct |
4 |
Correct |
140 ms |
10384 KB |
Output is correct |
5 |
Correct |
157 ms |
12772 KB |
Output is correct |
6 |
Correct |
149 ms |
11344 KB |
Output is correct |
7 |
Correct |
164 ms |
13136 KB |
Output is correct |
8 |
Correct |
144 ms |
11116 KB |
Output is correct |
9 |
Correct |
144 ms |
10752 KB |
Output is correct |
10 |
Correct |
152 ms |
11076 KB |
Output is correct |
11 |
Correct |
145 ms |
11092 KB |
Output is correct |
12 |
Correct |
146 ms |
9556 KB |
Output is correct |
13 |
Correct |
147 ms |
10320 KB |
Output is correct |
14 |
Correct |
154 ms |
11936 KB |
Output is correct |
15 |
Correct |
153 ms |
11020 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
135 ms |
9880 KB |
Output is correct |
18 |
Correct |
140 ms |
9808 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
887 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
812 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
19792 KB |
Output is correct |
2 |
Correct |
166 ms |
13668 KB |
Output is correct |
3 |
Correct |
158 ms |
15148 KB |
Output is correct |
4 |
Correct |
140 ms |
10384 KB |
Output is correct |
5 |
Correct |
157 ms |
12772 KB |
Output is correct |
6 |
Correct |
149 ms |
11344 KB |
Output is correct |
7 |
Correct |
164 ms |
13136 KB |
Output is correct |
8 |
Correct |
144 ms |
11116 KB |
Output is correct |
9 |
Correct |
144 ms |
10752 KB |
Output is correct |
10 |
Correct |
152 ms |
11076 KB |
Output is correct |
11 |
Correct |
145 ms |
11092 KB |
Output is correct |
12 |
Correct |
146 ms |
9556 KB |
Output is correct |
13 |
Correct |
147 ms |
10320 KB |
Output is correct |
14 |
Correct |
154 ms |
11936 KB |
Output is correct |
15 |
Correct |
153 ms |
11020 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
135 ms |
9880 KB |
Output is correct |
18 |
Correct |
140 ms |
9808 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Runtime error |
887 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |