Drunk Coding
InterviewTime limit1sMemory limit256 MB
Maintain a sequence under point updates and answer range-product sign queries (+/-/0) for each test case until EOF.
- Level
Medium5 of 10
- Topics
- Segment tree, Prefix sum, Math, Implementation
- Solved
- No attempts yet
Problem
It is the night before the ACM-ICPC contest. To unwind, Sanggeun heads to a nearby bar with his teammates.
To warm up for the next day's contest, they decide to play a small game.
First, Seonyeong writes down a sequence of integers for Sanggeun. The game consists of rounds, and in each round Seonyeong issues one of the following two commands.
- Change: Replace one value of the sequence with a new value.
- Multiply: Seonyeong names and ; Sanggeun must answer whether the product is positive, negative, or zero.
Every wrong answer to a multiply command costs Sanggeun a shot of soju. Luckily, Seonyeong lets him use his laptop, and Sanggeun trusts his coding skills more than his mental arithmetic.
Write a program that helps Sanggeun answer each multiply command.
Input
The input consists of several test cases, processed one after another until end of file.
The first line of each test case contains the sequence size and the number of rounds . ()
The second line contains the values separated by spaces. ()
Each of the next lines contains one command, starting with the letter C or P.
C i V: a change command; set to . (, )P i j: a multiply command; ask for the sign of . ()
Each test case contains at least one multiply command.
Output
For each test case, print the results of all its multiply commands concatenated on a single line. The -th character is the result of the -th multiply command: print + if the product is positive, - if it is negative, and 0 if it is zero.
Hint
Ballmer's Peak Theory is the (tongue-in-cheek) claim that programmers write superhuman code when their blood alcohol concentration is between 0.129% and 0.138%.