This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize "O3"
#pragma GCC optimize "unroll-loops"
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct pi {
int a,b;
bool operator<(const pi& o) const {
return a<o.a;
}
};
const int mxN = 1e5+1, oo = 1e9;
const int B = 10;
struct DS {
pi best[1<<B][1<<B][B*2+1] = {};
char popcnt[1<<B];
static void cmax(pi& a, const pi& b) {
a = max(a,b);
}
DS() {
for(int i=0;i<1<<B;++i) popcnt[i]=__builtin_popcount(i);
}
static pair<int,int> split(int a) {
return {a&((1<<B)-1),a>>B};
}
void insert(int a, const pi& v) {
auto [l,r] = split(a);
for(int msk=0;msk<1<<B;++msk) {
cmax(best[r][msk][popcnt[msk&a]],v);
}
}
pi query(int a, int k) {
auto [l,r] = split(a);
pi res = {};
for(int msk=0;msk<1<<B;++msk) {
int pp = popcnt[msk&r];
if(pp<=k) {
cmax(res,best[msk][l][k-pp]);
}
}
return res;
}
} *ds = new DS();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n;
vi a(n);
vector<short> k(n);
for(auto& i : a) cin >> i;
for(auto& i : k) cin >> i;
vi dp(n),par(n,-1);
for(int i=0;i<n;++i) {
auto [v,pr] = ds->query(a[i],k[i]);
if(v) par[i]=pr;
dp[i]=v+1;
ds->insert(a[i],{dp[i],i});
}
// recover solution
auto it = max_element(all(dp));
int i = it-dp.begin();
cout << *it << '\n';
vi b;
while(i!=-1) {
b.push_back(i+1);
i=par[i];
}
reverse(all(b));
cout << b << '\n';
}
Compilation message (stderr)
subsequence.cpp: In member function 'void DS::insert(int, const pi&)':
subsequence.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | auto [l,r] = split(a);
| ^
subsequence.cpp:35:43: warning: array subscript has type 'char' [-Wchar-subscripts]
35 | cmax(best[r][msk][popcnt[msk&a]],v);
| ~~~~~~~~~~~~^
subsequence.cpp: In member function 'pi DS::query(int, int)':
subsequence.cpp:39:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | auto [l,r] = split(a);
| ^
subsequence.cpp: In function 'int main()':
subsequence.cpp:60:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | auto [v,pr] = ds->query(a[i],k[i]);
| ^
# | 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... |