using
System;
class
GFG
{
static
readonly
int
INF = 1000000;
static
int
[]pref =
new
int
[500005];
static
int
[]suf =
new
int
[500005];
static
int
[]MAX =
new
int
[500005];
static
void
build(
int
[]a,
int
tl,
int
tr,
int
v)
{
if
(tl == tr)
{
MAX[v] = a[tl];
pref[v] = a[tl];
suf[v] = a[tl];
}
else
{
int
tm = (tl + tr) / 2;
build(a, tl, tm, v * 2);
build(a, tm + 1, tr, v * 2 + 1);
MAX[v] = Math.Max(MAX[v * 2],
Math.Max(MAX[v * 2 + 1],
suf[v * 2] + pref[v * 2 + 1]));
pref[v] = Math.Max(pref[v * 2],
pref[2 * v]
+ (pref[2 * v] == (tm - tl + 1)?1:0)
* pref[v * 2 + 1]);
suf[v] = Math.Max(
suf[v * 2 + 1],
suf[2 * v + 1]
+ suf[v * 2] * (suf[2 * v + 1] == (tr - tm)?1:0));
}
}
static
void
update(
int
[]a,
int
pos,
int
tl,
int
tr,
int
v)
{
if
(tl > pos || tr < pos)
{
return
;
}
if
(tl == tr && tl == pos)
{
MAX[v] = a[pos];
pref[v] = a[pos];
suf[v] = a[pos];
}
else
{
int
tm = (tl + tr) / 2;
update(a, pos, tl, tm, v * 2);
update(a, pos, tm + 1, tr, v * 2 + 1);
MAX[v] = Math.Max(MAX[v * 2],
Math.Max(MAX[v * 2 + 1],
suf[v * 2] + pref[v * 2 + 1]));
pref[v] = Math.Max(pref[v * 2],
pref[2 * v]
+ (pref[2 * v] == (tm - tl + 1)?1:0)
* pref[v * 2 + 1]);
suf[v] = Math.Max(suf[v * 2 + 1],
suf[2 * v + 1]
+ (suf[2 * v + 1] == (tr - tm)?1:0)
* suf[v * 2]);
}
}
static
void
solveQueries(
int
[]arr,
int
n,
int
[,] Q,
int
k)
{
int
cntQuery = Q.GetLength(0);
build(arr, 0, n - 1, 1);
for
(
int
i = 0; i < cntQuery; i++)
{
if
(Q[i, 0] == 1)
{
Console.Write(MAX[1] +
" "
);
}
else
{
arr[Q[i, 1] - 1] ^= 1;
update(arr, Q[i, 1] - 1, 0, n - 1, 1);
}
}
}
public
static
void
Main(String[] args)
{
int
N = 10;
int
[]arr = { 1, 1, 0, 1, 1,
1, 0, 0, 1, 1 };
int
[,]Q = { { 1,0 }, { 2, 3 }, { 1,0 } };
int
K = 3;
solveQueries(arr, N, Q, K);
}
}