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 <stdlib.h>
#include <string.h>
#include "floppy.h"
using namespace std;
void read_array(int subtask_id, const std::vector<int> &v)
{
int N = v.size();
string bits('0', 2 * N);
int tart = 0;
vector<int> pos;
pos.clear();
for (int i = 0; i < N; i++)
pos.push_back(i);
while (pos.size() > 1)
{
vector<int> uj;
uj.clear();
int pre = -1;
bool ok = false;
for (int i : pos)
{
if (pre == -1)
{
ok = true;
}
else if (v[pre] < v[i])
{
ok = true;
bits[tart++] = '1';
}
else
{
if (ok)
uj.push_back(pre);
ok = false;
bits[tart++] = '0';
}
pre = i;
}
if (ok)
uj.push_back(pre);
pos = uj;
}
save_to_floppy(bits);
}
vector<int> kerd[40000];
std::vector<int> solve_queries(int subtask_id, int N,
const std::string &bits,
const std::vector<int> &aa, const std::vector<int> &bb)
{
int Q = aa.size();
std::vector<int> ans(Q);
for (int i = 0; i < Q; i++)
{
kerd[bb[i]].push_back(i);
if (aa[i] == bb[i])
ans[i] = aa[i];
}
vector<int> pos;
pos.clear();
for (int i = 0; i < N; i++)
pos.push_back(i);
int tart = 0;
while (pos.size() > 1)
{
vector<int> uj;
uj.clear();
int pre = -1;
bool ok = false;
for (int i : pos)
{
if (pre == -1)
{
ok = true;
}
else if (bits[tart++] == '0')
{
if (ok)
uj.push_back(pre);
ok = false;
}
else
{
ok = true;
}
pre = i;
}
if (ok)
uj.push_back(pre);
pos = uj;
int a = -1, b = -1;
auto it = pos.begin();
for (int i = 0; i < N; i++){
if(it!=pos.end() && (*it)==i){
a = b;
b = i;
it++;
}
for(int j : kerd[i]){
if(a < aa[j] && aa[j] <= b)
ans[j] = b;
}
}
}
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... |