Devu And Churu

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Devu and Churu love to play games a lot. Today, they have an array A consisting of N positive integers. First they listed all N × (N+1) / 2 nonempty continuous subarrays of the array A on a piece of paper and then replaced all the subarrays on the paper with the maximum element present in the respective subarray.
Devu and Churu decided to play a game with numbers on the paper. They both have decided to make moves turn by turn. In one turn, the player picks some number from the list and discards that number. The one who is not able to make a valid move will be the loser. To make the game more interesting, they decided to put some constraints on their moves.
A constraint on a game can be any of following three types :
 > K : They are allowed to choose numbers having values strictly greater than K only.
 < K : They are allowed to choose numbers having values strictly less than K only.
 = K : They are allowed to choose numbers having values equal to K only.
Given M constraints and who goes first, you have to tell the outcome of each game. Print 'D' if Devu wins otherwise print 'C' without quotes.
Note that M games are independent, that is, they'll rewrite numbers by using array A after each game. (This is the task for the loser of the previous game!)
Input
First line of input contains two space separated integers N and M denoting the size of array A and number of game played by them. Next line of input contains N spaceseparated integers denoting elements of array A. Each of the next M lines of input contains three spaceseparated parameters describing a game. First two parameter are a character C ∈ {<, >, =} and an integer K denoting the constraint for that game. The last parameter is a character X ∈ {D, C} denoting the player who will start the game.
Output
Output consists of a single line containing a string of length M made up from characters D and C only, where i^{th} character in the string denotes the outcome of the i^{th} game.
Constraints:
 1 ≤ N, M ≤ 10^{6}
 1 ≤ A_{i}, K ≤ 10^{9}
 X ∈ {D, C}
 C ∈ {<, >, =}
Subtasks:
 Subtask 1 : 1 ≤ N, M ≤ 10^{4} : ( 20 pts )
 Subtask 2 : 1 ≤ N, M ≤ 10^{5} : ( 30 pts )
 Subtask 3 : 1 ≤ N, M ≤ 10^{6} : ( 50 pts )
Example:
Input: 3 5 1 2 3 > 1 D < 2 C = 3 D > 4 C < 5 D Output: DCDDC
Explanation:
Subarray List :
 [1]
 [2]
 [3]
 [1,2]
 [2,3]
 [1,2,3]
Numbers on the paper after replacement :
 [1]
 [2]
 [3]
 [2]
 [3]
 [3]
Game 1 : There are only 5 numbers > 1 in the list.
Game 2 : There is only 1 number < 2 in the list.
Game 3 : There are only 3 numbers = 3 in the list.
Game 4 : There are no numbers > 4 in the list. So the first player cannot make his move.
Game 5 : There are 6 numbers < 5 in the list.
Author:  ma5termind 
Tester:  laycurse 
Editorial  http://discuss.codechef.com/problems/DCGAME 
Tags  aug15, binarysearch, combinatorics, ma5termind, medium, stack, stockspan, value 
Date Added:  2042015 
Time Limit:  1.5 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 