SHARE
TWEET

Untitled

a guest Nov 12th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define ll long long
  4. using namespace std;
  5. const ll maxn = (ll)1e5 + 1;
  6. vector<ll> numbers(maxn);
  7. vector<ll> tree(4*maxn);
  8. bool flip;
  9. ll n, m, a, p, b;
  10.  
  11. void build(int pos, int i, int j){
  12.     int esq = 2*pos;
  13.     int dir = 2*pos + 1;
  14.     int mid = (i+j)/2;
  15.  
  16.     if(i == j){
  17.         tree[pos] = numbers[i];
  18.     }else{
  19.         tree[pos] = 0;
  20.         build(esq, i, mid);
  21.         build(dir, mid+1,j);
  22.         if(!flip) tree[pos] = tree(esq) | tree(dir);
  23.         else tree[pos] = tree(esq) ^ tree(dir);
  24.         flip = !flip;
  25.  
  26.     }
  27.  
  28. }
  29.  
  30. int update(int pos,int i, int j, int x, int value){
  31.     int esq = 2*pos;
  32.     int dir = 2*pos + 1;
  33.     int mid = (i+j)/2;
  34.     if(i == j){
  35.         tree[pos] = value;
  36.     }else{
  37.         if(!flip){
  38.         if(x <= mid) tree[pos] = update(esq, i, mid, x, value) | tree[dir];
  39.         else tree[pos] = tree[esq] | update(dir, mid+i, j, x, value);
  40.         }
  41.         else{
  42.             if(x <= mid) tree[pos] = update(esq, i, mid, x, value) ^ tree[dir];
  43.             else tree[pos] = tree[esq] ^ update(dir, mid+i, j, x, value);
  44.         }
  45.         flip = !flip;
  46.     }
  47.     return tree[pos];
  48. }
  49. int main(){
  50.     cin.tie(0);
  51.     ios::sync_with_stdio(0);
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top