# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
512408 | Stickfish | Floppy (RMI20_floppy) | C++17 | 99 ms | 15456 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 <iostream>
#include <string.h>
#include <vector>
#include "floppy.h"
using namespace std;
void read_array(int subtask_id, const vector<int>& v) {
int n = v.size();
string bits = "";
vector<int> st;
for (int i = 0; i < n; ++i) {
while (st.size() && v[i] >= v[st.back()]) {
st.pop_back();
bits.push_back('0');
}
st.push_back(i);
bits.push_back('1');
}
save_to_floppy(bits);
}
vector<int> get_v(int n, const string& bits) {
vector<int> ans(n);
int i = 0;
int l = bits.size();
vector<int> st = {-1};
for (int j = 0; j < l; ++j) {
if (bits[j] == '0') {
st.pop_back();
} else {
ans[i] = st.back();
st.push_back(i);
++i;
}
}
return ans;
}
vector<int> solve_queries(int subtask_id, int N, const string& bits, const vector<int>& a, const vector<int>& b) {
vector<int> v = get_v(N, bits);
//for (int i = 0; i < N; ++i)
//cout << v[i] << ' ';
//cout << endl;
vector<vector<int>> redg(N);
for (int i = 0; i < N; ++i) {
if (v[i] == -1)
continue;
redg[i].push_back(v[i]);
for (int j = 1; j - 1 < redg[redg[i][j - 1]].size(); ++j) {
redg[i].push_back(redg[redg[i][j - 1]][j - 1]);
}
}
int m = a.size();
vector<int> answers(m);
for (int i = 0; i < m; ++i) {
int l = a[i];
int v = b[i];
int j = 20;
while (j >= 0) {
if (j < redg[v].size() && l <= redg[v][j])
v = redg[v][j];
else
--j;
}
//cout << a[i] << ' ' << b[i] << ": " << v << endl;
answers[i] = v;
}
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... |