G++ Language
Time limit0.1sMemory limit256 MB
Write a G++ program that reads H and W, then leaves the sum of the cells in the rectangle from (a, b) to (c, d) in memory 0 and zeros elsewhere.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Implementation, Math
- Solved
- No attempts yet
Problem
The genius Kyojun spent several years of research and built a new programming language, G++. G++ supports the following operations:
- "INPUT ": Reads one integer from the input and writes it to memory . If there are no more integers to read, an Input Error occurs.
- "NOT ": Writes the logical negation of the value in memory to memory .
- "BNOT ": Writes the bitwise NOT of the value in memory to memory .
- "AND … ": Writes the bitwise AND of the values in memories … to memory . , …, must all be different, and . If this is not satisfied, an Index Error occurs.
- "OR … ": Writes the bitwise OR of the values in memories … to memory . , …, must all be different, and . If this is not satisfied, an Index Error occurs.
- "XOR … ": Writes the bitwise XOR of the values in memories … to memory . , …, must all be different, and . If this is not satisfied, an Index Error occurs.
- "LSHIFT ": Writes the value in memory shifted left bitwise by the value in memory to memory .
- "RSHIFT ": Writes the value in memory shifted right bitwise by the value in memory to memory .
A G++ program runs its operations in order, starting from the first. Right when it starts, memory is allocated for int variables. If your code accesses memory , then must hold. Otherwise, a Memory Error occurs. At the start, all variables are initialized to .
The total number of operations in a G++ program must not exceed . Otherwise, a Time Limit Exceeded Error occurs.
The total number of memory accesses in a G++ program must not exceed . Otherwise, an Access Limit Exceeded Error occurs.
Kyojun is a perfectionist. Your G++ code must not contain unnecessary spaces or line breaks. The last character of the G++ code must be a newline character. Otherwise, a Compile Error occurs.
In addition, if your G++ code causes Undefined Behavior, a Runtime Error occurs. The following cases cause Undefined Behavior when a G++ program runs:
- When shifting left by bits, and must both hold. Also, if , then must hold. Otherwise, Undefined Behavior occurs.
- When shifting right by bits, if does not hold, Undefined Behavior occurs.
For the input "2 16 5", the following G++ code writes the value 5 to memory 4.
INPUT 2
NOT 2 3
NOT 3 2
INPUT 0
INPUT 0
XOR 3 0 1 2 1
OR 3 3 1 2 4
You must now solve the following problem in G++:
There is a two-dimensional grid of size , with cells wide and cells tall. The top-left cell has coordinates , and the bottom-right cell has coordinates . The cell at coordinates contains the number .
Consider a rectangle in the grid whose top-left corner is and whose bottom-right corner is . Let be the sum of the numbers in the cells inside this rectangle. You must write a G++ code that, for the following input, leaves in memory 0 after running, and leaves in every other memory.
The input given to the G++ program is as follows:
…
Input
You are given only two integers, and . In other words, your submitted code can read only the values of and . Note that the values of , …, , , , , and are not provided.
Output
After running, memory 0 must contain , and every other memory must contain . Print the G++ code.
Constraints
All data satisfy the following conditions:
- , , , …, are all positive integers.
- .
- For every integer with , .
- , , , are all integers.
- , .