1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| #include <iostream> #include <cstring> #include <cstdio>
using namespace std;
const int N = 1e5+10;
struct node { int m, r, g, b; }node[N]; int last[N], pre1[N], pre2[N], pre3[N];
int main() { int t; scanf("%d", &t); while (t--) { memset(node, 0, sizeof(node)); memset(last, 0, sizeof(last)); memset(pre1, 0, sizeof(pre1)); memset(pre2, 0, sizeof(pre2)); memset(pre3, 0, sizeof(pre3));
int n, q; scanf("%d%d", &n, &q); last[0] = -1; for (int i = 1; i <= n; i++) { int mode, x; scanf("%d%x", &mode, &x); node[i].m = mode, node[i].r = (x/256/256)%256, node[i].g = (x/256)%256, node[i].b = (x)%256; if (mode == 1) last[i] = i; else last[i] = last[i-1]; pre1[i] = pre1[i-1] + node[i].r; pre2[i] = pre2[i-1] + node[i].g; pre3[i] = pre3[i-1] + node[i].b; } for (int i = 1; i <= q; i++) { int l, r; scanf("%d %d", &l, &r); int rr, gg, bb; if (last[r] >= l && last[r] <= r) { rr = min(node[last[r]].r + pre1[r] - pre1[last[r]], 255); gg = min(node[last[r]].g + pre2[r] - pre2[last[r]], 255); bb = min(node[last[r]].b + pre3[r] - pre3[last[r]], 255); } else { rr = min(pre1[r] - pre1[l-1], 255); gg = min(pre2[r] - pre2[l-1], 255); bb = min(pre3[r] - pre3[l-1], 255); } printf("%02X%02X%02X\n", rr, gg, bb); }
} return 0; }
|