이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "floppy.h"
using namespace std;
struct sparse{
vector<vector<pair<int, int>>> s;
void init(const vector<int> &a){
s.resize(24, vector<pair<int, int>> (a.size()));
for (int i=0; i<a.size(); i++){
s[0][i] = {a[i], i};
}
for (int i=1; i<s.size(); i++){
for (int j=0; j + (1 << (i-1)) < s[0].size(); j++){
s[i][j] = max(s[i-1][j], s[i-1][j + (1 << (i-1))]);
}
}
}
pair<int, int> query(int l, int r) const{
int lg = 31 - __builtin_clz(r - l + 1);
return max(s[lg][l], s[lg][r - (1 << lg) + 1]);
}
};
void get_bits(string &result, int l, int r, const sparse &v){
int pos = v.query(l, r).second;
if (l == pos) result += '0';
else{
result += '1';
get_bits(result, l, pos-1, v);
}
if (pos == r) result += '0';
else{
result += '1';
get_bits(result, pos+1, r, v);
}
}
void read_array(int subtask_id, const vector<int> &v){
string result;
sparse x; x.init(v);
get_bits(result, 0, v.size()-1, x);
save_to_floppy(result);
}
void read_bits(vector<int> &v, const string &result, int &ptr, int depth){
char posl = result[ptr++];
if (posl == '1'){
read_bits(v, result, ptr, depth-1);
}
v.push_back(depth);
char posr = result[ptr++];
if (posr == '1'){
read_bits(v, result, ptr, depth-1);
}
}
vector<int> solve_queries(int subtask_id, int N, const string &bits, const vector<int> &a, const vector<int> &b){
vector<int> ss; int ptr = 0;
read_bits(ss, bits, ptr, 0);
sparse s; s.init(ss);
vector<int> result(a.size());
for (int i=0; i<result.size(); i++){
result[i] = s.query(a[i], b[i]).second;
}
return result;
}
컴파일 시 표준 에러 (stderr) 메시지
floppy.cpp: In member function 'void sparse::init(const std::vector<int>&)':
floppy.cpp:10:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int i=0; i<a.size(); i++){
| ~^~~~~~~~~
floppy.cpp:14:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i=1; i<s.size(); i++){
| ~^~~~~~~~~
floppy.cpp:15:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int j=0; j + (1 << (i-1)) < s[0].size(); j++){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i=0; i<result.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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |