Submission #533795

#TimeUsernameProblemLanguageResultExecution timeMemory
533795amunduzbaevFloppy (RMI20_floppy)C++17
100 / 100
92 ms21580 KiB
#include "bits/stdc++.h" using namespace std; #include "floppy.h" #ifndef EVAL #include "grader.cpp" #endif const int MAX = 4e4 + 5; int st[MAX][20]; void read_array(int QOQ, const vector<int> &v) { int n = (int)v.size(); for(int i=0;i<n;i++) st[i][0] = i; for(int j=1;j<20;j++){ int d = (1 << (j - 1)); for(int i=0;i + d < n;i++){ st[i][j] = st[i][j-1]; if(v[st[i + d][j-1]] > v[st[i][j]]){ st[i][j] = st[i + d][j-1]; } } } auto get = [&](int l, int r){ int lg = __lg(r - l + 1); if(v[st[l][lg]] >= v[st[r - (1 << lg) + 1][lg]]) return st[l][lg]; return st[r - (1 << lg) + 1][lg]; }; string res(2 * n, '0'); int last = 0; function<void(int, int, int)> rec = [&](int l, int r, int x){ int m = get(l, r); //~ cout<<m<<" "<<x<<"\n"; if(l < m) res[x<<1] = '1', rec(l, m - 1, ++last); if(m < r) res[x<<1|1] = '1', rec(m + 1, r, ++last); }; rec(0, n - 1, 0); //~ cout<<"\n"; save_to_floppy(res); } /* 3 4 10 4 2 3 1 0 0 0 0 1 0 0 2 0 0 3 0 1 1 1 1 2 2 1 3 2 2 2 2 2 3 2 3 3 3 */ vector<int> solve_queries(int QOQ, int n, const string &tree, const vector<int> &a, const vector<int> &b) { int m = a.size(); vector<int> v(n, -1); int p = 0; int last = 0; function<int(int)> rec = [&](int x){ int mx = 0; if(tree[x<<1] == '1') mx = max(mx, rec(++last) + 1); int pos = p++; if(tree[x<<1|1] == '1') mx = max(mx, rec(++last) + 1); v[pos] = mx; //~ cout<<pos<<" "<<x<<"\n"; return mx; }; rec(0); //~ for(int i=0;i<n;i++) cout<<v[i]<<" "; //~ cout<<"\n"; for(int i=0;i<n;i++){ st[i][0] = i; assert(~v[i]); } for(int j=1;j<20;j++){ int d = (1 << (j - 1)); for(int i=0;i + d < n;i++){ st[i][j] = st[i][j-1]; if(v[st[i + d][j-1]] > v[st[i][j]]){ st[i][j] = st[i + d][j-1]; } } } auto get = [&](int l, int r){ int lg = __lg(r - l + 1); if(v[st[l][lg]] >= v[st[r - (1 << lg) + 1][lg]]) return st[l][lg]; return st[r - (1 << lg) + 1][lg]; }; vector<int> res; for(int i=0;i<m;i++){ res.push_back(get(a[i], b[i])); } return res; }

Compilation message (stderr)

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...