# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
494335 | Tenis0206 | Floppy (RMI20_floppy) | C++17 | 88 ms | 14528 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>
#include "floppy.h"
using namespace std;
/*string bglobal;
void save_to_floppy(string bits)
{
bglobal = bits;
}
*/
void read_array(int subtask, const vector<int> &v)
{
stack<int> st;
string bits;
for(int i=0;i<v.size();i++)
{
while(!st.empty() && v[i]>v[st.top()])
{
bits.push_back('0');
st.pop();
}
bits.push_back('1');
st.push(i);
}
save_to_floppy(bits);
}
int rmq[25][100005];
int Log2[100005];
int l[100005];
void build_rmq(int n)
{
for(int i=2;i<=n;i++)
{
Log2[i] = 1 + Log2[i/2];
}
for(int i=1;i<=n;i++)
{
rmq[0][i] = i;
}
for(int k=1;k<=Log2[n];k++)
{
for(int i=1;i<=n;i++)
{
if(l[rmq[k-1][i]]<l[rmq[k-1][i+(1<<(k-1))]])
{
rmq[k][i] = rmq[k-1][i];
}
else
{
rmq[k][i] = rmq[k-1][i+(1<<(k-1))];
}
}
}
}
int query(int x, int y)
{
int k = y - x + 1;
k = Log2[k];
if(l[rmq[k][x]]<l[rmq[k][y-(1<<k)+1]])
{
return rmq[k][x];
}
return rmq[k][y-(1<<k)+1];
}
vector<int> solve_queries(int subtask, int n, const string &bits, const vector<int> &a, const vector<int> &b)
{
stack<int> st;
int poz = 0;
for(int i=1;i<=n;i++)
{
while(poz<bits.size() && bits[poz]=='0')
{
++poz;
st.pop();
}
if(st.empty())
{
l[i] = 0;
}
else
{
l[i] = st.top();
}
++poz;
st.push(i);
}
build_rmq(n);
vector<int> rez;
for(int i=0;i<a.size();i++)
{
int x = a[i] + 1;
int y = b[i] + 1;
rez.push_back(query(x,y)-1);
}
return rez;
}
/*int main()
{
int n;
cin>>n;
vector<int> v;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
v.push_back(x);
}
int q;
cin>>q;
vector<int> a,b;
for(int i=1;i<=q;i++)
{
int x,y;
cin>>x>>y;
a.push_back(x);
b.push_back(y);
}
read_array(0,v);
vector<int> rez = solve_queries(0,n,bglobal,a,b);
for(auto it : rez)
{
cout<<it<<' ';
}
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... |