#abc360d. D - Ghost Ants

D - Ghost Ants

Score : 350350 points

问题陈述

在数轴上有 NN 只蚂蚁,编号为 11NN。蚂蚁 ii (1iN)(1 \leq i \leq N) 从坐标 XiX_i 开始,面向正方向或负方向。最初,所有蚂蚁都在不同的坐标上。每只蚂蚁面向的方向由一个长度为 NN 的二进制字符串 SS 表示,如果 SiS_i0,则蚂蚁 ii 面向负方向;如果 SiS_i1,则面向正方向。

设当前时间为 00,蚂蚁们以每单位时间 11 单位的速度沿着各自的方向移动,持续 (T+0.1)(T+0.1) 单位时间,直到时间 (T+0.1)(T+0.1)。如果有多只蚂蚁到达同一坐标,它们会相互穿过,而不会改变方向或速度。在 (T+0.1)(T+0.1) 单位时间后,所有蚂蚁停止。

找出在时间 (T+0.1)(T+0.1) 之前,有多少对 (i,j)(i, j) 满足 1i<jN1 \leq i < j \leq N 并且蚂蚁 iijj 相互穿过。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

There are NN ants on a number line, labeled 11 to NN. Ant ii (1iN)(1 \leq i \leq N) starts at coordinate XiX_i and faces either a positive or negative direction. Initially, all ants are at distinct coordinates. The direction each ant is facing is represented by a binary string SS of length NN, where ant ii is facing the negative direction if SiS_i is 0 and the positive direction if SiS_i is 1.

Let the current time be 00, and the ants move in their respective directions at a speed of 11 unit per unit time for (T+0.1)(T+0.1) units of time until time (T+0.1)(T+0.1). If multiple ants reach the same coordinate, they pass through each other without changing direction or speed. After (T+0.1)(T+0.1) units of time, all ants stop.

Find the number of pairs (i,j)(i, j) such that 1i<jN1 \leq i < j \leq N and ants ii and jj pass each other from now before time (T+0.1)(T+0.1).

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^{5}
  • 1T1091 \leq T \leq 10^{9}
  • SS is a string of length NN consisting of 0 and 1.
  • 109Xi109-10^{9} \leq X_i \leq 10^{9} (1iN)(1 \leq i \leq N)
  • XiXjX_i \neq X_j (1i<jN)(1 \leq i < j \leq N)
  • NN, TT, and XiX_i (1iN)(1 \leq i \leq N) are integers.

Input

The input is given from Standard Input in the following format:

NN TT

SS

X1X_1 X2X_2 ... XNX_N

Output

Print the answer.

Sample Input 1

6 3
101010
-5 -1 0 1 2 4

Sample Output 1

5

The following five pairs of ants pass each other:

  • Ant 33 and ant 44 pass each other at time 0.50.5.
  • Ant 55 and ant 66 pass each other at time 11.
  • Ant 11 and ant 22 pass each other at time 22.
  • Ant 33 and ant 66 pass each other at time 22.
  • Ant 11 and ant 44 pass each other at time 33.

No other pairs of ants pass each other, so print 55.

Sample Input 2

13 656320850
0100110011101
-900549713 -713494784 -713078652 -687818593 -517374932 -498415009 -472742091 -390030458 -379340552 -237481538 -44636942 352721061 695864366

Sample Output 2

14