CF1718A2 Burenka and Traditions (hard version)
CF1718A2 Burenka and Traditions (hard version)
考察长度除以
如果长度为
- 操作长度
1 或2 。 - 长度为
1 的操作和长度为2 的操作不重叠。 - 长度为
1 的操作之间不重叠,长度为2 的操作之间不完全重合,但可以相交。
考虑一段相邻相交的极长的连续的长度为
因此,从原序列中选出若干段异或和为
时间复杂度
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1e5 + 5;
int n, a[N];
void solve() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
int ans = n, S = 0;
map<int, int> mp;
mp[0] = 1;
for(int i = 1; i <= n; i++) {
S ^= a[i];
if(mp.find(S) != mp.end()) {
ans--;
mp.clear();
mp[S = 0] = 1;
}
else mp[S] = 1;
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
int T = 1;
cin >> T;
while(T--) solve();
return 0;
}