Submission #584733

# Submission time Handle Problem Language Result Execution time Memory
584733 2022-06-27T23:33:06 Z Deepesson Floppy (RMI20_floppy) C++17
100 / 100
122 ms 22496 KB
///Encoder
#include <bits/stdc++.h>

void save_to_floppy(const std::string &bits);

//#include "floppy.h"

void read_array(int subtask_id, const std::vector<int> &v) {
    std::string answer;
    std::stack<int> stk;
    for(int i=0;i!=v.size();++i){
        auto x = v[i];
        while(stk.size()&&x>=stk.top()){
            answer+="0";
            stk.pop();
        }
        answer+="1";
        stk.push(v[i]);
    }
    save_to_floppy(answer);
}

///Solver
#include <bits/stdc++.h>

#define MAX 205000
typedef std::pair<int,int> pii;

std::vector<pii> queries[MAX];

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> answers;
    for(int i=0;i!=a.size();++i)answers.push_back(-1);
    for(int i=0;i!=a.size();++i){
        queries[b[i]].push_back({a[i],i});
    }
    int cur=0;
    std::vector<pii> stack;
    for(int i=0;i!=N;++i){
        int min=i;
        while(bits[cur]!='1'){
            min=std::min(min,stack.back().second);
            ++cur;
            stack.pop_back();
        }
        stack.push_back({i,min});
        ++cur;
        for(auto&x:queries[i]){
            int la=0,ra=stack.size()-1;
            while(la<ra){
                int m = (la+ra)/2;
                if(stack[m].second<x.first){
                    la=m+1;
                }else ra=m;
            }
            if(la&&stack[la].second>x.first)--la;
            answers[x.second]=stack[la].first;
        }
    }
    return answers;
}

Compilation message

floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:11:18: 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){
      |                 ~^~~~~~~~~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i=0;i!=a.size();++i)answers.push_back(-1);
      |                 ~^~~~~~~~~~
floppy.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     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 6 ms 10272 KB Output is correct
2 Correct 8 ms 10284 KB Output is correct
3 Correct 7 ms 10264 KB Output is correct
4 Correct 10 ms 10284 KB Output is correct
5 Correct 12 ms 10284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 12232 KB Output is correct
2 Correct 27 ms 12988 KB Output is correct
3 Correct 31 ms 13128 KB Output is correct
4 Correct 28 ms 12932 KB Output is correct
5 Correct 25 ms 13088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 18716 KB Output is correct
2 Correct 92 ms 22168 KB Output is correct
3 Correct 122 ms 22496 KB Output is correct
4 Correct 117 ms 22340 KB Output is correct
5 Correct 91 ms 22176 KB Output is correct