using
System;
class
GFG {
static
int
getMiddleValue(
int
low,
int
high)
{
return
low + (high - low) / 2;
}
static
int
getSumUtil(
int
[] st,
int
low,
int
high,
int
L,
int
R,
int
node)
{
if
(L <= low && R >= high)
return
st[node];
if
(high < L || low > R)
return
0;
int
mid = getMiddleValue(low, high);
return
getSumUtil(st, low, mid, L, R, 2 * node + 1)
+ getSumUtil(st, mid + 1, high, L, R,
2 * node + 2);
}
static
void
updateValueUtil(
int
[] st,
int
low,
int
high,
int
i,
int
diff,
int
node)
{
if
(i < low || i > high)
return
;
st[node] = st[node] + diff;
if
(high != low) {
int
mid = getMiddleValue(low, high);
updateValueUtil(st, low, mid, i, diff,
2 * node + 1);
updateValueUtil(st, mid + 1, high, i, diff,
2 * node + 2);
}
}
static
void
updateValue(
int
[] arr,
int
[] st,
int
n,
int
i,
int
new_val)
{
int
diff = new_val - arr[i];
arr[i] = new_val;
updateValueUtil(st, 0, n - 1, i, diff, 0);
}
static
int
getSum(
int
[] st,
int
n,
int
L,
int
R)
{
return
getSumUtil(st, 0, n - 1, L, R, 0);
}
static
int
buildSegTreeUtil(
int
[] arr,
int
low,
int
high,
int
[] st,
int
node)
{
if
(low == high) {
st[node] = arr[low];
return
arr[low];
}
int
mid = getMiddleValue(low, high);
st[node] = buildSegTreeUtil(arr, low, mid, st,
node * 2 + 1)
+ buildSegTreeUtil(arr, mid + 1, high,
st, node * 2 + 2);
return
st[node];
}
static
int
[] buildSegTree(
int
[] arr,
int
n)
{
int
x = (
int
)(Math.Ceiling(Math.Log(n) / Math.Log(2)));
int
max_size = 2 * (
int
)Math.Pow(2, x) - 1;
int
[] st =
new
int
[max_size];
buildSegTreeUtil(arr, 0, n - 1, st, 0);
return
st;
}
static
void
findPermutation(
int
[] arr,
int
N,
int
[,] Q,
int
M)
{
int
[] st = buildSegTree(arr, N);
for
(
int
i = 0; i < M; i++) {
int
queryType = Q[i,0];
if
(queryType == 1) {
int
pos = Q[i,1], value = Q[i,2];
updateValue(arr, st, N, pos, value);
}
else
{
int
L = Q[i,1], R = Q[i,2];
int
size = R - L + 1;
int
total_From_1_To_Size
= size * (size + 1) / 2;
int
total_From_L_To_R = getSum(st, N, L, R);
if
(total_From_L_To_R
== total_From_1_To_Size) {
Console. WriteLine(
"YES"
);
}
else
{
Console. WriteLine(
"NO"
);
}
}
}
}
public
static
void
Main(
string
[] args)
{
int
[] arr = { 6, 4, 1, 2, 3, 8, 10 };
int
N = arr.Length;
int
[,] Q = { { 2, 2, 4 }, { 1, 2, 9 }, { 2, 2, 4 },
{ 1, 2, 1 }, { 2, 0, 4 }, { 1, 0, 5 },
{ 2, 0, 4 } };
int
M = Q.GetLength(0);
findPermutation(arr, N, Q, M);
}
}