Submission #645530

# Submission time Handle Problem Language Result Execution time Memory
645530 2022-09-27T09:54:20 Z Alex_tz307 Floppy (RMI20_floppy) C++17
100 / 100
89 ms 12112 KB
#include <bits/stdc++.h>
#include "floppy.h"
 
using namespace std;

vector<int> solve_queries(int subtask_id, int n, const string &bits, const vector<int> &a, const vector<int> &b) {
  vector<int> lg2(n + 1);
  for (int i = 2; i <= n; ++i) {
    lg2[i] = lg2[i / 2] + 1;
  }
  vector<vector<int>> nxt(n + 1, vector<int>(lg2[n] + 1, n));
  vector<int> stk;
  int ptr = 0;
  for (int i = 0; i < n; ++i) {
    while (bits[ptr] == '0') {
      nxt[stk.back()][0] = i;
      stk.pop_back();
      ptr += 1;
    }
    stk.emplace_back(i);
    ptr += 1;
  }
  for (int j = 1; j <= lg2[n]; ++j) {
    for (int i = 0; i < n; ++i) {
      nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
    }
  }
  int m = a.size();
  vector<int> res(m);
  for (int i = 0; i < m; ++i) {
    int l = a[i], r = b[i];
    for (int j = lg2[r - l + 1]; j >= 0; --j) {
      if (nxt[l][j] <= r) {
        l = nxt[l][j];
      }
    }
    res[i] = l;
  }
  return res;
}

void read_array(int subtask_id, const vector<int> &v) {
  int n = v.size();
  vector<int> stk;
  string bits = "";
  for (int i = 0; i < n; ++i) {
    while (!stk.empty() && stk.back() < v[i]) {
      stk.pop_back();
      bits += '0';
    }
    stk.emplace_back(v[i]);
    bits += '1';
  }
  save_to_floppy(bits);
}

Compilation message

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
1 Correct 2 ms 784 KB Output is correct
2 Correct 2 ms 784 KB Output is correct
3 Correct 2 ms 784 KB Output is correct
4 Correct 2 ms 792 KB Output is correct
5 Correct 2 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3196 KB Output is correct
2 Correct 20 ms 3240 KB Output is correct
3 Correct 20 ms 3188 KB Output is correct
4 Correct 20 ms 3216 KB Output is correct
5 Correct 22 ms 3176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 11804 KB Output is correct
2 Correct 81 ms 11796 KB Output is correct
3 Correct 89 ms 12112 KB Output is correct
4 Correct 81 ms 12008 KB Output is correct
5 Correct 78 ms 11896 KB Output is correct