# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
478887 | Neacsu_Mihai | Floppy (RMI20_floppy) | C++14 | 89 ms | 14212 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 <iostream>
#include <stack>
#include <vector>
#include "floppy.h"
#define LOGMAX 17 //2 ^ 17 < NMAX, 2 ^ 18 > NMAX
#define NMAX 200000 //doua sute de mii
using namespace std;
int RMQ[LOGMAX + 1][NMAX + 1];
int stanga[NMAX + 1];
int log[NMAX + 1];
void read_array(int subtask_id, const vector<int> &v){
int N = v.size();
int k = 0;
stack <int> st;
string bits;
for(int i = 0; i < N; i++){
while(!st.empty() && v[i] > v[st.top()]){
bits.push_back('0');
st.pop();
}
bits.push_back('1');
st.push(i);
}
save_to_floppy(bits);
}
int rezultant(int A, int B){
if(stanga[A] < stanga[B]){
return A;
}
else { //la egalitate il aleg pe B
return B;
}
}
void buildRMQ(int N){
log[1] = 0;
for(int j = 2; j <= N; j++){
log[j] = log[j / 2] + 1;
}
for(int i = 1; i <= N; i++){
RMQ[0][i] = i;
}
for(int j = 1; (1 << j) <= N; j++){
for(int i = 1; i - 1 + (1 << j) <= N; i++){
RMQ[j][i] = rezultant(RMQ[j - 1][i], RMQ[j - 1][i + (1 << (j - 1))]);
}
}
}
int query(int A, int B){
//returnez minimul din [A, B]
int k = log[B - A + 1];
return rezultant(RMQ[k][A], RMQ[k][B - (1 << k) + 1]);
}
vector<int> solve_queries(int subtask_id, int n, const string &bits, const vector<int> &a, const vector<int> &b){
//dau build la stanga[]
int poz = 0;
stack <int> st;
for(int i = 1; i <= n; i++){
while(bits[poz] == '0'){
st.pop();
poz++;
}
//acum bits[poz] = 1
if(st.empty()){
stanga[i] = 0;
}
else {
stanga[i] = st.top();
}
st.push(i);
poz++;
}
buildRMQ(n);
vector <int> rez;
for(int i = 0; i < a.size(); i++){
rez.push_back( query(a[i] + 1, b[i] + 1) - 1 );
}
return rez;
}
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... |