#603
Unrated
Tractor Paths
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Note: The time limit for this problem is 4s, twice the default. The memory limit for this problem is 512MB, twice the default.

Farmer John has NN (2N21052\le N\le 2\cdot 10^5) tractors, where the iith tractor can only be used within the inclusive interval [i,ri][\ell_i,r_i]. The tractor intervals have left endpoints 1<2<<N\ell_1<\ell_2<\dots<\ell_N and right endpoints r1<r2<<rNr_1<r_2<\dots<r_N. Some of the tractors are special.

Two tractors ii and jj are said to be adjacent if [i,ri][\ell_i,r_i] and [j,rj][\ell_j,r_j] intersect. Farmer John can transfer from one tractor to any adjacent tractor. A path between two tractors aa and bb consists of a sequence of transfers such that the first tractor in the sequence is aa, the last tractor in the sequence is bb, and every two consecutive tractors in the sequence are adjacent. It is guaranteed that there is a path between tractor 11 and tractor NN. The length of a path is the number of transfers (or equivalently, the number of tractors within it minus one).

You are given QQ (1Q21051\le Q\le 2\cdot 10^5) queries, each specifying a pair of tractors aa and bb (1a<bN1\le a<b\le N). For each query, output two integers:

The length of any shortest path between tractor aa to tractor bb.The number of special tractors such that there exists at least one shortest path from tractor aa to tractor bb containing it.

입력

The first line contains NN and QQ.

The next line contains a string of length 2N2N consisting of Ls and Rs, representing the left and right endpoints in sorted order. It is guaranteed that for each proper prefix of this string, the number of Ls exceeds the number of Rs.

The next line contains a bit string of length NN, representing for each tractor whether it is special or not.

The next QQ lines each contain two integers aa and bb, specifying a query.

출력

For each query, the two quantities separated by spaces.

예제 입력 1

8 10
LLLLRLLLLRRRRRRR
11011010
1 2
1 3
1 4
1 5
1 6
1 7
1 8
2 3
2 4
2 5

예제 출력 1

1 2
1 1
1 2
2 4
2 3
2 4
2 3
1 1
1 2
1 2

점수

Inputs 2-3: N,Q5000N,Q\le 5000Inputs 4-7: There are at most 10 special tractors.Inputs 8-16: No additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.