Bfs

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

요약
남학생 또는 여학생 두 명의 순서를 맞바꿀 때마다, 던지는 순서를 정해 막대의 기울기가 S를 넘지 않도록 할 수 있는지 판정한다.
난이도

어려움10점 중 8점

유형
그리디, 누적 합, 세그먼트 트리, 이분 탐색
정답자
아직 제출이 없습니다

문제

The kids from 402 heard the bell and quickly went outside to play. Seeing a big pole in the middle of the field they thought of the following game. Initially they split in groups of girls and boys (there are mm girls and 𝑛n boys) and then they position themselves somewhere on the field.

Initially the pole is completely vertical (has tilt 00). Each player has certain force (B_iB\_i is the force of the iith boy, F_iF\_i is the force of the iith girl). The game goes like this: at each step, either the boy or the girl closest to the pole (with the smallest index) throws a ball to the pole, after which he/she leaves the game. A boy's throw tilts the pole to the right, while a girl's throw tilts the pole to the left. The tilt of the pole changes with a value equal to the player's force.

In order to make sure the game doesn't end disastrously, the pole is not allowed to be tilted (in either direction) more than SS. The kids are wondering if they can find an order of throws such that this condition is respected.

To make things more interesting, their teacher chooses QQ moments when she swaps the order of two consecutive boys or girls. All the swaps are persistent.

You should help the kids decide if there is a valid order of throws after each swap.

입력

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

The second line contains nn integers representing the force values of the boys.

The third line contains mm integers representing the force values of the girls.

The fourth line contains a single integer QQ.

Each of the next QQ lines is of the form \[B∣F] x y\[B|F]\ x\ y, where \[B∣F]\[B|F] represents the group of the swap (BB stands for the boys' group, FF for the girls' group), while xx and yy are the swapped positions.

출력

Output QQ lines, each containing 11 if the game can be successful, or 00 otherwise.

제한

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

예제1

  1. 예제 1

    입력
    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
    
    예상 출력
    0
    1
    0
    1
    0
    1
    0
    1
    0
    1
    0
    1
    0
    1