Under construction

Still being built. Things may change

Bfs

Time limit1sMemory limit1024 MB

Summary
Boys push the tilt right and girls push it left, in an order that keeps the tilt within S. After each swap inside one group, decide whether a valid order still exists.
Level

Hard8 of 10

Topics
Dynamic programming, Segment tree, Prefix sum
Solved
No attempts yet

Problem

Kids from 402 heard the bell and ran outside to play. A tall pole stood in the middle of the field, so they came up with this game. At first the kids split into a group of mm girls and a group of nn boys, then they took positions somewhere on the field.

The pole starts completely vertical, with tilt 00. Each player has a force: BiB_i is the force of the ii-th boy and FiF_i is the force of the ii-th girl. The game runs step by step. At each step, either the boy or the girl closest to the pole (the one with the smallest index) throws a ball at the pole, then leaves the game. A boy's throw tilts the pole to the right, and a girl's throw tilts it to the left. Each throw changes the tilt by the thrower's force.

To keep the game from ending in disaster, the tilt of the pole must never exceed SS in either direction. The kids want to know whether some order of throws keeps the tilt within this limit.

The teacher picks QQ moments and swaps the order of two consecutive boys or two consecutive girls. The swaps are permanent. After each swap, decide whether a valid order of throws exists.

Input

The first line contains three integers nn, mm, and SS.

The second line contains nn integers, the forces of the boys.

The third line contains mm integers, the forces of the girls.

The fourth line contains a single integer QQ.

Each of the next QQ lines has the form B x y or F x y. B means the swap is in the boys' group, F means it is in the girls' group, and xx and yy are the swapped positions.

Output

Print QQ lines. Print 11 if the game can be successful after the swap, or 00 otherwise.

Constraints

  • 1≤n,m,Q≤1051 \le n, m, Q \le 10^5
  • 1≤S≤1091 \le S \le 10^9
  • 0≤Bi,Fi≤1090 \le B_i, F_i \le 10^9
  • For every swap, ∣x−y∣=1|x - y| = 1.
  • It is guaranteed that the game is successful before the first swap.

Examples1

  1. Example 1

    Input
    6 3 30000
    15000 15000 60000 30000 29805 56555
    60000 60000 57187
    14
    B 2 3
    B 2 3
    B 2 3
    B 2 3
    F 2 3
    F 2 3
    B 2 3
    B 2 3
    B 3 4
    B 3 4
    B 2 3
    B 2 3
    F 2 3
    F 2 3
    
    Expected output
    0
    1
    0
    1
    0
    1
    0
    1
    0
    1
    0
    1
    0
    1