Submission #1056846

#TimeUsernameProblemLanguageResultExecution timeMemory
1056846allin27xFloppy (RMI20_floppy)C++17
100 / 100
67 ms13412 KiB
#include <bits/stdc++.h> using namespace std; const int N = 40004; int t[4*N]; int ar[N]; int n; string ans=""; void build(int p, int l, int r){ if (l==r){ t[p] = l; return; } int m = (l+r)/2; build(2*p, l, m); build(2*p+1, m+1, r); t[p] = ar[t[2*p]] > ar[t[2*p+1]] ? t[2*p] : t[2*p+1]; } void build(){build(1, 0, n-1);} int query(int p, int tl, int tr, int l, int r){ if (l>r) return -1; if (tl==l && tr==r) return t[p]; int tm = (tl+tr)/2; int a = query(2*p, tl, tm, l, min(r,tm)); int b = query(2*p+1, tm+1, tr, max(tm+1,l), r); if (a==-1 && b==-1) return -1; if (a==-1) return b; if (b==-1) return a; if (ar[a] > ar[b]) return a; else return b; } int query(int l, int r){return query(1,0,n-1,l,r);} void save_to_floppy(const string &bits); void encode(int l, int r){ if (l==r){ ans+="00"; return; } int m = query(l,r); if (m==l){ ans += "01"; encode(m+1, r); } else if (m==r){ ans += "10"; encode(l, m-1); } else { ans += "11"; encode(l, m-1); encode(m+1, r); } } void read_array(int subt, const vector<int> &v){ n = v.size(); for (int i=0; i<n; i++) ar[i] = v[i]; build(); encode(0,n-1); save_to_floppy(ans); } int szl[N]; int szr[N]; int ind = 0; void dfs(){ int l = ans[2*ind]=='1'; char r = ans[2*ind+1]=='1'; if (!l && !r) return; int old_ind = ind; ind+=1; dfs(); if (!l){ szr[old_ind] = ind-old_ind; return; } if (!r){ szl[old_ind] = ind-old_ind; return; } szl[old_ind] = ind-old_ind; int old_ind1 = ind; ind+=1; dfs(); szr[old_ind] = ind - old_ind1; } void decode(int i, int l, int r, int cd){ if (l>r) return; if (l==r){ ar[l] = cd; return; } int m = l + szl[i]; ar[m] = cd; decode(i+1, l, m-1, cd-1); decode(i+1+szl[i], m+1, r, cd-1); } vector<int> solve_queries(int subt, int N, const string &bits, const vector<int> &a, const vector<int> &b){ n = N; ans = bits; dfs(); decode(0, 0, N-1, N); build(); // for (int i=0; i<N; i++) cout<<szl[i]<<szr[i]<<'\n'; vector<int> ans(a.size()); for (int i=0; i<a.size(); i++){ ans[i] = query(a[i],b[i]); } return ans; }

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:101:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |  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...