Submission #512408

#TimeUsernameProblemLanguageResultExecution timeMemory
512408StickfishFloppy (RMI20_floppy)C++17
100 / 100
99 ms15456 KiB
#include <stdlib.h> #include <iostream> #include <string.h> #include <vector> #include "floppy.h" using namespace std; void read_array(int subtask_id, const vector<int>& v) { int n = v.size(); string bits = ""; vector<int> st; for (int i = 0; i < n; ++i) { while (st.size() && v[i] >= v[st.back()]) { st.pop_back(); bits.push_back('0'); } st.push_back(i); bits.push_back('1'); } save_to_floppy(bits); } vector<int> get_v(int n, const string& bits) { vector<int> ans(n); int i = 0; int l = bits.size(); vector<int> st = {-1}; for (int j = 0; j < l; ++j) { if (bits[j] == '0') { st.pop_back(); } else { ans[i] = st.back(); st.push_back(i); ++i; } } return ans; } vector<int> solve_queries(int subtask_id, int N, const string& bits, const vector<int>& a, const vector<int>& b) { vector<int> v = get_v(N, bits); //for (int i = 0; i < N; ++i) //cout << v[i] << ' '; //cout << endl; vector<vector<int>> redg(N); for (int i = 0; i < N; ++i) { if (v[i] == -1) continue; redg[i].push_back(v[i]); for (int j = 1; j - 1 < redg[redg[i][j - 1]].size(); ++j) { redg[i].push_back(redg[redg[i][j - 1]][j - 1]); } } int m = a.size(); vector<int> answers(m); for (int i = 0; i < m; ++i) { int l = a[i]; int v = b[i]; int j = 20; while (j >= 0) { if (j < redg[v].size() && l <= redg[v][j]) v = redg[v][j]; else --j; } //cout << a[i] << ' ' << b[i] << ": " << v << endl; answers[i] = v; } return answers; }

Compilation message (stderr)

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:50:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for (int j = 1; j - 1 < redg[redg[i][j - 1]].size(); ++j) {
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
floppy.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             if (j < redg[v].size() && l <= redg[v][j])
      |                 ~~^~~~~~~~~~~~~~~~
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...