#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,l,r) for(int i=l; i<r; i++)
#define all(x) x.begin(),x.end()
#define len(x) (int)x.size();
#define fi first
#define se second
#define elif else if
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
constexpr ll LINF=1001001001001001001LL;
constexpr ll MINF=1001001001001LL;
constexpr int INF=1001001001;
int N;
vi riffle(vi p){
int lf=0;
int ri=N/2;
vi ret(N);
rep(i,N){
if(lf==N/2||(ri!=N&&p[lf]>p[ri])){
ret[i]=p[ri];
ri++;
}
else{
ret[i]=p[lf];
lf++;
}
}
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin>>N>>Q;
vi P(N);
rep(i,N)cin>>P[i];
vector<vector<pii>> query(N);
rep(i,Q){
int t,p;
cin>>t>>p;
query[min(N-1,t)].emplace_back(i,p-1);
}
vi ans(Q);
rep(i,N){
for(auto &[j,p]:query[i]){
ans[j]=P[p];
}
P=riffle(P);
}
for(int i:ans)cout<<i<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
26092 KB |
Output is correct |
2 |
Correct |
125 ms |
24524 KB |
Output is correct |
3 |
Correct |
119 ms |
24028 KB |
Output is correct |
4 |
Correct |
115 ms |
21988 KB |
Output is correct |
5 |
Correct |
137 ms |
25936 KB |
Output is correct |
6 |
Correct |
121 ms |
25932 KB |
Output is correct |
7 |
Correct |
131 ms |
27216 KB |
Output is correct |
8 |
Correct |
126 ms |
24480 KB |
Output is correct |
9 |
Correct |
125 ms |
23660 KB |
Output is correct |
10 |
Correct |
122 ms |
23292 KB |
Output is correct |
11 |
Correct |
125 ms |
23632 KB |
Output is correct |
12 |
Correct |
116 ms |
20984 KB |
Output is correct |
13 |
Correct |
129 ms |
22480 KB |
Output is correct |
14 |
Correct |
129 ms |
25640 KB |
Output is correct |
15 |
Correct |
126 ms |
23264 KB |
Output is correct |
16 |
Correct |
1 ms |
360 KB |
Output is correct |
17 |
Correct |
116 ms |
21820 KB |
Output is correct |
18 |
Correct |
118 ms |
21168 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3087 ms |
33552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3049 ms |
8132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
26092 KB |
Output is correct |
2 |
Correct |
125 ms |
24524 KB |
Output is correct |
3 |
Correct |
119 ms |
24028 KB |
Output is correct |
4 |
Correct |
115 ms |
21988 KB |
Output is correct |
5 |
Correct |
137 ms |
25936 KB |
Output is correct |
6 |
Correct |
121 ms |
25932 KB |
Output is correct |
7 |
Correct |
131 ms |
27216 KB |
Output is correct |
8 |
Correct |
126 ms |
24480 KB |
Output is correct |
9 |
Correct |
125 ms |
23660 KB |
Output is correct |
10 |
Correct |
122 ms |
23292 KB |
Output is correct |
11 |
Correct |
125 ms |
23632 KB |
Output is correct |
12 |
Correct |
116 ms |
20984 KB |
Output is correct |
13 |
Correct |
129 ms |
22480 KB |
Output is correct |
14 |
Correct |
129 ms |
25640 KB |
Output is correct |
15 |
Correct |
126 ms |
23264 KB |
Output is correct |
16 |
Correct |
1 ms |
360 KB |
Output is correct |
17 |
Correct |
116 ms |
21820 KB |
Output is correct |
18 |
Correct |
118 ms |
21168 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Execution timed out |
3087 ms |
33552 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |