# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
858154 | alexdumitru | Floppy (RMI20_floppy) | C++17 | 74 ms | 13808 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 <stdlib.h>
#include <string.h>
#include <stack>
#include "floppy.h"
void read_array(int subtask_id, const std::vector<int> &v) {
std :: string s;
std :: stack<int> st;
for (int i = 0; i < v.size(); i++) {
while (!st.empty() && st.top() < v[i]) {
s += "1";
st.pop();
}
s += "0";
st.push(v[i]);
}
save_to_floppy(s);
}
int query(int st, int dr, int prev[][16]) {
for(int i = 15; i >= 0; i--)
if(prev[dr][i] >= st)
dr = prev[dr][i];
return dr;
}
std :: vector<int> solve_queries(int subtask_id, int N,
const std :: string &bits,
const std :: vector<int> &a, const std :: vector<int> &b) {
int ptr = 0;
std :: stack<int> st;
int prev[N][16];
for (int i = 0; i < N; i++) {
while(bits[ptr] == '1'){
st.pop();
ptr++;
}
prev[i][0] = st.empty() ? i : st.top();
for(int j = 1; j < 16; j++)
prev[i][j] = prev[prev[i][j - 1]][j - 1];
st.push(i);
ptr++;
}
std :: vector<int> answers;
int M = a.size();
for (int i = 0; i < M; i++)
answers.push_back(query(a[i], b[i], prev));
return answers;
}
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... |