제출 #474469

#제출 시각아이디문제언어결과실행 시간메모리
474469AlexandruabcdeFloppy (RMI20_floppy)C++14
100 / 100
104 ms15760 KiB
#include <stdlib.h> #include <string.h> #include "floppy.h" #include <iostream> std::vector <std::vector <int> > RMQ; std::vector <int> Log; std::vector <int> arr; std::string floppy; void Precompute_RMQ (std::vector<int> v) { Log.resize(v.size()+1); arr.resize(v.size()); for (int i = 0; i < v.size(); ++ i ) arr[i] = v[i]; Log[1] = 0; for (int i = 2; i <= v.size(); ++ i ) Log[i] = Log[i/2] + 1; RMQ.resize(Log[v.size()]+1); RMQ[0].resize(v.size()); for (int i = 0; i < v.size(); ++ i ) RMQ[0][i] = i; for (int lg = 1; lg <= Log[v.size()]; ++ lg ) { RMQ[lg].resize(v.size()); for (int i = 0; i + (1<<lg) - 1 < v.size(); ++ i ) { int poz_st = RMQ[lg-1][i]; int poz_dr = RMQ[lg-1][i+(1<<(lg-1))]; if (arr[poz_st] > arr[poz_dr]) RMQ[lg][i] = poz_st; else RMQ[lg][i] = poz_dr; } } } int Answer_RMQ (int L, int R) { int k = Log[R-L+1]; int poz_st = RMQ[k][L]; int poz_dr = RMQ[k][R-(1<<k)+1]; if (arr[poz_st] > arr[poz_dr]) return poz_st; else return poz_dr; } void DFS (int L, int R) { if (L > R) return; int position = Answer_RMQ(L, R); if (position == L) floppy.push_back('0'); else floppy.push_back('1'); if (position == R) floppy.push_back('0'); else floppy.push_back('1'); DFS(L, position-1); DFS(position+1, R); } void read_array(int subtask_id, const std::vector<int> &v) { Precompute_RMQ(v); DFS(0, v.size()-1); arr.clear(); RMQ.clear(); Log.clear(); save_to_floppy(floppy); } int global_index = 0; int position = 0; void FindArray (int depth = 1) { char st = floppy[global_index*2]; char dr = floppy[global_index*2+1]; if (st == '1') { global_index++; FindArray(depth+1); } arr[position] = depth; ++ position; if (dr == '1') { global_index++; FindArray(depth+1); } } void Precompute_NEW_RMQ () { Log.resize(arr.size()+1); Log[1] = 0; for (int i = 2; i <= arr.size(); ++ i ) Log[i] = Log[i/2] + 1; RMQ.resize(Log[arr.size()]+1); for (int i = 0; i <= Log[arr.size()]; ++ i ) RMQ[i].resize(arr.size()); for (int i = 0; i < arr.size(); ++ i ) RMQ[0][i] = i; for (int lg = 1; lg <= Log[arr.size()]; ++ lg ) for (int i = 0; i + (1<<lg) - 1 < arr.size(); ++ i ) { int poz_st = RMQ[lg-1][i]; int poz_dr = RMQ[lg-1][i+(1<<(lg-1))]; if (arr[poz_st] < arr[poz_dr]) RMQ[lg][i] = poz_st; else RMQ[lg][i] = poz_dr; } } int Answer_NEW_RMQ (int L, int R) { int k = Log[R-L+1]; int poz_st = RMQ[k][L]; int poz_dr = RMQ[k][R-(1<<k)+1]; if (arr[poz_st] < arr[poz_dr]) return poz_st; else return poz_dr; } 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> ans; floppy = bits; arr.resize(floppy.size()/2); FindArray(0); Precompute_NEW_RMQ(); for (int i = 0; i < a.size(); ++ i ) ans.push_back(Answer_NEW_RMQ(a[i], b[i])); return ans; }

컴파일 시 표준 에러 (stderr) 메시지

floppy.cpp: In function 'void Precompute_RMQ(std::vector<int>)':
floppy.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i < v.size(); ++ i )
      |                     ~~^~~~~~~~~~
floppy.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 2; i <= v.size(); ++ i )
      |                     ~~^~~~~~~~~~~
floppy.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < v.size(); ++ i )
      |                     ~~^~~~~~~~~~
floppy.cpp:30:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int i = 0; i + (1<<lg) - 1 < v.size(); ++ i )  {
      |                         ~~~~~~~~~~~~~~~~^~~~~~~~~~
floppy.cpp: In function 'void Precompute_NEW_RMQ()':
floppy.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (int i = 2; i <= arr.size(); ++ i )
      |                     ~~^~~~~~~~~~~~~
floppy.cpp:100:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for (int i = 0; i < arr.size(); ++ i )
      |                     ~~^~~~~~~~~~~~
floppy.cpp:104:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for (int i = 0; i + (1<<lg) - 1 < arr.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:130:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...