답안 #924398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924398 2024-02-09T02:42:43 Z huutuan Floppy (RMI20_floppy) C++14
100 / 100
77 ms 16848 KB
#include "floppy.h"

#include <bits/stdc++.h>

using namespace std;

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

vector<int> solve_queries(int subtask_id, int n, const string &bits,
                          const vector<int> &a, const vector<int> &b) {
   vector<int> l(n);
   stack<int> st;
   vector<vector<pair<int, int>>> sparse(16, vector<pair<int, int>>(n));
   int idx=0;
   for (int i=0; i<n; ++i){
      while (bits[idx]=='0') st.pop(), ++idx;
      l[i]=st.size()?st.top():-1;
      sparse[0][i]={l[i], -i};
      st.push(i);
      ++idx;
   }
   for (int i=1; i<16; ++i) for (int j=0; j+(1<<i)<=n; ++j) sparse[i][j]=min(sparse[i-1][j], sparse[i-1][j+(1<<(i-1))]);
   vector<int> ans;
   auto get=[&](int l, int r) -> pair<int, int> {
      int lg=__lg(r-l+1);
      return min(sparse[lg][l], sparse[lg][r-(1<<lg)+1]);
   };
   for (int i=0; i<(int)a.size(); ++i){
      ans.push_back(-get(a[i], b[i]).second);
   }
   return ans;
}

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) {
      |         ~~~~~~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 816 KB Output is correct
2 Correct 3 ms 824 KB Output is correct
3 Correct 1 ms 828 KB Output is correct
4 Correct 1 ms 1072 KB Output is correct
5 Correct 2 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 4784 KB Output is correct
2 Correct 17 ms 4792 KB Output is correct
3 Correct 17 ms 4780 KB Output is correct
4 Correct 16 ms 4828 KB Output is correct
5 Correct 17 ms 4788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 16848 KB Output is correct
2 Correct 66 ms 16600 KB Output is correct
3 Correct 62 ms 16392 KB Output is correct
4 Correct 68 ms 16680 KB Output is correct
5 Correct 77 ms 16524 KB Output is correct