Submission #858559

# Submission time Handle Problem Language Result Execution time Memory
858559 2023-10-08T18:26:57 Z dbence Floppy (RMI20_floppy) C++14
100 / 100
74 ms 18676 KB
#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

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 time Memory Grader output
1 Correct 2 ms 6972 KB Output is correct
2 Correct 2 ms 6976 KB Output is correct
3 Correct 2 ms 6968 KB Output is correct
4 Correct 2 ms 6976 KB Output is correct
5 Correct 2 ms 6968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 9664 KB Output is correct
2 Correct 23 ms 9652 KB Output is correct
3 Correct 17 ms 9644 KB Output is correct
4 Correct 18 ms 9640 KB Output is correct
5 Correct 18 ms 9524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 18468 KB Output is correct
2 Correct 71 ms 18468 KB Output is correct
3 Correct 73 ms 18608 KB Output is correct
4 Correct 71 ms 18668 KB Output is correct
5 Correct 70 ms 18676 KB Output is correct