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 "floppy.h"
#include <bits/stdc++.h>
using namespace std;
void read_array(int subtask_id, const vector<int> &v) {
string bits = "";
int n=v.size();
stack<int> st;
for (int i=0; i<n; ++i){
while (st.size() && v[st.top()]<=v[i]) st.pop(), bits.push_back('0');
st.push(i);
bits.push_back('1');
}
save_to_floppy(bits);
}
vector<int> solve_queries(int subtask_id, int n, const string &bits,
const vector<int> &a, const vector<int> &b) {
vector<int> l(n);
stack<int> st;
vector<vector<pair<int, int>>> sparse(16, vector<pair<int, int>>(n));
int idx=0;
for (int i=0; i<n; ++i){
while (bits[idx]=='0') st.pop(), ++idx;
l[i]=st.size()?st.top():-1;
sparse[0][i]={l[i], -i};
st.push(i);
++idx;
}
for (int i=1; i<16; ++i) for (int j=0; j+(1<<i)<=n; ++j) sparse[i][j]=min(sparse[i-1][j], sparse[i-1][j+(1<<(i-1))]);
vector<int> ans;
auto get=[&](int l, int r) -> pair<int, int> {
int lg=__lg(r-l+1);
return min(sparse[lg][l], sparse[lg][r-(1<<lg)+1]);
};
for (int i=0; i<(int)a.size(); ++i){
ans.push_back(-get(a[i], b[i]).second);
}
return ans;
}
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... |