Submission #649745

#TimeUsernameProblemLanguageResultExecution timeMemory
649745dariaFloppy (RMI20_floppy)C++17
0 / 100
132 ms31116 KiB
#include "bits/stdc++.h" #include "floppy.h" using namespace std; const int F = (1 << 17); int n; string ans; vector<string> bit(F, ""); vector<int> adj[F]; void dfs(int s){ ans += bit[s]; for(auto u : adj[s]) dfs(u); } void solve(const vector<int> &v, int l, int r, int p){ int mx = -1, id = -1; for(int i=l; i<r; ++i) if(v[i] > mx){ mx = v[i]; id = i;} if(p != -1) adj[p].push_back(v[id]); if(id == l) bit[v[id]] += '0'; else bit[v[id]] += '1'; if(id == r-1) bit[v[id]] += '0'; else bit[v[id]] += '1'; if(id != l) solve(v, l, id, v[id]); if(id != r-1) solve(v, id+1, r, v[id]); } void read_array(int subtask_id, const std::vector<int> &v) { n = v.size(); vector<pair<int, int> > v0(n); for(int i=0; i<n; ++i) v0[i] = {v[i], i}; sort(v0.begin(), v0.end()); vector<int> v1(n); for(int i=0; i<n; ++i) v1[v0[i].second] = i; solve(v1, 0, n, -1); dfs(n-1); //cout << ans << endl; save_to_floppy(ans); } vector<int> sz(F, 1), l(F, 0), val(F, 0); bool vis[F]; int nxt = 0; void rdfs(int id, int z, const string &st){ //cout << id << endl; if(vis[id]) return; vis[id] = 1; val[id] = z; if(st[2*id] == '1'){ l[id+1] += l[id]; //cout << "+ l padre: " << id+1 << " " << l[id+1] << endl; rdfs(id+1, z+1, st); sz[id] += sz[id+1]; l[id] += sz[id+1]; //cout << "+ sz figlio sx: " <<id << " " << l[id] << endl; } if(st[2*id+1] == '1'){ while(vis[nxt]) nxt++; l[nxt] += l[id] + 1; rdfs(nxt, z+1, st); sz[id] += sz[nxt]; //cout << "+ l padre + 1: " << nxt << " " << l[nxt] << endl; } } vector<pair<int, int> > st(2*F, {F, -1}); pair<int, int> query(int v, int tl, int tr, int l, int r){ if(r <= tl || tr <= l) return {F, -1}; if(l <= tl && tr <= r) return st[v]; int tm = (tl +tr)/2; return min(query(2*v, tl, tm, l, r), query(2*v+1, tm, tr, l , r)); } std::vector<int> solve_queries(int subtask_id, int n,const std::string &bits, const std::vector<int> &a, const std::vector<int> &b) { rdfs(0, 0, bits); vector<int> v(n); for(int i=0; i<n; ++i) st[F+l[i]] = {val[i], l[i]}; for(int i=F-1; i>0; --i) st[i] = min(st[2*i], st[2*i+1]); vector<int> res; for(int i=0; i<a.size(); ++i) res.push_back(query(1, 0, F, a[i], b[i]+1).second); res.resize(a.size()); return res; }

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:90:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |  for(int i=0; i<a.size(); ++i) res.push_back(query(1, 0, F, a[i], b[i]+1).second);
      |               ~^~~~~~~~~
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...