This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = 1e6 + 5, mod = 1e9 + 7, LOG = 20;
int n, a[mxN], k[mxN], p[mxN], dp[mxN];
set <pair <int, pair <int, int> > > st[(1 << 11)][(1 << 11)];
int mask1[mxN], mask2[mxN];
int main() {
ios :: sync_with_stdio(false), cin.tie(nullptr);
cin >> n;
vector <int> f, s;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
for (int j = 0; j < 10; ++j) {
if ((a[i] >> j) & 1) mask1[i] += (1 << j);
}
for (int j = 10; j < 20; ++j) {
if ((a[i] >> j) & 1) mask2[i] += (1 << (j - 10));
}
f.push_back(mask1[i]); s.push_back(mask2[i]);
}
for (int i = 1; i <= n; ++i) cin >> k[i];
sort(f.begin(), f.end());
f.erase(unique(f.begin(), f.end()), f.end());
sort(s.begin(), s.end());
s.erase(unique(s.begin(), s.end()), s.end());
pair <int, int> ans = {0, 0};
for (int i = 1; i <= n; ++i) {
dp[i] = 1;
{ // get
for (auto mask : f) {
int x = k[i] - __builtin_popcount(mask1[i] & mask);
auto up = st[mask][mask2[i]].lower_bound({x, {-mod, 0}});
if (up != st[mask][mask2[i]].end() && up -> first == x) {
pair <int, int> y = up -> second;
if (-y.first + 1 > dp[i]) {
p[i] = y.second;
dp[i] = -y.first + 1;
}
}
}
}
{ // upd
for (auto mask : s)
st[mask1[i]][mask].insert({__builtin_popcount(mask & mask2[i]), {-dp[i], i}});
}
ans = max(ans, {dp[i], i});
}
int now = ans.second;
vector <int> seq;
while (now > 0) {
seq.push_back(now);
now = p[now];
}
reverse(seq.begin(), seq.end());
cout << (int)seq.size() << '\n';
for (auto x : seq) cout << x << ' ';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |