E. Data Structures Fan
非常有意思的一道思维题!!!!
先上两个题解:
题解1:
题解2:
总的思路就是伪“前缀和”,然后维护选0还是选1的异或和就够了。
如果改变,就直接像前缀和那样改,证明理由就是0^a = a ;a^a =0;
代码:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
ll a[N];
int main()
{
ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
ll t; cin >> t;
while (t--)
{
ll n; cin >> n;
for (int i = 1; i <= n; i++)cin >> a[i];
string s; cin >> s;
ll ans = 0; ll ansz = 0;
for (int i = 0; i < s.length(); i++)
if (s[i] - '0')
if (!ans)ans = a[i + 1];
else ans ^= a[i + 1];
else
if (!ansz)ansz = a[i + 1];
else ansz ^= a[i + 1];
for (int i = 1; i <= n; i++)
a[i] ^= a[i - 1];
ll q; cin >> q;
while (q--)
{
ll op; cin >> op;
if (op == 1)
{
ll x, y; cin >> x >> y;
ans ^= a[x - 1] ^ a[y];
ansz ^= a[x - 1] ^ a[y];
}
else
{
int t; cin >> t;
if(t)cout << ans << ' ';
else cout << ansz << ' ';
}
}
cout << '\n';
}
return 0;
}