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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#include <cstdio> #include <string> #include <iostream>
using namespace std;
const auto U = [](auto x) { return [x](auto ...y) { return x(x, y...); }; }; const auto getr = [](int l, int r, int id) { return id + ((l + r) / 2 - l + 1) * 2; };
class segtree { public: class node { public: unsigned vset, zand; bool pexist; } nodes[400005]; void pushdown(int l, int r, int id) { if(nodes[id].vset != 114514) { nodes[id + 1].vset = nodes[id + 1].zand = (nodes[id + 1].pexist ? nodes[id].vset : 0x1ff); nodes[getr(l, r, id)].vset = nodes[getr(l, r, id)].zand = (nodes[getr(l, r, id)].pexist ? nodes[id].vset : 0x1ff); nodes[id].vset = 114514; } } void pushup(int l, int r, int id) { nodes[id].zand = nodes[id + 1].zand & nodes[getr(l, r, id)].zand; nodes[id].pexist = nodes[id + 1].pexist || nodes[getr(l, r, id)].pexist; if(!nodes[id].pexist) nodes[id].zand = 0x1ff; } void build(int n, const string &x, const string &y, const string &z, char px, char py, char pz) { U([&](auto &&self, int l, int r, int id) -> void { if(l == r) { nodes[id] = {114514, 0x1ff, x[l - 1] == px && y[l - 1] == py && z[l - 1] == pz}; return; } self(self, l, (l + r) / 2, id + 1); self(self, (l + r) / 2 + 1, r, getr(l, r, id)); pushup(l, r, id); })(1, n, 1); } void vset(int n, int L, int R, int val) { U([&](auto &&self, int l, int r, int vl, int vr, int id) -> void { if(l == vl && r == vr || !nodes[id].pexist) { nodes[id].vset = nodes[id].zand = (nodes[id].pexist ? val : 0x1ff); return; } pushdown(l, r, id); if(vl <= (l + r) / 2) self(self, l, (l + r) / 2, vl, min(vr, (l + r) / 2), id + 1); if(vr > (l + r) / 2) self(self, (l + r) / 2 + 1, r, max(vl, (l + r) / 2 + 1), vr, getr(l, r, id)); pushup(l, r, id); })(1, n, L, R, 1); } unsigned qaand() { return nodes[1].pexist ? nodes[1].zand : 0x1ff; } } segs[30];
int main() { int n; scanf("%d", &n); string sa, sb, sc; cin >> sa >> sb >> sc; auto cmask = [](char a, char b, char c, char t) -> unsigned { int va = (a == 'J' ? 0 : (a == 'O' ? 1 : 2)); int vb = (b == 'J' ? 0 : (b == 'O' ? 1 : 2)); int vc = (c == 'J' ? 0 : (c == 'O' ? 1 : 2)); int vt = (t == 'J' ? 0 : (t == 'O' ? 1 : 2)); unsigned res = 0; if((va + vb + vt) % 3 == 0) res |= 1 << 0; if((va + vc + vt) % 3 == 0) res |= 1 << 1; if((vb + vc + vt) % 3 == 0) res |= 1 << 2; if((vc + vt) % 3 == (va + vb) % 3) res |= 1 << 3; if((vb + vt) % 3 == (va + vc) % 3) res |= 1 << 4; if((va + vt) % 3 == (vb + vc) % 3) res |= 1 << 5; if(va == vt) res |= 1 << 6; if(vb == vt) res |= 1 << 7; if(vc == vt) res |= 1 << 8; return res; }; auto qid = [](char a, char b, char c) -> unsigned { return (a == 'J' ? 0 : (a == 'O' ? 1 : 2)) * 9 + (b == 'J' ? 0 : (b == 'O' ? 1 : 2)) * 3 + (c == 'J' ? 0 : (c == 'O' ? 1 : 2)); }; for(char x : {'J', 'O', 'I'}) { for(char y : {'J', 'O', 'I'}) { for(char z : {'J', 'O', 'I'}) { segs[qid(x, y, z)].build(n, sa, sb, sc, x, y, z); } } } int q; scanf("%d", &q); string t; cin >> t; for(int i=1;i<=n;i++) { segs[qid(sa[i-1], sb[i-1], sc[i-1])].vset(n, i, i, cmask(sa[i-1], sb[i-1], sc[i-1], t[i-1])); } auto qvalid = []() -> bool { unsigned vm = 0x1ff; for(int i=0;i<27;i++) if(!(vm &= segs[i].qaand())) return false; return true; }; printf(qvalid() ? "Yes\n" : "No\n"); while(q--) { int l, r; char c; scanf("%d%d %c", &l, &r, &c); for(char x : {'J', 'O', 'I'}) { for(char y : {'J', 'O', 'I'}) { for(char z : {'J', 'O', 'I'}) { segs[qid(x, y, z)].vset(n, l, r, cmask(x, y, z, c)); } } } printf(qvalid() ? "Yes\n" : "No\n"); } return 0; }
|