版本比较
题解:P15078 [ICPC 2024 Chengdu R] Expanding Array
正文
增加 5 行删除 5 行
11 行未改动121314151616171819203 行未改动2425262728282930313220 行未改动5354555657575859606161626364654 行未改动707172737474757677782 行未改动11 行未改动
具体来说,把 $0$ 和以下 $7$ 种运算的结果全部收集起来,去重后集合的大小就是答案:
- $x$ - $x$
- $y$
- $x$ 与 $y$ 的按位与3 行未改动- $x$ 与 $y$ 的按位异或
- $x$ 异或上 $x$ 与 $y$ 的按位与
- $y$ 异或上 $x$ 与 $y$ 的按位与
:::info[证明:为什么结论成立]20 行未改动
int main(){ ios::sync_with_stdio(0); cin.tie(0);
int n; cin>>n; for(int i=0;i<n;i++) cin>>a[i];
unordered_set<int>st; st.insert(0); for(int i=1;i<n;i++){ int x=a[i],y=a[i-1];4 行未改动 st.insert(x^y); st.insert(x^(x&y)); st.insert(y^(x&y)); }
cout<<st.size(); return 0;}```2 行未改动