7.27 第三场 Photoshop Layers
Photoshop Layers
Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1264 Accepted Submission(s): 475
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 ‘‘64FF32’’.
There are n layers in Photoshop workstation, labeled by 1,2,…,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 ci=(Ri,Gi,Bi), the blending mode of the i-th layer is mi (mi∈{1,2}):
- If mi=1, the blending mode of this layer is ‘‘Normal’’. Assume the previous color displayed on the screen is (Rp,Gp,Bp), now the new color will be (Ri,Gi,Bi).
- If mi=2, the blending mode of this layer is ‘‘Linear Dodge’’. Assume the previous color displayed on the screen is (Rp,Gp,Bp), now the new color will be (min(Rp+Ri,255), min(Gp+Gi,255), min(Bp+Bi,255)).
You will be given q queries. In the i-th query, you will be given two integers li and ri (1≤li≤ri≤n). Please write a program to compute the final color displayed on the screen if we only keep all the layers indexed within [li,ri] 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≤T≤10), the number of test cases. For each test case:
The first line of the input contains two integers n and q (1≤n,q≤100000), denoting the number of layers and the number of queries.
In the next n lines, the i-th line contains an integer mi and a six-digit hexadecimal capital string ci, describing the i-th layer.
In the next q lines, the i-th line contains two integers li and ri (1≤li≤ri≤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
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int m[N], last[N];
int r[N], g[N], b[N];
int main() {
ios::sync_with_stdio(false);
int T;
scanf("%d", &T);
while (T--) {
int n, q;
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) {
int x;
//%X读入十六进制(x大小写不影响输入)
scanf("%d%X", &m[i], &x);
//记录1的位置
last[i] = (m[i] == 1 ? i : last[i - 1]);
//处理rgb
b[i] = b[i - 1] + (x & 255);
x >>= 8;
g[i] = g[i - 1] + (x & 255);
x >>= 8;
r[i] = r[i - 1] + (x);
}
while (q--) {
int x, y;
scanf("%d%d", &x, &y);
int xx = max(x, last[y]);
//%X输出十六进制(x大小写影响输出字母大小写)
printf("%02X%02X%02X\n", min(r[y] - r[xx - 1], 255), min(g[y] - g[xx - 1], 255),
min(b[y] - b[xx - 1], 255));
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效