using
System;
using
System.Collections.Generic;
class
GFG{
static
int
bitsSize = 32;
class
Pair{
public
int
first;
public
int
second;
public
Pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
int
toDecimal(
int
[]result,
int
size)
{
int
ans = 0;
for
(
int
i = 0; i < size; i++)
{
if
(result[i] != 0)
ans += (
int
)Math.Pow(2, i);
}
return
ans;
}
static
void
findOrUtil(
int
[]result,
int
old_value,
int
new_value)
{
int
i = 0;
while
(old_value != 0)
{
result[i] -= old_value % 2;
old_value = old_value / 2;
i++;
}
i = 0;
while
(new_value != 0)
{
result[i] += new_value % 2;
new_value = new_value / 2;
i++;
}
}
static
void
findOR(
int
[] arr, List<Pair> queries)
{
int
[]result =
new
int
[bitsSize];
for
(
int
i = 0; i < arr.Length; i++)
{
int
val = arr[i];
int
j = 0;
while
(val != 0)
{
result[j] += val % 2;
val = val / 2;
j++;
}
}
for
(
int
q = 0; q < queries.Count; q++)
{
int
index = queries[q].first;
int
new_value = queries[q].second;
findOrUtil(result, arr[index], new_value);
arr[index] = new_value;
int
ans = toDecimal(result, bitsSize);
Console.WriteLine(ans);
}
}
public
static
void
Main(String[] args)
{
int
[]arr = { 1, 2, 3, 4 };
List<Pair> queries =
new
List<Pair>();
queries.Add(
new
Pair(3, 0));
queries.Add(
new
Pair(1, 8));
findOR(arr, queries);
}
}