#include<bits/stdc++.h>
#include "floppy.h"
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
const int maxn = 1e5 + 5;
pii tree[4 * maxn], t[4 * maxn];
vector<int> A;
int n, cur = 0;
string bits, s;
///////////////////
/*
#include <algorithm>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#define NMAX 100000
#define MMAX 100000
int subtask_id, N, M;
std::vector<int> v, sorted_v;
std::vector<int> a, b;
std::vector<int> correct_answers;
// Print score to stdout and exit.
void score_and_exit(const double pts, const char *verdict) {
fprintf(stderr, "%s", verdict);
fprintf(stdout, "%f", pts);
exit(0);
}
// Contestant sent too many bits.
void too_many_bits() {
score_and_exit(0, "Too many stored bits!");
}
// Contestant did not send any bits.
void misformatted_stored_bits() {
score_and_exit(0, "Misformatted stored bits or save_to_floppy not called!");
}
// Contestant did not call the answer function.
void answer_not_provided() {
score_and_exit(0, "Answer not provided!");
}
// Contestant sent a wrong answer.
void wrong_answer() {
score_and_exit(0, "Wrong answer to query!");
}
// Contestant sent a correct answer.
void correct_answer() {
score_and_exit(1, "OK!");
} */
void upd(int u,int ind,int l,int r,int val) {
if(l > ind || r < ind) return;
if(l == r) {
t[u] = {val, l};
return;
}
int mid = (l + r) / 2;
upd(2 * u, ind, l, mid, val); upd(2 * u + 1, ind, mid + 1, r, val);
t[u] = min(t[2 * u], t[2 * u + 1]);
}
pii Get(int u,int st,int en,int l,int r) {
if(l > en || r < st) return {n + 1, 0};
if(st <= l && r <= en) { cout << l <<" daa " << r << endl;
return t[u]; }
int mid = (l + r) / 2;
return min(Get(2 * u, st, en, l, mid), Get(2 * u + 1, st, en, mid + 1, r));
}
void go(int l,int r) {
if(l > r) return;
int x = 0;
for(int i = cur; i < cur + 16; i++) {
x += (s[i] == '1') * (1 << (i - cur));
}
cur += 16;
upd(1, x, 0, n, cur / 16 - 1);
go(l, x - 1); go(x + 1, r);
}
std::vector<int> solve_queries(int subtask_id, int N,
const std::string &bits,
const std::vector<int> &a, const std::vector<int> &b) {
s = bits; n = N - 1;
cur = 0;
go(0, n);
vector<int> ans(a.size());
for(int i = 0; i < a.size(); i++) {
ans[i] = Get(1, a[i], b[i], 0, n).s;
}
return ans;
}
/*
void save_to_floppy(const std::string &bits) {
std::vector<int> contestant_answers = solve_queries(subtask_id, N, bits, a, b);
for (int i = 0; i < M; ++i) {
if (contestant_answers[i] != correct_answers[i]) {
wrong_answer();
}
}
correct_answer();
exit(0);
}*/
////////////////////////////////////////////////////////////////
void build(int u,int l,int r) {
if(l == r) {
tree[u] = {A[l], l};
return;
}
int mid = (l + r) / 2;
build(2 * u, l, mid); build(2 * u + 1, mid + 1, r);
tree[u] = max(tree[2 * u], tree[2 * u + 1]);
}
pii get(int u, int st,int en,int l,int r) {
if(l > en || r < st) return {-1, 0};
if(st <= l && r <= en) return tree[u];
int mid = (l + r) / 2;
return max(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
}
void solve(int l,int r) {
if(l > r) return;
int x = get(1, l, r, 0, n).s;
for(int i = 0; i < 16; i++) {
if((1 << i) & x) bits += '1';
else bits += '0';
}
solve(l, x - 1); solve(x + 1, r);
}
void read_array(int subtask_id, const std::vector<int> &v) {
bits = "";
n = v.size(); n--;
A = v;
build(1, 0, n);
solve(0, n);
save_to_floppy(bits);
}
/*
/////////////////
void read_test() {
assert(scanf("%d", &subtask_id) == 1);
assert(scanf("%d%d", &N, &M) == 2);
assert(1 <= N && N <= NMAX);
assert(0 <= M && M <= MMAX);
v.resize(N);
for (int i = 0; i < N; ++i) {
assert(scanf("%d", &v[i]) == 1);
}
// Check all values are distinct.
cout << "++" << endl;
sorted_v.resize(N);
for (int i = 0; i < N; ++i) {
sorted_v[i] = v[i];
}
std::sort(sorted_v.begin(), sorted_v.end());
for (int i = 0; i + 1 < N; ++i) {
assert(sorted_v[i] < sorted_v[i + 1]);
}
a.resize(M);
b.resize(M);
correct_answers.resize(M);
for (int i = 0; i < M; ++i) {
assert(scanf("%d%d%d", &a[i], &b[i], &correct_answers[i]) == 3);
assert(0 <= a[i] && a[i] <= correct_answers[i] &&
correct_answers[i] <= b[i] && b[i] < N);
}
}
////////////////////////////////////////////////////////////////////////
int main(int argc, char **argv) {
// Read input data.
read_test();
// Send subtask_id, v.
read_array(subtask_id, v);
answer_not_provided();
return 0;
}*/
Compilation message
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:93:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
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 |
1 |
Incorrect |
8 ms |
764 KB |
Security error -- do not print anything to stdout |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1059 ms |
124448 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1010 ms |
127632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |