Imagine
InterviewTime limit1sMemory limit256 MB
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 metres wide and metres tall — a grid of cells, each one square centimetre. Every so often an activist places a 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 . Precisely, the cell in column and row starts as A when is even, and as B when 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 with : the total number of actions (stickers and queries combined).
- Each of the next lines is one action, in one of two forms:
A x yorB x y— place a sticker of the named party on the cell in column , row , where .R x1 y1 x2 y2— a query over the subrectangle with top-left corner and bottom-right corner , where and .
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.