F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Photoshop Layers

Time Limit: 3000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1737    Accepted Submission(s): 635


Problem Description
Pixels in a digital picture can be represented with three integers $(R,G,B)$ in the range $0$ to $255$ that indicate the intensity of the red, green, and blue colors. The color of a pixel can be expressed as a six-digit hexadecimal capital string. For example, $(R=100,G=255,B=50)$ can be expressed as ''$\texttt{64FF32}$''.

There are $n$ layers in Photoshop workstation, labeled by $1,2,\dots,n$ from bottom to top. The screen will display these layers from bottom to top. In this problem, you only need to handle the case that the color of all the pixels in a layer are the same. The color of the $i$-th layer is $c_i=(R_i,G_i,B_i)$, the blending mode of the $i$-th layer is $m_i$ ($m_i\in\{1,2\}$):
  • If $m_i=1$, the blending mode of this layer is ''Normal''. Assume the previous color displayed on the screen is $(R_p,G_p,B_p)$, now the new color will be $(R_i,G_i,B_i)$.
  • If $m_i=2$, the blending mode of this layer is ''Linear Dodge''. Assume the previous color displayed on the screen is $(R_p,G_p,B_p)$, now the new color will be $(\min(R_p+R_i,255)$, $\min(G_p+G_i,255)$, $\min(B_p+B_i,255))$.
You will be given $q$ queries. In the $i$-th query, you will be given two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$). Please write a program to compute the final color displayed on the screen if we only keep all the layers indexed within $[l_i,r_i]$ without changing their order. Note that the color of the background is $(R=0,G=0,B=0)$.
 

Input
The first line contains a single integer $T$ ($1 \leq T \leq 10$), the number of test cases. For each test case:

The first line of the input contains two integers $n$ and $q$ ($1 \leq n,q \leq 100\,000$), denoting the number of layers and the number of queries.

In the next $n$ lines, the $i$-th line contains an integer $m_i$ and a six-digit hexadecimal capital string $c_i$, describing the $i$-th layer.

In the next $q$ lines, the $i$-th line contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), describing the $i$-th query.
 

Output
For each query, print a single line containing a six-digit hexadecimal capital string, denoting the final displayed color.
 

Sample Input
1 5 5 1 64C832 2 000100 2 010001 1 323C21 2 32C8C8 1 2 1 3 2 3 2 4 2 5
 

Sample Output
64C932 65C933 010101 323C21 64FFE9
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-19 01:15:30, Gzip enabled