답안 #831233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831233 2023-08-20T01:21:23 Z perchuts Crossing (JOI21_crossing) C++17
100 / 100
403 ms 35864 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int ll

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;

const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 3e5+100;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rnd(int l, int r) {
      uniform_int_distribution<ll> uid(l, r);
      return uid(rng);
}

int pr[maxn][3], seg[4*maxn], lz[4*maxn];

void push(int i, int l, int r) {
      if (lz[i] == 3) return;
      seg[i] = pr[r][lz[i]] ^ pr[l-1][lz[i]];
      if (l != r) lz[2*i] = lz[2*i+1] = lz[i];
      lz[i] = 3;
}

void upd(int i, int l, int r, int x, int y, int k) {
      push(i, l, r);
      if (r < x || y < l) return;
      if (x <= l && r <= y) {
            lz[i] = k;
            push(i, l, r);
            return;
      }
      int md = (l + r) / 2;
      upd(2*i, l, md, x, y, k), upd(2*i+1, md+1, r, x, y, k);
      seg[i] = seg[2*i] ^ seg[2*i+1];
}

int32_t main(){_
      int n; cin >> n; string a, b, c; cin >> a >> b >> c;
      // there are only 27 strings that can be generated (trust)
      map<char, int> f;

      f['J'] = 2, f['O'] = 0, f['I'] = 1;

      for (int i = 0; i < 3; ++i) {
            for (int j = 1; j <= n; ++j) {
                  pr[j][i] = pr[j-1][i] ^ rnd(0, 8e18);
            }
      }

      map<int, bool> existe;

      for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                  for (int k = 0; k < 3; ++k) {
                        int x = 0;
                        if ((i + j + k) % 3 != 1) continue;
                        for (int w = 1; w <= n; ++w) {
                              int ac = f[a[w-1]], bc = f[b[w-1]], cc = f[c[w-1]];
                              int res = (ac * i + bc * j + cc * k) % 3;
                              if (ac == bc && bc == cc) res = ac;
                              x ^= pr[w][res] ^ pr[w-1][res];
                        }
                        existe[x] = 1;
                  }
            }
      }

      for (int i = 1; i < 4*maxn; ++i) lz[i] = 3;

      int q; cin >> q;
      string t; cin >> t;

      for (int i = 1; i <= n; ++i) upd(1, 1, n, i, i, f[t[i-1]]);

      cout << (existe[seg[1]] == 1 ? "Yes" : "No") << endl;

      while (q--) {
            int l, r; char c; cin >> l >> r >> c;
            upd(1, 1, n, l, r, f[c]);
            cout << (existe[seg[1]] == 1 ? "Yes" : "No") << endl;
      }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 19628 KB Output is correct
2 Correct 121 ms 20472 KB Output is correct
3 Correct 94 ms 13960 KB Output is correct
4 Correct 124 ms 20408 KB Output is correct
5 Correct 114 ms 20592 KB Output is correct
6 Correct 122 ms 19672 KB Output is correct
7 Correct 111 ms 20044 KB Output is correct
8 Correct 137 ms 20812 KB Output is correct
9 Correct 125 ms 20384 KB Output is correct
10 Correct 125 ms 21836 KB Output is correct
11 Correct 129 ms 21128 KB Output is correct
12 Correct 124 ms 21832 KB Output is correct
13 Correct 177 ms 21032 KB Output is correct
14 Correct 127 ms 21912 KB Output is correct
15 Correct 134 ms 21036 KB Output is correct
16 Correct 139 ms 22008 KB Output is correct
17 Correct 121 ms 21148 KB Output is correct
18 Correct 78 ms 12252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 19628 KB Output is correct
2 Correct 121 ms 20472 KB Output is correct
3 Correct 94 ms 13960 KB Output is correct
4 Correct 124 ms 20408 KB Output is correct
5 Correct 114 ms 20592 KB Output is correct
6 Correct 122 ms 19672 KB Output is correct
7 Correct 111 ms 20044 KB Output is correct
8 Correct 137 ms 20812 KB Output is correct
9 Correct 125 ms 20384 KB Output is correct
10 Correct 125 ms 21836 KB Output is correct
11 Correct 129 ms 21128 KB Output is correct
12 Correct 124 ms 21832 KB Output is correct
13 Correct 177 ms 21032 KB Output is correct
14 Correct 127 ms 21912 KB Output is correct
15 Correct 134 ms 21036 KB Output is correct
16 Correct 139 ms 22008 KB Output is correct
17 Correct 121 ms 21148 KB Output is correct
18 Correct 78 ms 12252 KB Output is correct
19 Correct 377 ms 29616 KB Output is correct
20 Correct 302 ms 30324 KB Output is correct
21 Correct 300 ms 30868 KB Output is correct
22 Correct 277 ms 28340 KB Output is correct
23 Correct 170 ms 23344 KB Output is correct
24 Correct 162 ms 22100 KB Output is correct
25 Correct 324 ms 31964 KB Output is correct
26 Correct 349 ms 29976 KB Output is correct
27 Correct 364 ms 32356 KB Output is correct
28 Correct 332 ms 29924 KB Output is correct
29 Correct 315 ms 31968 KB Output is correct
30 Correct 175 ms 23228 KB Output is correct
31 Correct 351 ms 32336 KB Output is correct
32 Correct 390 ms 29372 KB Output is correct
33 Correct 166 ms 21904 KB Output is correct
34 Correct 319 ms 30096 KB Output is correct
35 Correct 268 ms 28792 KB Output is correct
36 Correct 169 ms 22112 KB Output is correct
37 Correct 183 ms 21980 KB Output is correct
38 Correct 248 ms 27692 KB Output is correct
39 Correct 226 ms 26284 KB Output is correct
40 Correct 239 ms 26460 KB Output is correct
41 Correct 255 ms 20232 KB Output is correct
42 Correct 139 ms 20296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 19628 KB Output is correct
2 Correct 121 ms 20472 KB Output is correct
3 Correct 94 ms 13960 KB Output is correct
4 Correct 124 ms 20408 KB Output is correct
5 Correct 114 ms 20592 KB Output is correct
6 Correct 122 ms 19672 KB Output is correct
7 Correct 111 ms 20044 KB Output is correct
8 Correct 137 ms 20812 KB Output is correct
9 Correct 125 ms 20384 KB Output is correct
10 Correct 125 ms 21836 KB Output is correct
11 Correct 129 ms 21128 KB Output is correct
12 Correct 124 ms 21832 KB Output is correct
13 Correct 177 ms 21032 KB Output is correct
14 Correct 127 ms 21912 KB Output is correct
15 Correct 134 ms 21036 KB Output is correct
16 Correct 139 ms 22008 KB Output is correct
17 Correct 121 ms 21148 KB Output is correct
18 Correct 78 ms 12252 KB Output is correct
19 Correct 115 ms 19904 KB Output is correct
20 Correct 96 ms 13912 KB Output is correct
21 Correct 176 ms 21280 KB Output is correct
22 Correct 105 ms 19272 KB Output is correct
23 Correct 164 ms 21324 KB Output is correct
24 Correct 114 ms 20252 KB Output is correct
25 Correct 141 ms 21324 KB Output is correct
26 Correct 119 ms 19900 KB Output is correct
27 Correct 123 ms 21232 KB Output is correct
28 Correct 118 ms 20208 KB Output is correct
29 Correct 123 ms 20640 KB Output is correct
30 Correct 106 ms 19532 KB Output is correct
31 Correct 124 ms 21492 KB Output is correct
32 Correct 121 ms 21324 KB Output is correct
33 Correct 128 ms 20904 KB Output is correct
34 Correct 108 ms 19916 KB Output is correct
35 Correct 126 ms 21908 KB Output is correct
36 Correct 120 ms 21056 KB Output is correct
37 Correct 135 ms 21808 KB Output is correct
38 Correct 133 ms 21048 KB Output is correct
39 Correct 127 ms 21828 KB Output is correct
40 Correct 124 ms 21060 KB Output is correct
41 Correct 135 ms 21824 KB Output is correct
42 Correct 151 ms 21016 KB Output is correct
43 Correct 114 ms 20384 KB Output is correct
44 Correct 158 ms 22376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 19628 KB Output is correct
2 Correct 121 ms 20472 KB Output is correct
3 Correct 94 ms 13960 KB Output is correct
4 Correct 124 ms 20408 KB Output is correct
5 Correct 114 ms 20592 KB Output is correct
6 Correct 122 ms 19672 KB Output is correct
7 Correct 111 ms 20044 KB Output is correct
8 Correct 137 ms 20812 KB Output is correct
9 Correct 125 ms 20384 KB Output is correct
10 Correct 125 ms 21836 KB Output is correct
11 Correct 129 ms 21128 KB Output is correct
12 Correct 124 ms 21832 KB Output is correct
13 Correct 177 ms 21032 KB Output is correct
14 Correct 127 ms 21912 KB Output is correct
15 Correct 134 ms 21036 KB Output is correct
16 Correct 139 ms 22008 KB Output is correct
17 Correct 121 ms 21148 KB Output is correct
18 Correct 78 ms 12252 KB Output is correct
19 Correct 377 ms 29616 KB Output is correct
20 Correct 302 ms 30324 KB Output is correct
21 Correct 300 ms 30868 KB Output is correct
22 Correct 277 ms 28340 KB Output is correct
23 Correct 170 ms 23344 KB Output is correct
24 Correct 162 ms 22100 KB Output is correct
25 Correct 324 ms 31964 KB Output is correct
26 Correct 349 ms 29976 KB Output is correct
27 Correct 364 ms 32356 KB Output is correct
28 Correct 332 ms 29924 KB Output is correct
29 Correct 315 ms 31968 KB Output is correct
30 Correct 175 ms 23228 KB Output is correct
31 Correct 351 ms 32336 KB Output is correct
32 Correct 390 ms 29372 KB Output is correct
33 Correct 166 ms 21904 KB Output is correct
34 Correct 319 ms 30096 KB Output is correct
35 Correct 268 ms 28792 KB Output is correct
36 Correct 169 ms 22112 KB Output is correct
37 Correct 183 ms 21980 KB Output is correct
38 Correct 248 ms 27692 KB Output is correct
39 Correct 226 ms 26284 KB Output is correct
40 Correct 239 ms 26460 KB Output is correct
41 Correct 255 ms 20232 KB Output is correct
42 Correct 139 ms 20296 KB Output is correct
43 Correct 115 ms 19904 KB Output is correct
44 Correct 96 ms 13912 KB Output is correct
45 Correct 176 ms 21280 KB Output is correct
46 Correct 105 ms 19272 KB Output is correct
47 Correct 164 ms 21324 KB Output is correct
48 Correct 114 ms 20252 KB Output is correct
49 Correct 141 ms 21324 KB Output is correct
50 Correct 119 ms 19900 KB Output is correct
51 Correct 123 ms 21232 KB Output is correct
52 Correct 118 ms 20208 KB Output is correct
53 Correct 123 ms 20640 KB Output is correct
54 Correct 106 ms 19532 KB Output is correct
55 Correct 124 ms 21492 KB Output is correct
56 Correct 121 ms 21324 KB Output is correct
57 Correct 128 ms 20904 KB Output is correct
58 Correct 108 ms 19916 KB Output is correct
59 Correct 126 ms 21908 KB Output is correct
60 Correct 120 ms 21056 KB Output is correct
61 Correct 135 ms 21808 KB Output is correct
62 Correct 133 ms 21048 KB Output is correct
63 Correct 127 ms 21828 KB Output is correct
64 Correct 124 ms 21060 KB Output is correct
65 Correct 135 ms 21824 KB Output is correct
66 Correct 151 ms 21016 KB Output is correct
67 Correct 114 ms 20384 KB Output is correct
68 Correct 158 ms 22376 KB Output is correct
69 Correct 338 ms 31028 KB Output is correct
70 Correct 335 ms 33980 KB Output is correct
71 Correct 168 ms 24568 KB Output is correct
72 Correct 192 ms 24492 KB Output is correct
73 Correct 159 ms 24384 KB Output is correct
74 Correct 302 ms 33164 KB Output is correct
75 Correct 175 ms 25648 KB Output is correct
76 Correct 373 ms 35864 KB Output is correct
77 Correct 281 ms 31892 KB Output is correct
78 Correct 161 ms 24392 KB Output is correct
79 Correct 196 ms 24472 KB Output is correct
80 Correct 269 ms 31904 KB Output is correct
81 Correct 179 ms 25696 KB Output is correct
82 Correct 403 ms 35688 KB Output is correct
83 Correct 317 ms 32780 KB Output is correct
84 Correct 171 ms 24328 KB Output is correct
85 Correct 171 ms 24380 KB Output is correct
86 Correct 306 ms 31256 KB Output is correct
87 Correct 332 ms 33696 KB Output is correct
88 Correct 179 ms 23680 KB Output is correct
89 Correct 360 ms 32176 KB Output is correct
90 Correct 313 ms 33944 KB Output is correct
91 Correct 173 ms 23772 KB Output is correct
92 Correct 271 ms 32052 KB Output is correct
93 Correct 158 ms 24412 KB Output is correct
94 Correct 178 ms 24360 KB Output is correct
95 Correct 184 ms 24396 KB Output is correct
96 Correct 258 ms 31132 KB Output is correct
97 Correct 234 ms 31384 KB Output is correct
98 Correct 258 ms 29828 KB Output is correct
99 Correct 325 ms 23884 KB Output is correct
100 Correct 137 ms 23180 KB Output is correct