Logo
(追記) (追記ここまで)

23178번 - Organizing Beads 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB162968866.165%

문제

Hyunuk has a long barrel of $n$ (2ドル \le n \le 2 \cdot 10^5$) cells. Each cell is either empty or contains a bead. When storing beads, it doesn't look good if they are scattered here and there, so Hyunuk wants to gather all the beads at one end. Specifically, if the barrel has $k$ beads, the beads must be in cells 1ドル$ through $k$ or in cells $n-k+1$ through $k$.

Hyunuk can move the bead in the $i$-th cell of the barrel to the ($i-1$)-th cell or the ($i+1$)-th cell by lightly pushing it. If there is a bead in the cell to be moved, that bead is also pushed in the same direction. For example, let there be beads in the 2nd, 3rd, and 5th cells. If Hyunuk pushes the bead in the 2nd cell to the 3rd cell, the bead in the 3rd cell is also pushed to the 4th cell. The bead in the 5th cell remains in place.

Hyunuk wonders how the minimum number of moves required to organize all beads will change when he adds or removes beads from the barrel. Write a program that calculates the minimum number of moves required to organize the bead barrel as Hyunuk inserts or removes beads from the barrel.

입력

The first line contains a single integer $n\ (2 \le n \le 2 \cdot 10^5),ドル the length of the bead barrel.

The second line contains a string of length $n$ consisting of only O's and X's representing the state of the bead barrel. If the $i$-th character of the string is O, then the cell has a bead in it. Otherwise, the $i$-th character of the string is X and the cell is empty.

The third line contains a single integer $q\ (1 \le q \le 2 \cdot 10^5),ドル the number of actions performed by Hyunuk.

The next $q$ lines each contain a single integer $k\ (1 \le k \le n)$ representing Hyunuk's action. This means that if there is a bead in the $k$-th cell of the barrel, the bead is removed, and if there is no bead, it is inserted at the corresponding position.

The input will be designed such that the barrel will never have zero beads.

출력

Output $q$ lines, the $i$-th of which contains a single integer, the minimum number of moves required to organize all beads after Hyunuk's first $i$ actions.

제한

예제 입력 1

6
OXXOXO
4
3
1
6
3

예제 출력 1

2
1
2
2

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2021 KAIST 11th ICPC Mock Competition I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /