# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
494454 | iulia13 | 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 N = 40005;
const int LG = 20;
int st[N];
int rmq[N][LG];
int lft[N];
///void save_to_floppy(string &bits);
void read_array(int subtask_id, vector <int> &v)
{
string a = "";
int k = 0, n = v.size();
for (int i = 0; i < n; i++)
{
while (k && st[k] < v[i])
{
a += '1';
k--;
}
st[++k] = v[i];
a += '0';
}
save_to_floppy(a);
}
vector <int> sol;
int lg[N];
vector<int> solve_queries(int subtask_id, int N, string &bits, vector<int> &A, vector<int> &B)
{
int k = 0, m = bits.size(), jj = 0;
for (int i = 1; i <= N; i++)
{
if (1 < i)
lg[i] = 1 + lg[i / 2];
while(k && bits[jj] == '1')
k--, jj++;
jj++;
lft[i] = st[k];
st[++k] = i;
rmq[i][0] = i;
}
for (int j = 1; (1 << j) <= N; j++)
for (int i = 1; i <= N; i++)
{
rmq[i][j] = rmq[i][j - 1];
if (lft[rmq[i + (1 << (j - 1))][j - 1]] < i)
rmq[i][j] = rmq[i + (1 << (j - 1))][j - 1];
}
int q = A.size();
for (int i = 0; i < q; i++)
{
int a = A[i], b = B[i];
a++, b++;
int lgg = lg[b - a + 1];
int ans = rmq[a][lgg];
if (lft[rmq[b - (1 << lgg) + 1][lgg]] < a)
ans = rmq[b - (1 << lgg) + 1][lgg];
sol.push_back(ans - 1);
}
return sol;
}/*
#define NMAX 100000
#define MMAX 100000
int subtask_id, NN, M;
vector<int> v, sorted_v;
vector<int> a, b;
vector<int> correct_answers;
void read_test() {
cin >> subtask_id >> NN >> M;
v.resize(NN);
for (int i = 0; i < NN; ++i) {
cin >> v[i];
}
a.resize(M);
b.resize(M);
correct_answers.resize(M);
for (int i = 0; i < M; ++i) {
cin >> a[i] >> b[i] >> correct_answers[i];
}
}
void save_to_floppy(string &bits) {
std::vector<int> contestant_answers = solve_queries(subtask_id, NN, bits, a, b);
int x = contestant_answers.size();
for (auto it : contestant_answers)
cout << it << " ";
}
int main(int argc, char **argv) {
// Read input data.
read_test();
// Send subtask_id, v.
read_array(subtask_id, v);
return 0;
}*/