Don't Fight The Music

시간 제한3초메모리 제한1024 MB

요약
한 구간에 같은 색 개수 기반 토글 연산을 T번 적용했을 때 위로 보이는 값의 합을 구하고, 중간에 점 갱신과 뒤집기가 들어온다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 비트 연산, 구현, 수학
정답자
아직 제출이 없습니다

문제

There are NN cards in a row. Each card has a red front side and a blue back side. An integer R_iR\_i is written on the red side of the ii-th card, and an integer B_iB\_i is written on the blue side. Initially, every card is facing either red side up or blue side up.

An operation on a range \[l,r]\[l, r] is defined as follows:

  • For each ii from ll to rr, let c_ic\_i be the number of indices jj with l≤j<il \le j < i such that card jj shows the same color as card ii at the beginning of the current operation.
  • After the operation, card ii shows its red side if c_ic\_i is even, and its blue side if c_ic\_i is odd.
  • All cards in \[l,r]\[l, r] are updated simultaneously.

You need to process the following QQ queries:

  • 1 i — Flip the ii-th card.
  • 2 i k — Change the value on the red side of the ii-th card to kk.
  • 3 i k — Change the value on the blue side of the ii-th card to kk.
  • 4 l r T — Calculate the sum of the numbers on the face-up sides in the range \[l,r]\[l, r], when the operation has been applied to this range TT times. The state of the cards does not change as a result of this query.

입력

The first line contains a single integer NN, the number of cards.

The second line contains a string ss of length NN, consisting of characters R and B. The ii-th character of ss denotes the initial side of the ii-th card (R for red side up, B for blue side up).

The third line contains NN integers R_1,R_2,⋯ ,R_NR\_1, R\_2, \cdots, R\_N — the values on the red sides of the cards.

The fourth line contains NN integers B_1,B_2,⋯ ,B_NB\_1, B\_2, \cdots, B\_N — the values on the blue sides of the cards.

The fifth line contains a single integer QQ, the number of queries.

Each of the next QQ lines describes a query of one of the four types as described above.

출력

For each query of type 44, output a single integer, the calculated sum for the specified range.

제한

  • 1≤N,Q≤2⋅1051 \le N, Q \le 2\cdot 10^5
  • 1≤R_i,B_i≤1091 \le R\_i, B\_i \le 10^9
  • For a query of type 11: 1≤i≤N1 \le i \le N
  • For a query of type 22 or 33: 1≤i≤N1 \le i \le N, 1≤k≤1091 \le k \le 10^9
  • For a query of type 44: 1≤l≤r≤N1 \le l \le r \le N, 1≤T≤1091 \le T \le 10^9
  • It is guaranteed that there is at least one query of type 4.

예제2

  1. 예제 1

    입력
    5
    RRRRR
    1 2 3 2 1
    5 4 3 4 5
    4
    4 1 5 1
    4 1 5 2
    1 2
    4 1 4 1
    
    예상 출력
    13
    11
    8
    
  2. 예제 2

    입력
    8
    RBRBRBRB
    451 79 882 122 1289 242 2459 262
    697 1082 1888 3070 225 410 751 1089
    11
    1 5
    4 1 6 10121
    1 3
    2 6 803
    3 3 741
    4 2 7 11104
    1 5
    3 8 690
    2 5 137
    3 6 148
    4 3 8 20915
    
    예상 출력
    7187
    5810
    6333