# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
858559 | dbence | Floppy (RMI20_floppy) | C++14 | 74 ms | 18676 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"
const int N = 1e5 + 1;
const int L = 20;
int nxt[L][N];
void write_bits(const std::vector <int> &v, std::string &bits) {
std::stack <int> st;
for (int i = 0; i < v.size(); ++i) {
while (!st.empty() && st.top() < v[i]) {
bits += "1";
st.pop();
}
bits += "0";
st.push(v[i]);
}
}
int query(int l, int r) {
int cur = l;
for (int i = L - 1; i >= 0; --i) {
if (nxt[i][cur] <= r) {
cur = nxt[i][cur];
}
}
return cur;
}
void read_bits(const std::string &bits, int n) {
std::stack <int> st;
std::fill(nxt[0], nxt[0] + n + 1, n);
int curr = 0;
for (char c: bits) {
if (c == '0') {
st.push(curr++);
} else {
nxt[0][st.top()] = curr;
st.pop();
}
}
for (int i = 1; i < L; ++i) {
for (int j = 0; j <= n; ++j) {
nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
}
}
}
void read_array(int subtask_id, const std::vector<int> &v) {
std::string bits = "";
write_bits(v, bits);
save_to_floppy(bits);
}
std::vector<int> solve_queries(int subtask_id, int N, const std::string &bits, const std::vector<int> &a, const std::vector<int> &b) {
read_bits(bits, N);
std::vector <int> ans;
for (int i = 0; i < a.size(); ++i) {
ans.push_back(query(a[i], b[i]));
}
return ans;
}
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... |