This page is still under construction.

Parts of this page are still being built. What you see may change.

Imagine

Interview

Time limit1sMemory limit256 MB

Summary
Maintain a 1024x1024 grid that starts as a checkerboard and process stickers plus rectangle queries for counts of each letter.
Level

Medium5 of 10

Topics
Prefix sum, Array, Implementation, Simulation
Solved
No attempts yet

Problem

Imagine a made-up city with two fictional political parties named A and B (the names are short, and nobody minded).

In the center of the city stands a billboard that is 10.2410.24 metres wide and 10.2410.24 metres tall — a grid of 1024×10241024 \times 1024 cells, each one square centimetre. Every so often an activist places a 1 cm×1 cm1\,\text{cm} \times 1\,\text{cm} sticker showing either an A or a B onto a single cell. A newly placed sticker completely covers whatever was on that cell before, so only the most recently placed sticker on a cell is ever visible.

Before any sticker is placed, the board is coloured like a checkerboard with an A in the top-left corner at x=y=1x = y = 1. Precisely, the cell in column xx and row yy starts as A when x+yx + y is even, and as B when x+yx + y is odd:

        x=1  x=2  x=3  x=4
 y=1:    A    B    A    B
 y=2:    B    A    B    A
 y=3:    A    B    A    B
 y=4:    B    A    B    A

Actions are processed in chronological order and come in two kinds: placing a sticker on one cell, and asking how many A cells and how many B cells currently lie inside a given axis-aligned subrectangle of the board. Answer every such question efficiently.

Input

The input describes a single scenario.

  • The first line contains one integer NN with 1≤N≤1,000,0001 \le N \le 1{,}000{,}000: the total number of actions (stickers and queries combined).
  • Each of the next NN lines is one action, in one of two forms:
    • A x y or B x y — place a sticker of the named party on the cell in column xx, row yy, where 1≤x,y≤10241 \le x, y \le 1024.
    • R x1 y1 x2 y2 — a query over the subrectangle with top-left corner (x1,y1)(x_1, y_1) and bottom-right corner (x2,y2)(x_2, y_2), where 1≤x1≤x2≤10241 \le x_1 \le x_2 \le 1024 and 1≤y1≤y2≤10241 \le y_1 \le y_2 \le 1024.

On every line the letter and the integers are separated by single spaces. Stickers and queries may be interleaved in any order.

Output

For each query, in the order the queries appear in the input, print one line with two integers separated by a single space: the number of A cells and the number of B cells currently inside the queried subrectangle.

Examples4

  1. Example 1

    Input
    7
    R 1 1 3 3
    A 2 3
    A 1 3
    R 1 1 3 3
    B 2 2
    B 3 3
    R 2 2 3 3
    
    Expected output
    5 4
    6 3
    1 3
    
  2. Example 2

    Input
    1
    R 1 1 1 1
    
    Expected output
    1 0
    
  3. Example 3

    Input
    1
    R 2 1 2 1
    
    Expected output
    0 1
    
  4. Example 4

    Input
    5
    R 5 6 5 6
    A 5 6
    R 5 6 5 6
    B 5 6
    R 5 6 5 6
    
    Expected output
    0 1
    1 0
    0 1