Submission #1056607

# Submission time Handle Problem Language Result Execution time Memory
1056607 2024-08-13T10:15:46 Z Vanilla Floppy (RMI20_floppy) C++17
100 / 100
60 ms 13012 KB
#include <bits/stdc++.h>
#include "floppy.h"
using namespace std;

struct query {
    int x,y,idx;

    bool operator < (const query& oth) const {
        return make_pair(-x, y) < make_pair(-oth.x, oth.y);
    }
};

void read_array(int subtask_id, const vector<int> &v) {
    string s = "";
    stack <int> st;
    int n = v.size();
    for (int i = 0; i < n; i++){
        while (!st.empty() && v[i] > st.top()) {
            st.pop();
            s.push_back('0');
        }
        st.push(v[i]);
        s.push_back('1');
    }
    save_to_floppy(s);
}

vector<int> solve_queries(int subtask_id, int n,
        const string &bits,
        const vector<int> &a, const vector<int> &b) {
    stack <int> st;
    st.push(-1);
    vector <int> high(n);
    int idx = 0;
    for (char c: bits) {
        if (c == '1') {
            high[idx] = st.top();
            st.push(idx++);
        }
        else {
            st.pop();
        }
    }
    vector <query> v;
    for (int i = 0; i < a.size(); i++){
        v.push_back({a[i], b[i], i});
    }
    sort(v.begin(), v.end());
    vector <int> rs(a.size());
    for (auto [l, r, idx]: v){
        vector <int> vals;
        int inir = r;
        int last = r;
        while (r != high[r] && r >= l) {
            vals.push_back(r);
            last = r;
            r = high[r];
        }
        for (int i = 0; i < (int) vals.size() - 1; i++){
            high[vals[i]] = vals.back();
        }
        rs[idx] = last;
    }
    // for (int i: rs) {
    //     cout << i << " ";
    // }
    // cout << "\n";
    return rs;
}

Compilation message

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:45:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < a.size(); i++){
      |                     ~~^~~~~~~~~~
floppy.cpp:52:13: warning: unused variable 'inir' [-Wunused-variable]
   52 |         int inir = r;
      |             ^~~~
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 1 ms 812 KB Output is correct
2 Correct 1 ms 812 KB Output is correct
3 Correct 1 ms 812 KB Output is correct
4 Correct 0 ms 812 KB Output is correct
5 Correct 1 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2880 KB Output is correct
2 Correct 14 ms 2844 KB Output is correct
3 Correct 16 ms 2852 KB Output is correct
4 Correct 16 ms 2856 KB Output is correct
5 Correct 13 ms 2876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 9304 KB Output is correct
2 Correct 54 ms 9440 KB Output is correct
3 Correct 53 ms 9148 KB Output is correct
4 Correct 55 ms 12776 KB Output is correct
5 Correct 53 ms 13012 KB Output is correct