Score : 475 points
问题描述
给定一个长度为 N 的序列 A=(A1,A2,…,AN),其中包含数字 0, 1 和 2,以及一个长度也为 N 的字符串 S=S1S2…SN,其中包含字符 M
, E
, 和 X
。
要求计算满足条件 1≤i<j<k≤N 且 SiSjSk= MEX
的所有整数元组 (i,j,k) 的 mex(Ai,Aj,Ak) 的总和。这里,mex(Ai,Aj,Ak) 表示既不等于 Ai,Aj 也不等于 Ak 的最小非负整数。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a length-N sequence A=(A1,A2,…,AN) consisting of 0, 1, and 2, and a length-N string S=S1S2…SN consisting of M
, E
, and X
.
Find the sum of mex(Ai,Aj,Ak) over all tuples of integers (i,j,k) such that 1≤i<j<k≤N and SiSjSk= MEX
. Here, mex(Ai,Aj,Ak) denotes the minimum non-negative integer that equals neither Ai,Aj, nor Ak.
Constraints
- 3≤N≤2×105
- N is an integer.
- Ai∈{0,1,2}
- S is a string of length N consisting of
M
, E
, and X
.
The input is given from Standard Input in the following format:
N
A1 A2 … AN
S
Output
Print the answer as an integer.
4
1 1 0 2
MEEX
Sample Output 1
3
The tuples (i,j,k) (1≤i<j<k≤N) such that SiSjSk = MEX
are the following two: (i,j,k)=(1,2,4),(1,3,4). Since mex(A1,A2,A4)=mex(1,1,2)=0 and mex(A1,A3,A4)=mex(1,0,2)=3, the answer is 0+3=3.
3
0 0 0
XXX
Sample Output 2
0
15
1 1 2 0 0 2 0 2 0 0 0 0 0 2 2
EXMMXXXEMEXEXMM
Sample Output 3
13
update @ 2024/3/10 08:44:37