CF1582F2 Korney Korneevich and XOR (hard version)
1582F2. Korney Korneevich and XOR (hard version)
看到题目一个基本的想法是设
实际上从前往后考虑的时候我们并不关心当前位置,因此实际有用的状态只有
但是这个状态设计有些鸡肋,我们没办法优化。换个 DP 方法:设
此外,对于同一个
复杂度分析:枚举复杂度:每个
const int V = 1 << 13;
int n, ans = 1, vis[V], mx[V];
vint buc[V];
int main() {
cin >> n, vis[0] = 1;
for(int i = 1; i < V; i++) buc[i].pb(0), mx[i] = V - 1;
for(int i = 1; i <= n; i++) {
int a = read();
for(int it : buc[a]) {
int p = it ^ a; ans += !vis[p], vis[p] = 1;
while(mx[p] > a) buc[mx[p]--].pb(p);
} buc[a] = {};
} cout << ans << endl;
for(int i = 0; i < V; i++)
if(vis[i]) cout << i << " ";
cout << endl;
return 0;
}