Submission #858559

#TimeUsernameProblemLanguageResultExecution timeMemory
858559dbenceFloppy (RMI20_floppy)C++14
100 / 100
74 ms18676 KiB
#include <bits/stdc++.h> #include "floppy.h" const int N = 1e5 + 1; const int L = 20; int nxt[L][N]; void write_bits(const std::vector <int> &v, std::string &bits) { std::stack <int> st; for (int i = 0; i < v.size(); ++i) { while (!st.empty() && st.top() < v[i]) { bits += "1"; st.pop(); } bits += "0"; st.push(v[i]); } } int query(int l, int r) { int cur = l; for (int i = L - 1; i >= 0; --i) { if (nxt[i][cur] <= r) { cur = nxt[i][cur]; } } return cur; } void read_bits(const std::string &bits, int n) { std::stack <int> st; std::fill(nxt[0], nxt[0] + n + 1, n); int curr = 0; for (char c: bits) { if (c == '0') { st.push(curr++); } else { nxt[0][st.top()] = curr; st.pop(); } } for (int i = 1; i < L; ++i) { for (int j = 0; j <= n; ++j) { nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; } } } void read_array(int subtask_id, const std::vector<int> &v) { std::string bits = ""; write_bits(v, bits); save_to_floppy(bits); } std::vector<int> solve_queries(int subtask_id, int N, const std::string &bits, const std::vector<int> &a, const std::vector<int> &b) { read_bits(bits, N); std::vector <int> ans; for (int i = 0; i < a.size(); ++i) { ans.push_back(query(a[i], b[i])); } return ans; }

Compilation message (stderr)

floppy.cpp: In function 'void write_bits(const std::vector<int>&, std::string&)':
floppy.cpp:10:23: 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 < v.size(); ++i) {
      |                     ~~^~~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...