Submission #858154

#TimeUsernameProblemLanguageResultExecution timeMemory
858154alexdumitruFloppy (RMI20_floppy)C++17
100 / 100
74 ms13808 KiB
#include <stdlib.h> #include <string.h> #include <stack> #include "floppy.h" void read_array(int subtask_id, const std::vector<int> &v) { std :: string s; std :: stack<int> st; for (int i = 0; i < v.size(); i++) { while (!st.empty() && st.top() < v[i]) { s += "1"; st.pop(); } s += "0"; st.push(v[i]); } save_to_floppy(s); } int query(int st, int dr, int prev[][16]) { for(int i = 15; i >= 0; i--) if(prev[dr][i] >= st) dr = prev[dr][i]; return dr; } std :: vector<int> solve_queries(int subtask_id, int N, const std :: string &bits, const std :: vector<int> &a, const std :: vector<int> &b) { int ptr = 0; std :: stack<int> st; int prev[N][16]; for (int i = 0; i < N; i++) { while(bits[ptr] == '1'){ st.pop(); ptr++; } prev[i][0] = st.empty() ? i : st.top(); for(int j = 1; j < 16; j++) prev[i][j] = prev[prev[i][j - 1]][j - 1]; st.push(i); ptr++; } std :: vector<int> answers; int M = a.size(); for (int i = 0; i < M; i++) answers.push_back(query(a[i], b[i], prev)); return answers; }

Compilation message (stderr)

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i = 0; i < v.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...