Submission #926723

#TimeUsernameProblemLanguageResultExecution timeMemory
926723vjudge1Floppy (RMI20_floppy)C++17
100 / 100
71 ms13924 KiB
#include "floppy.h" #include<bits/stdc++.h> using namespace std; const int MAXK = 16; int sp[MAXK][40100]; string ansss; vector <int> a; int best(int x,int y){ if (a[x] > a[y])return x; return y; } int lg[40100]; int id=0; void solve(int l,int r,int node = id++){ if (l > r)return; int sz = lg[r-l+1]; int mid = best(sp[sz][l],sp[sz][r-(1<<sz)+1]); ansss[node<<1] = ansss[node<<1|1] = '0'; if (mid > l){ solve(l,mid-1); ansss[node<<1] = '1'; } if (mid < r){ ansss[node<<1|1] = '1'; solve(mid+1,r); } } int n; void read_array(int subtask, const vector<int> &v) { n = v.size(); lg[1] = 0; for (int i = 2;i <= n;i ++)lg[i] = lg[i/2] + 1; a = v; for (int i = 0;i < n;i ++){ sp[0][i] = i; } for (int j = 1;j < MAXK;j ++){ for (int i = 0;i + (1<<j) - 1 < n;i++){ sp[j][i] = best(sp[j-1][i],sp[j-1][i+(1<<(j-1))]); } } ansss.resize(2*n); solve(0,n-1); save_to_floppy(ansss); } string mom; int cur = 0; int depth[40100]; int sex[40100]; void decode(int node = id++){ if (mom[node<<1] == '1'){ decode(); } sex[cur++] = node; if (mom[node<<1|1] == '1'){ decode(); } } int best2(int x,int y){ if (sex[x] < sex[y])return x; return y; } vector<int> solve_queries(int subtask, int n, const string &data, const vector<int> &a,const vector<int> &b) { vector<int> anssswer(a.size()); lg[1] = 0; for (int i = 2;i <= n;i ++){ lg[i] = lg[i>>1] + 1; } mom = data; id = 0; cur = 0; decode(); for (int i = 0;i < n;i ++){ sp[0][i] = i; } for (int j = 1;j < MAXK;j ++){ for (int i = 0;i + (1<<j) - 1 < n;i ++){ sp[j][i] = best2(sp[j-1][i],sp[j-1][i + (1<<(j-1))]); } } for (int i = 0;i < a.size();i++){ int l = a[i]; int r = b[i]; int sz = lg[r - l + 1]; anssswer[i] = best2(sp[sz][l],sp[sz][r - (1<<sz) + 1]); } return anssswer; }

Compilation message (stderr)

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     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...