# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
642768 | andrei_boaca | Abracadabra (CEOI22_abracadabra) | C++14 | 1306 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;
int n,q;
vector<int> v;
vector<vector<int>> vals;
vector<int> trans(vector<int> v)
{
vector<int> a,b;
for(int i=0;i<v.size();i++)
{
if(i*2<v.size())
a.push_back(v[i]);
else
b.push_back(v[i]);
}
reverse(a.begin(),a.end());
reverse(b.begin(),b.end());
vector<int> rez;
while(a.size()||b.size())
{
if(a.size()&&b.size())
{
int x=a.back();
int y=b.back();
rez.push_back(min(x,y));
if(x<y)
a.pop_back();
else
b.pop_back();
continue;
}
if(a.size())
{
int x=a.back();
a.pop_back();
rez.push_back(x);
}
else
{
int x=b.back();
b.pop_back();
rez.push_back(x);
}
}
return rez;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
v.push_back(x);
}
vals.push_back(v);
while(true)
{
v=trans(v);
vector<int> aux=vals.back();
bool iseq=1;
for(int i=0;i<v.size();i++)
if(v[i]!=aux[i])
iseq=0;
if(iseq)
break;
vals.push_back(v);
}
while(q--)
{
int i,j;
cin>>i>>j;
int lg=vals.size();
i=min(i,lg-1);
cout<<vals[i][j-1]<<'\n';
}
return 0;
}
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... |