Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // KEEP IT SIMPLE //
- #include<bits/stdc++.h>
- using namespace std;
- #define int long long
- #define MAX 100
- const int inf = 9e18;
- const double pi = acos(-1.0);
- const int M = 1e9 + 7;
- const int N = 1e5 + 5;
- int gccd(int a, int b){ if(a == 0) return b; return gccd(b % a, a); }
- int power(int x, unsigned int y){ int temp; if( y == 0) return 1; temp = power(x, y/2);
- if (y%2 == 0) return temp * temp; else return x * temp * temp;
- }
- int res[1000005], n;
- int BITree[1000005];
- int getSum(int index)
- {
- int sum = 0;
- while (index>0)
- {
- sum ^= BITree[index];
- index -= index & (-index);
- }
- return sum;
- }
- void updateBIT(int index, int val)
- {
- while (index <= n)
- {
- BITree[index] ^= val;
- index += index & (-index);
- }
- }
- int32_t main()
- {
- ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
- cin >> n;
- for(int i = 1 ; i <= n; i++)
- {
- cin >> res[i];
- updateBIT(i, res[i]);
- }
- int q;
- cin >> q;
- while(q--)
- {
- int l, r, pos;
- cin >> l >> r >> pos;
- int ans = getSum(r) ^ getSum(l - 1);
- int pro(0), p = ans;
- while(ans)
- {
- ans >>= 1;
- pro <<= 1;
- pro |= 1;
- }
- //cout << p << " " << pro << endl;
- if(p == pro)
- {
- cout << -1 << endl;
- }
- else
- {
- cout << (p ^ pro) << endl;
- updateBIT(pos, res[pos]);
- res[pos] = (p ^ pro);
- updateBIT(pos, res[pos]);
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment