Game of Pieces

시간 제한2초메모리 제한2048 MB

요약
무한 격자 위에 직사각형 조각을 떨어뜨리며, 각 조각이 착지한 뒤 빈 칸 위에 채워진 칸이 생기는지 판정한다.
난이도

어려움10점 중 8점

유형
시뮬레이션, 세그먼트 트리, 그리디, 구현
정답자
아직 제출이 없습니다

문제

If you’ve ever played Tetris for long enough, you might have experienced the Tetris effect – seeing falling blocks even after you have stopped playing. To stay focused on solving problems and avoid such distractions, we will consider a simplified version of the game.

The game is played on a board composed of square cells arranged in a grid. Columns of the grid are numbered sequentially from left to right. The board is infinite to the right and to the top. Each cell is either empty or filled, and initially, all cells are empty.

A sequence of N rectangular pieces is given, and the pieces are dropped onto the board one at a time. Pieces have different sizes. A piece of size LL is either vertical (L×1L \times 1 cells) or horizontal (1×L1 \times L cells). When a piece is dropped at a specified column, it starts at a location above all the currently filled cells and falls straight down until it either reaches the bottom of the board or lands on top of an already filled cell. Once a piece lands, it fills its final set of cells.

Each time a piece lands, the game is considered safe if no empty cell has a filled cell above it; otherwise the game is unsafe, the offending piece is removed from the board, and the game continues with the next piece as if it had never been dropped.

In the example below, corresponding to the first sample input, the game becomes unsafe once the second piece lands, hence the piece is removed and the next pieces keep the game safe.

Given the sequence of pieces and their drop positions, your task is to determine, for each piece, whether it makes the board unsafe after landing.

입력

The first line contains an integer NN (1≤N≤2⋅1051 ≤ N ≤ 2 \cdot 10^5), indicating the number of pieces.

Each of the next NN lines describes a piece with a character CC and two integers LL and PP (1≤L≤1091 ≤ L ≤ 10^9 and 1≤P≤10181 ≤ P ≤ 10^{18}), representing respectively the type of the piece, its length, and the position where it is dropped. For a vertical piece, CC is the character “|” (pipe), the piece has L×1L \times 1 cells, and it is dropped at column PP. For a horizontal piece, CC is the character “-” (hyphen), the piece has 1×L1 \times L cells, and it is dropped spanning columns P,P+1,…,P+L−1P, P + 1, \dots , P + L − 1.

출력

Output a single line with a string of length NN. The ii-th character of the string must be the uppercase letter “U” if the game becomes unsafe immediately after the ii-th piece lands on the board, and the uppercase letter “S” otherwise.

예제2

  1. 예제 1

    입력
    4
    | 3 1
    - 2 1
    | 3 2
    - 2 1
    
    예상 출력
    SUSS
    
  2. 예제 2

    입력
    4
    | 3 1
    | 2 3
    | 1 2
    - 2 2
    
    예상 출력
    SSSU