# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968500 | anton | Abracadabra (CEOI22_abracadabra) | C++17 | 1211 ms | 524288 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
void shuffle(vector<int> &val){
int k = val.size();
vector<deque<int>> parts(2);
for(int i =0; i<val.size()/2; i++){
parts[0].push_back(val[i]);
parts[1].push_back(val[i + val.size()/2]);
}
val.clear();
while(val.size()<k){
if(parts[0].size()==0){
val.push_back(parts[1].front());
parts[1].pop_front();
}
else if(parts[1].size()==0){
val.push_back(parts[0].front());
parts[0].pop_front();
}
else{
if(parts[0].front()<parts[1].front()){
val.push_back(parts[0].front());
parts[0].pop_front();
}
else{
val.push_back(parts[1].front());
parts[1].pop_front();
}
}
}
}
bool stable(vector<int>& r){
int big = 0;
for(int i = 0; i<r.size()/2; i++){
big = max(big, r[i]);
}
return r[(r.size()/2 )+1] > big;
}
signed main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n, q;
cin>>n>>q;
vector<int> v(n);
for(int i = 0; i<n; i++){
cin>>v[i];
}
vector<vector<int>> results;
results.push_back(v);
for(int i = 1; !stable(results.back()); i++){
results.push_back(results.back());
shuffle(results.back());
}
for(int i = 0;i<q; i++){
int t, j;
cin>>t>>j;
if(t>=results.size()){
cout<<results.back()[j-1]<<endl;
}
else{
cout<<results[t][j-1]<<endl;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |