# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
926718 | hotboy2703 | Floppy (RMI20_floppy) | C++17 | 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 "floplib.h" // DO NOT CHANGE THIS LINE
#include<bits/stdc++.h>
using namespace std;
const int MAXK = 16;
int sp[MAXK][40100];
string ansss;
vector <int> a;
int best(int x,int y){
if (a[x] > a[y])return x;
return y;
}
int lg[40100];
int id=0;
void solve(int l,int r,int node = id++){
if (l > r)return;
int sz = lg[r-l+1];
int mid = best(sp[sz][l],sp[sz][r-(1<<sz)+1]);
ansss[node<<1] = ansss[node<<1|1] = '0';
if (mid > l){
solve(l,mid-1);
ansss[node<<1] = '1';
}
if (mid < r){
ansss[node<<1|1] = '1';
solve(mid+1,r);
}
}
int n;
void read_array(int subtask, const vector<int> &v) {
n = v.size();
lg[1] = 0;
for (int i = 2;i <= n;i ++)lg[i] = lg[i/2] + 1;
a = v;
for (int i = 0;i < n;i ++){
sp[0][i] = i;
}
for (int j = 1;j < MAXK;j ++){
for (int i = 0;i + (1<<j) - 1 < n;i++){
sp[j][i] = best(sp[j-1][i],sp[j-1][i+(1<<(j-1))]);
}
}
ansss.resize(2*n);
solve(0,n-1);
save_to_floppy(ansss);
}
string mom;
int cur = 0;
int depth[40100];
int sex[40100];
void decode(int node = id++){
if (mom[node<<1] == '1'){
decode();
}
sex[cur++] = node;
if (mom[node<<1|1] == '1'){
decode();
}
}
int best2(int x,int y){
if (sex[x] < sex[y])return x;
return y;
}
vector<int> solve_queries(int subtask, int n, const string &data, const vector<pair<int, int>> &queries) {
vector<int> anssswer(queries.size());
lg[1] = 0;
for (int i = 2;i <= n;i ++){
lg[i] = lg[i>>1] + 1;
}
mom = data;
id = 0;
cur = 0;
decode();
for (int i = 0;i < n;i ++){
sp[0][i] = i;
}
for (int j = 1;j < MAXK;j ++){
for (int i = 0;i + (1<<j) - 1 < n;i ++){
sp[j][i] = best2(sp[j-1][i],sp[j-1][i + (1<<(j-1))]);
}
}
for (int i = 0;i < queries.size();i++){
int l = queries[i].first;
int r = queries[i].second;
int sz = lg[r - l + 1];
anssswer[i] = best2(sp[sz][l],sp[sz][r - (1<<sz) + 1]);
}
return anssswer;
}