답안 #493562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493562 2021-12-12T06:19:49 Z 600Mihnea Crossing (JOI21_crossing) C++17
100 / 100
2209 ms 41540 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

/// Delete all asserts for extra Boost

class Node {
public:
  bool stequal = false;
  bool jequal = false;
  bool oequal = false;
  bool iequal = false;
};

class IsEqual {
private:
  string s;
  string t;
  int n;
  vector<Node> tree;
  vector<char> lazy;

  void build(int v, int tl, int tr) {
    if (tl == tr) {
      tree[v].stequal = (s[tl] == t[tl]);
      tree[v].jequal = (s[tl] == 'J');
      tree[v].oequal = (s[tl] == 'O');
      tree[v].iequal = (s[tl] == 'I');

    } else {
      int tm = (tl + tr) / 2;
      build(2 * v, tl, tm);
      build(2 * v + 1, tm + 1, tr);
      tree[v].stequal = tree[2 * v].stequal & tree[2 * v + 1].stequal;
      tree[v].jequal = tree[2 * v].jequal & tree[2 * v + 1].jequal;
      tree[v].oequal = tree[2 * v].oequal & tree[2 * v + 1].oequal;
      tree[v].iequal = tree[2 * v].iequal & tree[2 * v + 1].iequal;
    }
  }

  void modify(int v, int tl, int tr, int l, int r, char ch) {
    if (lazy[v] != 'X') { /// push
      assert(lazy[v] == 'J' || lazy[v] == 'O' || lazy[v] == 'I');
      if (lazy[v] == 'J') {
        tree[v].stequal = tree[v].jequal;
      } else {
        if (lazy[v] == 'O') {
          tree[v].stequal = tree[v].oequal;
        } else {
          tree[v].stequal = tree[v].iequal;
        }
      }
      if (tl < tr) {
        lazy[2 * v] = lazy[2 * v + 1] = lazy[v];
      }
      lazy[v] = 'X';
    }
    if (tr < l || r < tl) {
      return;
    }
    if (l <= tl && tr <= r) {
      lazy[v] = ch;
      assert(lazy[v] == 'J' || lazy[v] == 'O' || lazy[v] == 'I');
      if (lazy[v] == 'J') {
        tree[v].stequal = tree[v].jequal;
      } else {
        if (lazy[v] == 'O') {
          tree[v].stequal = tree[v].oequal;
        } else {
          tree[v].stequal = tree[v].iequal;
        }
      }
      if (tl < tr) {
        lazy[2 * v] = lazy[2 * v + 1] = lazy[v];
      }
      lazy[v] = 'X';
    } else {
      int tm = (tl + tr) / 2;
      modify(2 * v, tl, tm, l, r, ch);
      modify(2 * v + 1, tm + 1, tr, l, r, ch);
      tree[v].stequal = tree[2 * v].stequal & tree[2 * v + 1].stequal;
    }
  }

public:

  IsEqual(string s, string t) : s(s), t(t), n((int) s.size()), tree(4 * ((int) s.size() + 7)), lazy(4 * ((int) s.size()), 'X') {
    assert((int) s.size() == (int) t.size());
    build(1, 0, n - 1);
  }

  void modify(int l, int r, char ch) {
    l--;
    r--;
    assert(0 <= l && l <= r && r < n);
    modify(1, 0, n - 1, l, r, ch);
  }

  bool isEqual() {
    return tree[1].stequal;
  }
};

string operator + (string s, string t) {
  assert((int) s.size() == (int) t.size());
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] != t[i]) {
      int x = 'J' + 'O' + 'I' - s[i] - t[i];
      s[i] = x;
    }
  }
  return s;
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  int n, q;
  string a, b, c, t;
  vector<IsEqual> all;
  cin >> n >> a >> b >> c >> q >> t;

  all.push_back({a, t});
  all.push_back({b, t});
  all.push_back({c, t});
  all.push_back({a + b, t});
  all.push_back({b + c, t});
  all.push_back({c + a, t});
  all.push_back({a + (b + c), t});
  all.push_back({b + (c + a), t});
  all.push_back({c + (a + b), t});


  function <string()> solve = [&] () {
    bool ok = false;
    for (auto &x : all) {
      ok |= x.isEqual();
    }
    if (ok) {
      return "Yes";
    } else {
      return "No";
    }
  };

  cout << solve() << "\n";

  while (q--) {
    int l, r;
    string ch;
    cin >> l >> r >> ch;
    for (auto& x : all) {
      x.modify(l, r, ch[0]);
    }
    cout << solve() << "\n";
  }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 872 KB Output is correct
2 Correct 390 ms 880 KB Output is correct
3 Correct 458 ms 960 KB Output is correct
4 Correct 354 ms 780 KB Output is correct
5 Correct 290 ms 1000 KB Output is correct
6 Correct 375 ms 800 KB Output is correct
7 Correct 292 ms 844 KB Output is correct
8 Correct 372 ms 860 KB Output is correct
9 Correct 316 ms 908 KB Output is correct
10 Correct 343 ms 912 KB Output is correct
11 Correct 303 ms 1128 KB Output is correct
12 Correct 318 ms 884 KB Output is correct
13 Correct 302 ms 888 KB Output is correct
14 Correct 324 ms 872 KB Output is correct
15 Correct 311 ms 876 KB Output is correct
16 Correct 309 ms 892 KB Output is correct
17 Correct 319 ms 836 KB Output is correct
18 Correct 425 ms 908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 872 KB Output is correct
2 Correct 390 ms 880 KB Output is correct
3 Correct 458 ms 960 KB Output is correct
4 Correct 354 ms 780 KB Output is correct
5 Correct 290 ms 1000 KB Output is correct
6 Correct 375 ms 800 KB Output is correct
7 Correct 292 ms 844 KB Output is correct
8 Correct 372 ms 860 KB Output is correct
9 Correct 316 ms 908 KB Output is correct
10 Correct 343 ms 912 KB Output is correct
11 Correct 303 ms 1128 KB Output is correct
12 Correct 318 ms 884 KB Output is correct
13 Correct 302 ms 888 KB Output is correct
14 Correct 324 ms 872 KB Output is correct
15 Correct 311 ms 876 KB Output is correct
16 Correct 309 ms 892 KB Output is correct
17 Correct 319 ms 836 KB Output is correct
18 Correct 425 ms 908 KB Output is correct
19 Correct 2085 ms 41208 KB Output is correct
20 Correct 1883 ms 41192 KB Output is correct
21 Correct 1059 ms 38872 KB Output is correct
22 Correct 1075 ms 34996 KB Output is correct
23 Correct 598 ms 2916 KB Output is correct
24 Correct 579 ms 2980 KB Output is correct
25 Correct 1165 ms 41244 KB Output is correct
26 Correct 1152 ms 41256 KB Output is correct
27 Correct 1393 ms 41288 KB Output is correct
28 Correct 1421 ms 41252 KB Output is correct
29 Correct 1380 ms 40064 KB Output is correct
30 Correct 649 ms 3088 KB Output is correct
31 Correct 1351 ms 41296 KB Output is correct
32 Correct 1322 ms 37676 KB Output is correct
33 Correct 585 ms 2884 KB Output is correct
34 Correct 1383 ms 41304 KB Output is correct
35 Correct 956 ms 30976 KB Output is correct
36 Correct 554 ms 3024 KB Output is correct
37 Correct 683 ms 2908 KB Output is correct
38 Correct 1563 ms 41392 KB Output is correct
39 Correct 695 ms 41248 KB Output is correct
40 Correct 984 ms 27552 KB Output is correct
41 Correct 2209 ms 41488 KB Output is correct
42 Correct 133 ms 41512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 872 KB Output is correct
2 Correct 390 ms 880 KB Output is correct
3 Correct 458 ms 960 KB Output is correct
4 Correct 354 ms 780 KB Output is correct
5 Correct 290 ms 1000 KB Output is correct
6 Correct 375 ms 800 KB Output is correct
7 Correct 292 ms 844 KB Output is correct
8 Correct 372 ms 860 KB Output is correct
9 Correct 316 ms 908 KB Output is correct
10 Correct 343 ms 912 KB Output is correct
11 Correct 303 ms 1128 KB Output is correct
12 Correct 318 ms 884 KB Output is correct
13 Correct 302 ms 888 KB Output is correct
14 Correct 324 ms 872 KB Output is correct
15 Correct 311 ms 876 KB Output is correct
16 Correct 309 ms 892 KB Output is correct
17 Correct 319 ms 836 KB Output is correct
18 Correct 425 ms 908 KB Output is correct
19 Correct 374 ms 980 KB Output is correct
20 Correct 444 ms 884 KB Output is correct
21 Correct 304 ms 836 KB Output is correct
22 Correct 261 ms 848 KB Output is correct
23 Correct 351 ms 876 KB Output is correct
24 Correct 293 ms 1016 KB Output is correct
25 Correct 315 ms 880 KB Output is correct
26 Correct 296 ms 844 KB Output is correct
27 Correct 304 ms 920 KB Output is correct
28 Correct 279 ms 872 KB Output is correct
29 Correct 338 ms 884 KB Output is correct
30 Correct 254 ms 896 KB Output is correct
31 Correct 341 ms 864 KB Output is correct
32 Correct 290 ms 924 KB Output is correct
33 Correct 327 ms 836 KB Output is correct
34 Correct 284 ms 888 KB Output is correct
35 Correct 300 ms 920 KB Output is correct
36 Correct 333 ms 968 KB Output is correct
37 Correct 297 ms 856 KB Output is correct
38 Correct 352 ms 888 KB Output is correct
39 Correct 298 ms 868 KB Output is correct
40 Correct 321 ms 848 KB Output is correct
41 Correct 328 ms 836 KB Output is correct
42 Correct 326 ms 956 KB Output is correct
43 Correct 294 ms 824 KB Output is correct
44 Correct 312 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 872 KB Output is correct
2 Correct 390 ms 880 KB Output is correct
3 Correct 458 ms 960 KB Output is correct
4 Correct 354 ms 780 KB Output is correct
5 Correct 290 ms 1000 KB Output is correct
6 Correct 375 ms 800 KB Output is correct
7 Correct 292 ms 844 KB Output is correct
8 Correct 372 ms 860 KB Output is correct
9 Correct 316 ms 908 KB Output is correct
10 Correct 343 ms 912 KB Output is correct
11 Correct 303 ms 1128 KB Output is correct
12 Correct 318 ms 884 KB Output is correct
13 Correct 302 ms 888 KB Output is correct
14 Correct 324 ms 872 KB Output is correct
15 Correct 311 ms 876 KB Output is correct
16 Correct 309 ms 892 KB Output is correct
17 Correct 319 ms 836 KB Output is correct
18 Correct 425 ms 908 KB Output is correct
19 Correct 2085 ms 41208 KB Output is correct
20 Correct 1883 ms 41192 KB Output is correct
21 Correct 1059 ms 38872 KB Output is correct
22 Correct 1075 ms 34996 KB Output is correct
23 Correct 598 ms 2916 KB Output is correct
24 Correct 579 ms 2980 KB Output is correct
25 Correct 1165 ms 41244 KB Output is correct
26 Correct 1152 ms 41256 KB Output is correct
27 Correct 1393 ms 41288 KB Output is correct
28 Correct 1421 ms 41252 KB Output is correct
29 Correct 1380 ms 40064 KB Output is correct
30 Correct 649 ms 3088 KB Output is correct
31 Correct 1351 ms 41296 KB Output is correct
32 Correct 1322 ms 37676 KB Output is correct
33 Correct 585 ms 2884 KB Output is correct
34 Correct 1383 ms 41304 KB Output is correct
35 Correct 956 ms 30976 KB Output is correct
36 Correct 554 ms 3024 KB Output is correct
37 Correct 683 ms 2908 KB Output is correct
38 Correct 1563 ms 41392 KB Output is correct
39 Correct 695 ms 41248 KB Output is correct
40 Correct 984 ms 27552 KB Output is correct
41 Correct 2209 ms 41488 KB Output is correct
42 Correct 133 ms 41512 KB Output is correct
43 Correct 374 ms 980 KB Output is correct
44 Correct 444 ms 884 KB Output is correct
45 Correct 304 ms 836 KB Output is correct
46 Correct 261 ms 848 KB Output is correct
47 Correct 351 ms 876 KB Output is correct
48 Correct 293 ms 1016 KB Output is correct
49 Correct 315 ms 880 KB Output is correct
50 Correct 296 ms 844 KB Output is correct
51 Correct 304 ms 920 KB Output is correct
52 Correct 279 ms 872 KB Output is correct
53 Correct 338 ms 884 KB Output is correct
54 Correct 254 ms 896 KB Output is correct
55 Correct 341 ms 864 KB Output is correct
56 Correct 290 ms 924 KB Output is correct
57 Correct 327 ms 836 KB Output is correct
58 Correct 284 ms 888 KB Output is correct
59 Correct 300 ms 920 KB Output is correct
60 Correct 333 ms 968 KB Output is correct
61 Correct 297 ms 856 KB Output is correct
62 Correct 352 ms 888 KB Output is correct
63 Correct 298 ms 868 KB Output is correct
64 Correct 321 ms 848 KB Output is correct
65 Correct 328 ms 836 KB Output is correct
66 Correct 326 ms 956 KB Output is correct
67 Correct 294 ms 824 KB Output is correct
68 Correct 312 ms 816 KB Output is correct
69 Correct 1734 ms 34696 KB Output is correct
70 Correct 1841 ms 41280 KB Output is correct
71 Correct 589 ms 2940 KB Output is correct
72 Correct 614 ms 3104 KB Output is correct
73 Correct 631 ms 3024 KB Output is correct
74 Correct 1002 ms 34648 KB Output is correct
75 Correct 598 ms 2968 KB Output is correct
76 Correct 1061 ms 41416 KB Output is correct
77 Correct 1101 ms 34856 KB Output is correct
78 Correct 610 ms 3020 KB Output is correct
79 Correct 622 ms 3024 KB Output is correct
80 Correct 959 ms 29528 KB Output is correct
81 Correct 551 ms 2884 KB Output is correct
82 Correct 1081 ms 41356 KB Output is correct
83 Correct 1082 ms 38796 KB Output is correct
84 Correct 654 ms 2972 KB Output is correct
85 Correct 566 ms 2880 KB Output is correct
86 Correct 1311 ms 31732 KB Output is correct
87 Correct 1398 ms 41216 KB Output is correct
88 Correct 652 ms 2964 KB Output is correct
89 Correct 1224 ms 36724 KB Output is correct
90 Correct 1352 ms 41392 KB Output is correct
91 Correct 678 ms 3012 KB Output is correct
92 Correct 956 ms 31160 KB Output is correct
93 Correct 587 ms 3088 KB Output is correct
94 Correct 559 ms 2896 KB Output is correct
95 Correct 572 ms 2944 KB Output is correct
96 Correct 1567 ms 41484 KB Output is correct
97 Correct 655 ms 41292 KB Output is correct
98 Correct 971 ms 27536 KB Output is correct
99 Correct 2183 ms 41540 KB Output is correct
100 Correct 132 ms 41484 KB Output is correct