제출 #1337239

#제출 시각아이디문제언어결과실행 시간메모리
1337239AndreyPavlovFloppy (RMI20_floppy)C++20
100 / 100
56 ms4140 KiB
#include <stdlib.h>
#include <string.h>
#include <stack>
#include <iostream>

#include "floppy.h"

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

std::vector<int> solve_queries(int subtask_id, int N,
        const std::string &bits,
        const std::vector<int> &a, const std::vector<int> &b) {
    std::vector <int> st;
    int j = 0;
    std::vector <std::vector <std::pair <int, int>>> v(N);
    std::vector <int> answer(a.size());
    for (int i = 0; i < a.size(); ++i) {
        v[b[i]].push_back({a[i], i});
    }
    for (char i : bits) {
        if (i == '0') {
            st.push_back(j);
            for (auto [x, y]: v[j]) {
                answer[y] = *std::lower_bound(st.begin(), st.end(), x);
            }
            ++j;
        } else {
            st.pop_back();
        }
    }
    /*for (int i = 0; i < answer.size(); ++i) {
        std::cout << a[i] << ' ' << b[i] << ' ' << answer[i] << '\n';
    }*/
    return answer;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...