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;
vector<int> solve_queries(int subtask_id, int n, const string &bits, const vector<int> &a, const vector<int> &b) {
vector<int> lg2(n + 1);
for (int i = 2; i <= n; ++i) {
lg2[i] = lg2[i / 2] + 1;
}
vector<vector<int>> nxt(n + 1, vector<int>(lg2[n] + 1, n));
vector<int> stk;
int ptr = 0;
for (int i = 0; i < n; ++i) {
while (bits[ptr] == '0') {
nxt[stk.back()][0] = i;
stk.pop_back();
ptr += 1;
}
stk.emplace_back(i);
ptr += 1;
}
for (int j = 1; j <= lg2[n]; ++j) {
for (int i = 0; i < n; ++i) {
nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
}
}
int m = a.size();
vector<int> res(m);
for (int i = 0; i < m; ++i) {
int l = a[i], r = b[i];
for (int j = lg2[r - l + 1]; j >= 0; --j) {
if (nxt[l][j] <= r) {
l = nxt[l][j];
}
}
res[i] = l;
}
return res;
}
void read_array(int subtask_id, const vector<int> &v) {
int n = v.size();
vector<int> stk;
string bits = "";
for (int i = 0; i < n; ++i) {
while (!stk.empty() && stk.back() < v[i]) {
stk.pop_back();
bits += '0';
}
stk.emplace_back(v[i]);
bits += '1';
}
save_to_floppy(bits);
}
Compilation message (stderr)
stub.cpp: In function 'void run2()':
stub.cpp:101:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
101 | if (query_answers.size() != M) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |