PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000090. Giáo sư Higashikata (Professor Higashikata)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Giáo sư Higashikata (Professor Higashikata)

Professor Higashikata

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a binary string ss of length nn. In one operation, swap the characters at two distinct positions of ss; each swap costs 11.

For each of the mm intervals [li,ri][l_i,r_i], let tit_i be the corresponding substring of the current ss, and define

t(s)=t1+t2+⋯+tm,t(s)=t_1+t_2+\cdots+t_m,

where ++ denotes concatenation. Intervals may overlap or coincide, so a character of ss may occur multiple times in t(s)t(s).

There are qq updates; update jj flips the bit sxjs_{x_j}. After each flip, find the minimum number of swaps needed to make t(s)t(s) lexicographically maximum among all strings obtainable by swapping characters of ss. Only report the minimum number; the swaps are hypothetical and are not actually carried out. Thus, only the bit flips persist between updates.

For equal-length binary strings, 1 is larger than 0 at the first position of difference.

Input

The first line contains n,m,qn,m,q, followed by binary string ss, mm interval lines li,ril_i,r_i, and qq flip positions xjx_j.

Output

Print one integer after each update: the minimum number of required swaps.

Subtasks

  • Subtask 1 (20 points): 1≤n,m,q≤151\le n,m,q\le 15, s∈{0,1}ns\in\{0,1\}^n, 1≤li≤ri≤n1\le l_i\le r_i\le n, 1≤xi≤n1\le x_i\le n.
  • Subtask 2 (30 points): 1≤n,m,q≤30001\le n,m,q\le 3000, s∈{0,1}ns\in\{0,1\}^n, 1≤li≤ri≤n1\le l_i\le r_i\le n, 1≤xi≤n1\le x_i\le n.
  • Subtask 3 (50 points): 1≤n,m,q≤2⋅1051\le n,m,q\le 2\cdot10^5, s∈{0,1}ns\in\{0,1\}^n, 1≤li≤ri≤n1\le l_i\le r_i\le n, 1≤xi≤n1\le x_i\le n.

Example

Input

2 2 4
01
1 2
1 2
1
1
2
2

Output

0
1
0
1

Explanation

Both intervals are [1,2][1,2]. When ss becomes 11, zero swaps are needed. For 01, swapping the two bits produces 10, requiring one swap.