Submission #521545

# Submission time Handle Problem Language Result Execution time Memory
521545 2022-02-02T11:28:03 Z Soumya1 Crossing (JOI21_crossing) C++17
100 / 100
502 ms 18484 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mod1 = 1e9 + 7;
const int mod2 = 10000019;
const int mxN = 2e5 + 5;
pair<int, int> p[mxN];
pair<int, int> pp[mxN];
vector<string> v;
vector<pair<int, int>> hsh;
pair<int, int> t[4 * mxN];
int lazy[4 * mxN];
int sz;
int eval(char c) {
  if (c == 'I') return 0;
  if (c == 'O') return 1;
  return 2;
}
void hashh(string s) {
  hsh.push_back({0, 0});
  for (char c : s) {
    hsh.back().first = (3LL * hsh.back().first + eval(c)) % mod1;
    hsh.back().second = (3LL * hsh.back().second + eval(c)) % mod2;
  }
}
void build(int x, int lx, int rx) {
  if (lx == rx) {
    int c = eval(v[sz - 1][lx - 1]);
    t[x] = {c, c};
    lazy[x] = -1;
    return;
  }
  int mx = (lx + rx) >> 1;
  build(x << 1, lx, mx);
  build(x << 1 | 1, mx + 1, rx);
  lazy[x] = -1;
  t[x].first = ((1LL * t[x << 1].first * p[rx - mx].first) % mod1 + t[x << 1 | 1].first) % mod1;
  t[x].second = ((1LL * t[x << 1].second * p[rx - mx].second) % mod2 + t[x << 1 | 1].second) % mod2;
}
pair<int, int> calc(int c, int len) {
  return {(1LL * pp[len - 1].first * c) % mod1, (1LL * pp[len - 1].second * c) % mod2};
}
void propagate(int x, int lx, int rx) {
  if (lx == rx) return;
  int mx = (lx + rx) >> 1;
  t[x << 1] = calc(lazy[x], mx - lx + 1);
  t[x << 1 | 1] = calc(lazy[x], rx - mx);
  lazy[x << 1] = lazy[x << 1 | 1] = lazy[x];
  lazy[x] = -1;
  return;
}
void update(int x, int lx, int rx, int l, int r, int c) {
  if (lazy[x] != -1) propagate(x, lx, rx);
  if (l > rx || lx > r) return;
  if (l <= lx && r >= rx) {
    t[x] = calc(c, rx - lx + 1);
    lazy[x] = c;
    return;
  }
  int mx = (lx + rx) >> 1;
  update(x << 1, lx, mx, l, r, c);
  update(x << 1 | 1, mx + 1, rx, l, r, c);
  t[x].first = ((1LL * t[x << 1].first * p[rx - mx].first) % mod1 + t[x << 1 | 1].first) % mod1;
  t[x].second = ((1LL * t[x << 1].second * p[rx - mx].second) % mod2 + t[x << 1 | 1].second) % mod2;
}
void init(string a, string b, string c) {
  p[0] = {1, 1};
  for (int i = 1; i < mxN; i++) {
    p[i].first = (3LL * p[i - 1].first) % mod1;
    p[i].second = (3LL * p[i - 1].second) % mod2;
  }
  pp[0] = {1, 1};
  for (int i = 1; i < mxN; i++) {
    pp[i].first = (pp[i - 1].first + p[i].first) % mod1;
    pp[i].second = (pp[i - 1].second + p[i].second) % mod2;
  }
  map<string, bool> mp;
  v = {a, b, c};
  mp[a] = mp[b] = mp[c] = true;
  auto op = [&](string s, string tt) {
    string ret;
    for (int i = 0; i < (int) s.size(); i++) {
      if (s[i] == tt[i]) ret += s[i];
      else ret += ('I' ^ 'J' ^ 'O') ^ s[i] ^ tt[i];
    }
    return ret;
  };
  for (int i = 0; i < (int) v.size(); i++) {
    for (int j = i + 1; j < (int) v.size(); j++) {
      string ops = op(v[i], v[j]);
      if (!mp[ops]) {
        mp[ops] = true;
        v.push_back(ops);
      }
    }
  }
  for (string s : v) {
    hashh(s);
  }
  sz = v.size() + 1;
}
void query() {
  // cout << t[1] << endl;
  for (auto i : hsh) {
    if (i == t[1]) {
      cout << "Yes\n";
      return;
    }
  }
  cout << "No\n";
}
void testCase() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  init(a, b, c);
  int q;
  string tt;
  cin >> q >> tt;
  v.push_back(tt);
  build(1, 1, n);
  query();
  // for (string s : v) cout << s << " "; cout << endl;
  // for (int i : hsh) cout << i << " "; cout << endl;
  while (q--) {
    int l, r;
    char cc;
    cin >> l >> r >> cc;
    update(1, 1, n, l, r, eval(cc));
    query();
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 77 ms 3908 KB Output is correct
2 Correct 84 ms 4036 KB Output is correct
3 Correct 95 ms 4052 KB Output is correct
4 Correct 82 ms 3968 KB Output is correct
5 Correct 70 ms 3968 KB Output is correct
6 Correct 66 ms 4024 KB Output is correct
7 Correct 67 ms 4000 KB Output is correct
8 Correct 70 ms 4024 KB Output is correct
9 Correct 83 ms 3992 KB Output is correct
10 Correct 70 ms 4036 KB Output is correct
11 Correct 72 ms 5572 KB Output is correct
12 Correct 77 ms 5568 KB Output is correct
13 Correct 99 ms 5636 KB Output is correct
14 Correct 76 ms 5524 KB Output is correct
15 Correct 72 ms 5568 KB Output is correct
16 Correct 77 ms 5504 KB Output is correct
17 Correct 80 ms 5564 KB Output is correct
18 Correct 92 ms 5484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 3908 KB Output is correct
2 Correct 84 ms 4036 KB Output is correct
3 Correct 95 ms 4052 KB Output is correct
4 Correct 82 ms 3968 KB Output is correct
5 Correct 70 ms 3968 KB Output is correct
6 Correct 66 ms 4024 KB Output is correct
7 Correct 67 ms 4000 KB Output is correct
8 Correct 70 ms 4024 KB Output is correct
9 Correct 83 ms 3992 KB Output is correct
10 Correct 70 ms 4036 KB Output is correct
11 Correct 72 ms 5572 KB Output is correct
12 Correct 77 ms 5568 KB Output is correct
13 Correct 99 ms 5636 KB Output is correct
14 Correct 76 ms 5524 KB Output is correct
15 Correct 72 ms 5568 KB Output is correct
16 Correct 77 ms 5504 KB Output is correct
17 Correct 80 ms 5564 KB Output is correct
18 Correct 92 ms 5484 KB Output is correct
19 Correct 288 ms 15804 KB Output is correct
20 Correct 347 ms 15716 KB Output is correct
21 Correct 160 ms 15472 KB Output is correct
22 Correct 165 ms 15292 KB Output is correct
23 Correct 116 ms 6852 KB Output is correct
24 Correct 113 ms 6916 KB Output is correct
25 Correct 174 ms 15704 KB Output is correct
26 Correct 206 ms 15776 KB Output is correct
27 Correct 199 ms 15740 KB Output is correct
28 Correct 199 ms 15748 KB Output is correct
29 Correct 196 ms 15736 KB Output is correct
30 Correct 125 ms 6904 KB Output is correct
31 Correct 266 ms 15756 KB Output is correct
32 Correct 186 ms 15516 KB Output is correct
33 Correct 145 ms 6904 KB Output is correct
34 Correct 193 ms 15692 KB Output is correct
35 Correct 144 ms 14852 KB Output is correct
36 Correct 132 ms 6888 KB Output is correct
37 Correct 110 ms 6920 KB Output is correct
38 Correct 250 ms 15564 KB Output is correct
39 Correct 134 ms 15720 KB Output is correct
40 Correct 148 ms 11780 KB Output is correct
41 Correct 333 ms 15912 KB Output is correct
42 Correct 63 ms 15200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 3908 KB Output is correct
2 Correct 84 ms 4036 KB Output is correct
3 Correct 95 ms 4052 KB Output is correct
4 Correct 82 ms 3968 KB Output is correct
5 Correct 70 ms 3968 KB Output is correct
6 Correct 66 ms 4024 KB Output is correct
7 Correct 67 ms 4000 KB Output is correct
8 Correct 70 ms 4024 KB Output is correct
9 Correct 83 ms 3992 KB Output is correct
10 Correct 70 ms 4036 KB Output is correct
11 Correct 72 ms 5572 KB Output is correct
12 Correct 77 ms 5568 KB Output is correct
13 Correct 99 ms 5636 KB Output is correct
14 Correct 76 ms 5524 KB Output is correct
15 Correct 72 ms 5568 KB Output is correct
16 Correct 77 ms 5504 KB Output is correct
17 Correct 80 ms 5564 KB Output is correct
18 Correct 92 ms 5484 KB Output is correct
19 Correct 85 ms 5428 KB Output is correct
20 Correct 92 ms 5424 KB Output is correct
21 Correct 84 ms 5512 KB Output is correct
22 Correct 62 ms 5284 KB Output is correct
23 Correct 72 ms 5524 KB Output is correct
24 Correct 79 ms 5504 KB Output is correct
25 Correct 94 ms 5584 KB Output is correct
26 Correct 67 ms 5448 KB Output is correct
27 Correct 71 ms 5572 KB Output is correct
28 Correct 65 ms 5272 KB Output is correct
29 Correct 79 ms 5552 KB Output is correct
30 Correct 65 ms 5356 KB Output is correct
31 Correct 74 ms 5492 KB Output is correct
32 Correct 72 ms 5452 KB Output is correct
33 Correct 88 ms 5584 KB Output is correct
34 Correct 77 ms 5312 KB Output is correct
35 Correct 72 ms 5568 KB Output is correct
36 Correct 76 ms 5552 KB Output is correct
37 Correct 85 ms 5548 KB Output is correct
38 Correct 79 ms 5548 KB Output is correct
39 Correct 73 ms 5644 KB Output is correct
40 Correct 78 ms 5572 KB Output is correct
41 Correct 80 ms 5524 KB Output is correct
42 Correct 73 ms 5532 KB Output is correct
43 Correct 71 ms 5416 KB Output is correct
44 Correct 76 ms 5556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 3908 KB Output is correct
2 Correct 84 ms 4036 KB Output is correct
3 Correct 95 ms 4052 KB Output is correct
4 Correct 82 ms 3968 KB Output is correct
5 Correct 70 ms 3968 KB Output is correct
6 Correct 66 ms 4024 KB Output is correct
7 Correct 67 ms 4000 KB Output is correct
8 Correct 70 ms 4024 KB Output is correct
9 Correct 83 ms 3992 KB Output is correct
10 Correct 70 ms 4036 KB Output is correct
11 Correct 72 ms 5572 KB Output is correct
12 Correct 77 ms 5568 KB Output is correct
13 Correct 99 ms 5636 KB Output is correct
14 Correct 76 ms 5524 KB Output is correct
15 Correct 72 ms 5568 KB Output is correct
16 Correct 77 ms 5504 KB Output is correct
17 Correct 80 ms 5564 KB Output is correct
18 Correct 92 ms 5484 KB Output is correct
19 Correct 288 ms 15804 KB Output is correct
20 Correct 347 ms 15716 KB Output is correct
21 Correct 160 ms 15472 KB Output is correct
22 Correct 165 ms 15292 KB Output is correct
23 Correct 116 ms 6852 KB Output is correct
24 Correct 113 ms 6916 KB Output is correct
25 Correct 174 ms 15704 KB Output is correct
26 Correct 206 ms 15776 KB Output is correct
27 Correct 199 ms 15740 KB Output is correct
28 Correct 199 ms 15748 KB Output is correct
29 Correct 196 ms 15736 KB Output is correct
30 Correct 125 ms 6904 KB Output is correct
31 Correct 266 ms 15756 KB Output is correct
32 Correct 186 ms 15516 KB Output is correct
33 Correct 145 ms 6904 KB Output is correct
34 Correct 193 ms 15692 KB Output is correct
35 Correct 144 ms 14852 KB Output is correct
36 Correct 132 ms 6888 KB Output is correct
37 Correct 110 ms 6920 KB Output is correct
38 Correct 250 ms 15564 KB Output is correct
39 Correct 134 ms 15720 KB Output is correct
40 Correct 148 ms 11780 KB Output is correct
41 Correct 333 ms 15912 KB Output is correct
42 Correct 63 ms 15200 KB Output is correct
43 Correct 85 ms 5428 KB Output is correct
44 Correct 92 ms 5424 KB Output is correct
45 Correct 84 ms 5512 KB Output is correct
46 Correct 62 ms 5284 KB Output is correct
47 Correct 72 ms 5524 KB Output is correct
48 Correct 79 ms 5504 KB Output is correct
49 Correct 94 ms 5584 KB Output is correct
50 Correct 67 ms 5448 KB Output is correct
51 Correct 71 ms 5572 KB Output is correct
52 Correct 65 ms 5272 KB Output is correct
53 Correct 79 ms 5552 KB Output is correct
54 Correct 65 ms 5356 KB Output is correct
55 Correct 74 ms 5492 KB Output is correct
56 Correct 72 ms 5452 KB Output is correct
57 Correct 88 ms 5584 KB Output is correct
58 Correct 77 ms 5312 KB Output is correct
59 Correct 72 ms 5568 KB Output is correct
60 Correct 76 ms 5552 KB Output is correct
61 Correct 85 ms 5548 KB Output is correct
62 Correct 79 ms 5548 KB Output is correct
63 Correct 73 ms 5644 KB Output is correct
64 Correct 78 ms 5572 KB Output is correct
65 Correct 80 ms 5524 KB Output is correct
66 Correct 73 ms 5532 KB Output is correct
67 Correct 71 ms 5416 KB Output is correct
68 Correct 76 ms 5556 KB Output is correct
69 Correct 349 ms 17488 KB Output is correct
70 Correct 377 ms 18300 KB Output is correct
71 Correct 116 ms 6980 KB Output is correct
72 Correct 122 ms 6880 KB Output is correct
73 Correct 114 ms 6908 KB Output is correct
74 Correct 155 ms 15460 KB Output is correct
75 Correct 111 ms 6928 KB Output is correct
76 Correct 197 ms 16152 KB Output is correct
77 Correct 170 ms 15480 KB Output is correct
78 Correct 119 ms 6852 KB Output is correct
79 Correct 116 ms 6908 KB Output is correct
80 Correct 218 ms 16664 KB Output is correct
81 Correct 123 ms 6944 KB Output is correct
82 Correct 221 ms 18316 KB Output is correct
83 Correct 270 ms 18176 KB Output is correct
84 Correct 158 ms 6976 KB Output is correct
85 Correct 131 ms 7012 KB Output is correct
86 Correct 235 ms 17008 KB Output is correct
87 Correct 349 ms 18432 KB Output is correct
88 Correct 132 ms 7028 KB Output is correct
89 Correct 227 ms 17640 KB Output is correct
90 Correct 381 ms 18344 KB Output is correct
91 Correct 163 ms 6956 KB Output is correct
92 Correct 234 ms 16896 KB Output is correct
93 Correct 160 ms 7028 KB Output is correct
94 Correct 160 ms 7048 KB Output is correct
95 Correct 174 ms 6976 KB Output is correct
96 Correct 396 ms 15472 KB Output is correct
97 Correct 215 ms 18292 KB Output is correct
98 Correct 255 ms 13724 KB Output is correct
99 Correct 502 ms 18484 KB Output is correct
100 Correct 148 ms 17744 KB Output is correct