Submission #169831

#TimeUsernameProblemLanguageResultExecution timeMemory
169831super_j6Longest beautiful sequence (IZhO17_subsequence)C++14
40 / 100
6099 ms9300 KiB
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define endl '\n' #define pi pair<int, int> struct trie{ trie *l, *r; int maxv = 0; pi val = {0, -1}; trie(){ l = r = NULL; } void add(int x, pi v, int d = 20){ if(d < 0){ val = max(val, v); return; } if(x & (1 << d)){ if(!r) r = new trie(); r->add(x, v, d - 1); maxv = max(maxv, 1 + r->maxv); }else{ if(!l) l = new trie(); l->add(x, v, d - 1); maxv = max(maxv, l->maxv); } } pi qry(int x, int b, int d = 20){ if(b < 0 || maxv < b || __builtin_popcount(x & ((1 << (d + 1)) - 1)) < b) return (pi){0, -1}; if(d < 0){ return val; } return max(l ? l->qry(x, b, d - 1) : (pi){0, -1}, r ? r->qry(x, b - ((x >> d) & 1), d - 1) : (pi){0, -1}); } }; const int maxn = 100000; int n; int a[maxn], b[maxn]; pi dp[maxn]; trie t; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < n; i++) cin >> b[i]; int ret = 0; for(int i = 0; i < n; i++){ dp[i] = t.qry(a[i], b[i]); dp[i].first++; t.add(a[i], {dp[i].first, i}); if(dp[ret].first < dp[i].first) ret = i; } vector<int> ans; while(ret != -1){ ans.push_back(ret + 1); ret = dp[ret].second; } reverse(ans.begin(), ans.end()); cout << ans.size() << endl; cout << ans[0]; for(int i = 1; i < ans.size(); i++) cout << " " << ans[i]; cout << endl; return 0; }

Compilation message (stderr)

subsequence.cpp: In function 'int main()':
subsequence.cpp:77:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < ans.size(); i++) cout << " " << ans[i];
                 ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...