# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
856246 | divad | Floppy (RMI20_floppy) | C++14 | 0 ms | 0 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"
using namespace std;
const int NMAX = 4e5+2;
int bigr[NMAX], st[NMAX], vf;
void read_array(int subtask_id, vector<int> &v){
string bits = "";
int n = v.size();
vf = 0;
for(int i = 0; i < n; i++){
while(vf > 0 && st[vf] < v[i]){
bits += "1";
vf--;
}
st[++vf] = v[i];
bits += "0";
}
save_to_floppy(bits);
}
vector<int> solve_queries(int subtask_id, int N, string &bits, vector<int> &a, vector<int> &b){
int n = N, m = a.size();
vf = 0;
int pos = 0;
for(int i = 1; i <= n; i++){
while(bits[pos] == '1'){
vf--;
pos++;
}
bigr[i] = st[vf];
st[++vf] = i;
pos++;
}
vector<int> ans;
for(int i = 0; i < m; i++){
int l = a[i], r = b[i];
l++, r++;
int id = r;
while(bigr[id] >= l){
id = bigr[id];
}
ans.push_back(id-1);
}
return ans;
}