#include "bits/stdc++.h"
#include "floppy.h"
using namespace std;
array<int, 2> t[16][42069];
void init(const vector<int>& v){
int n = v.size();
for(int i = 0; i < n; ++i) t[0][i] = {v[i], i};
for(int y = 0; y < 15; ++y){
int p = 1 << y;
for(int i = 0; i+p+p <= n; ++i) t[y+1][i] = max(t[y][i], t[y][i+p]);
}
}
int mx(int l, int r){
int y = 0, le = 1;
while(le+le <= r-l) ++y, le *= 2;
return max(t[y][l], t[y][r-le])[1];
}
void read_array(int st, const vector<int> &v){
init(v);
string bits;
function<void(int, int)> dfs = [&](int l, int r){
int idx = mx(l, r);
bits += (idx > l)? "1" : "0";
bits += (idx < r-1)? "1" : "0";
if(idx > l) dfs(l, idx);
if(idx < r-1) dfs(idx+1, r);
};
dfs(0, v.size());
save_to_floppy(bits);
}
vector<int> solve_queries(int st, int n, const string &bits, const vector<int> &a, const vector<int> &b){
vector<int> v, ans;
int i = 0;
function<void(int)> dfs = [&](int d){
int l = (bits[i++] == '1'), r = (bits[i++] == '1');
if(l) dfs(d-1);
v.push_back(d);
if(r) dfs(d-1);
};
dfs(42069);
init(v);
for(int i = 0; i < a.size(); ++i) ans.push_back(mx(a[i], b[i]+1));
return ans;
}
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:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 0; i < a.size(); ++i) ans.push_back(mx(a[i], b[i]+1));
| ~~^~~~~~~~~~
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) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
788 KB |
Output is correct |
2 |
Correct |
2 ms |
784 KB |
Output is correct |
3 |
Correct |
2 ms |
780 KB |
Output is correct |
4 |
Correct |
2 ms |
780 KB |
Output is correct |
5 |
Correct |
2 ms |
780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
5228 KB |
Output is correct |
2 |
Correct |
30 ms |
5304 KB |
Output is correct |
3 |
Correct |
35 ms |
6460 KB |
Output is correct |
4 |
Correct |
27 ms |
5872 KB |
Output is correct |
5 |
Correct |
30 ms |
5352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
120 ms |
20860 KB |
Output is correct |
2 |
Correct |
109 ms |
20808 KB |
Output is correct |
3 |
Correct |
115 ms |
25324 KB |
Output is correct |
4 |
Correct |
113 ms |
22984 KB |
Output is correct |
5 |
Correct |
112 ms |
20800 KB |
Output is correct |