CF1661E.Narrow Components
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a matrix a , consisting of 3 rows and n columns. Each cell of the matrix is either free or taken.
A free cell y is reachable from a free cell x if at least one of these conditions hold:
- x and y share a side;
- there exists a free cell z such that z is reachable from x and y is reachable from z .
A connected component is a set of free cells of the matrix such that all cells in it are reachable from one another, but adding any other free cell to the set violates this rule.
You are asked q queries about the matrix. Each query is the following:
- l r — count the number of connected components of the matrix, consisting of columns from l to r of the matrix a , inclusive.
Print the answers to all queries.
输入格式
The first line contains an integer n ( 1≤n≤5⋅105 ) — the number of columns of matrix a .
The i -th of the next three lines contains a description of the i -th row of the matrix a — a string, consisting of n characters. Each character is either 1 (denoting a free cell) or 0 (denoting a taken cell).
The next line contains an integer q ( 1≤q≤3⋅105 ) — the number of queries.
The j -th of the next q lines contains two integers lj and rj ( 1≤lj≤rj≤n ) — the description of the j -th query.
输出格式
Print q integers — the j -th value should be equal to the number of the connected components of the matrix, consisting of columns from lj to rj of the matrix a , inclusive.
输入输出样例
输入#1
12 100101011101 110110010110 010001011101 8 1 12 1 1 1 2 9 9 8 11 9 12 11 12 4 6
输出#1
7 1 1 2 1 3 3 3