답안 #680406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680406 2023-01-10T17:42:31 Z bashkort Crossing (JOI21_crossing) C++17
100 / 100
313 ms 13236 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

string cross(string &a, string &b) {
    string res(a.size(), 'a');
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] == b[i]) {
            res[i] = a[i];
        } else {
            res[i] = 'J' ^ 'O' ^ 'I' ^ a[i] ^ b[i];
        }
    }
    return res;
}

constexpr int MOD = 1e9 + 9;
constexpr int P = 239;

struct Info {
    int h, power, sum;

    Info() = default;
    Info(int a, int b) : h(a), power(b) {}
};

vector<Info> t;
vector<int> tag;
int sz;

void apply(int x, int y) {
    if (y != -1) {
        t[x].h = 1LL * t[x].sum * y % MOD;
        tag[x] = y;
    }
}

void push(int x) {
    apply(x << 1, tag[x]);
    apply(x << 1 | 1, tag[x]);
    tag[x] = -1;
}

void pull(int x) {
    t[x].h = (t[x << 1].h + 1LL * t[x << 1].power * P % MOD * t[x << 1 | 1].h) % MOD;
    t[x].power = 1LL * t[x << 1].power * t[x << 1 | 1].power % MOD * P % MOD;
    t[x].sum = (t[x << 1].sum + 1LL * t[x << 1].power * P % MOD * t[x << 1 | 1].sum) % MOD;
}

int to_int(char c) {
    return c == 'J' ? 0 : 1 + (c != 'O');
}

void init(int n, string T) {
    sz = 1 << __lg(n) + bool(n & (n - 1));
    tag.assign(sz << 1, -1), t.resize(sz << 1);

    for (int i = 0; i < n; ++i) {
        t[i + sz].sum = t[i + sz].power = 1;
        t[i + sz].h = to_int(T[i]);
    }
    for (int i = sz - 1; i > 0; --i) {
        pull(i);
    }
}

void rangeApply(int l, int r, int tg, int x = 1, int lx = 0, int rx = sz) {
    if (l >= rx || lx >= r) {
        return;
    }
    if (l <= lx && rx <= r) {
        apply(x, tg);
        return;
    }

    push(x);

    int mid = (lx + rx) >> 1;

    rangeApply(l, r, tg, x << 1, lx, mid), rangeApply(l, r, tg, x << 1 | 1, mid, rx);

    pull(x);
}

int hashed(string &s) {
    int ans = 0;
    for (int i = int(s.size()) - 1; i >= 0; --i) {
        ans = (1LL * ans * P + to_int(s[i])) % MOD;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    string A, B, C;
    cin >> A >> B >> C;

    unordered_set<string> every{A, B, C};

    queue<string> qu;
    qu.push(A), qu.push(B), qu.push(C);

    while (!qu.empty()) {
        string s = qu.front();
        qu.pop();

        for (string to : every) {
            string res = cross(s, to);

            if (!every.count(res)) {
                qu.push(res);
                every.insert(res);
            }
        }
    }

    unordered_set<int> st;
    for (string s : every) {
        st.insert(hashed(s));
    }

    int q;
    cin >> q;

    string T;
    cin >> T;

    init(n, T);

    cout << (st.count(t[1].h) ? "Yes\n" : "No\n");

    while (q--) {
        int l, r;
        char c;
        cin >> l >> r >> c;

        rangeApply(l - 1, r, to_int(c));

        cout << (st.count(t[1].h) ? "Yes\n" : "No\n");
    }

    return 0;
}

Compilation message

Main.cpp: In function 'std::string cross(std::string&, std::string&)':
Main.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i < a.size(); ++i) {
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'void init(int, std::string)':
Main.cpp:56:23: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   56 |     sz = 1 << __lg(n) + bool(n & (n - 1));
      |               ~~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 824 KB Output is correct
2 Correct 81 ms 888 KB Output is correct
3 Correct 82 ms 824 KB Output is correct
4 Correct 75 ms 844 KB Output is correct
5 Correct 70 ms 1004 KB Output is correct
6 Correct 68 ms 792 KB Output is correct
7 Correct 75 ms 796 KB Output is correct
8 Correct 72 ms 908 KB Output is correct
9 Correct 73 ms 800 KB Output is correct
10 Correct 73 ms 904 KB Output is correct
11 Correct 74 ms 908 KB Output is correct
12 Correct 73 ms 860 KB Output is correct
13 Correct 73 ms 844 KB Output is correct
14 Correct 73 ms 904 KB Output is correct
15 Correct 75 ms 808 KB Output is correct
16 Correct 73 ms 828 KB Output is correct
17 Correct 74 ms 828 KB Output is correct
18 Correct 81 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 824 KB Output is correct
2 Correct 81 ms 888 KB Output is correct
3 Correct 82 ms 824 KB Output is correct
4 Correct 75 ms 844 KB Output is correct
5 Correct 70 ms 1004 KB Output is correct
6 Correct 68 ms 792 KB Output is correct
7 Correct 75 ms 796 KB Output is correct
8 Correct 72 ms 908 KB Output is correct
9 Correct 73 ms 800 KB Output is correct
10 Correct 73 ms 904 KB Output is correct
11 Correct 74 ms 908 KB Output is correct
12 Correct 73 ms 860 KB Output is correct
13 Correct 73 ms 844 KB Output is correct
14 Correct 73 ms 904 KB Output is correct
15 Correct 75 ms 808 KB Output is correct
16 Correct 73 ms 828 KB Output is correct
17 Correct 74 ms 828 KB Output is correct
18 Correct 81 ms 924 KB Output is correct
19 Correct 237 ms 10448 KB Output is correct
20 Correct 234 ms 10428 KB Output is correct
21 Correct 164 ms 10380 KB Output is correct
22 Correct 162 ms 10128 KB Output is correct
23 Correct 116 ms 1544 KB Output is correct
24 Correct 119 ms 1512 KB Output is correct
25 Correct 181 ms 10324 KB Output is correct
26 Correct 175 ms 10404 KB Output is correct
27 Correct 184 ms 10332 KB Output is correct
28 Correct 195 ms 10480 KB Output is correct
29 Correct 189 ms 10476 KB Output is correct
30 Correct 126 ms 1500 KB Output is correct
31 Correct 193 ms 10448 KB Output is correct
32 Correct 198 ms 10316 KB Output is correct
33 Correct 126 ms 1508 KB Output is correct
34 Correct 189 ms 10408 KB Output is correct
35 Correct 181 ms 10036 KB Output is correct
36 Correct 150 ms 1484 KB Output is correct
37 Correct 119 ms 1436 KB Output is correct
38 Correct 210 ms 10476 KB Output is correct
39 Correct 132 ms 10348 KB Output is correct
40 Correct 180 ms 6064 KB Output is correct
41 Correct 302 ms 10636 KB Output is correct
42 Correct 93 ms 10580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 824 KB Output is correct
2 Correct 81 ms 888 KB Output is correct
3 Correct 82 ms 824 KB Output is correct
4 Correct 75 ms 844 KB Output is correct
5 Correct 70 ms 1004 KB Output is correct
6 Correct 68 ms 792 KB Output is correct
7 Correct 75 ms 796 KB Output is correct
8 Correct 72 ms 908 KB Output is correct
9 Correct 73 ms 800 KB Output is correct
10 Correct 73 ms 904 KB Output is correct
11 Correct 74 ms 908 KB Output is correct
12 Correct 73 ms 860 KB Output is correct
13 Correct 73 ms 844 KB Output is correct
14 Correct 73 ms 904 KB Output is correct
15 Correct 75 ms 808 KB Output is correct
16 Correct 73 ms 828 KB Output is correct
17 Correct 74 ms 828 KB Output is correct
18 Correct 81 ms 924 KB Output is correct
19 Correct 82 ms 880 KB Output is correct
20 Correct 87 ms 844 KB Output is correct
21 Correct 85 ms 932 KB Output is correct
22 Correct 94 ms 780 KB Output is correct
23 Correct 74 ms 908 KB Output is correct
24 Correct 72 ms 784 KB Output is correct
25 Correct 77 ms 908 KB Output is correct
26 Correct 73 ms 848 KB Output is correct
27 Correct 77 ms 792 KB Output is correct
28 Correct 69 ms 772 KB Output is correct
29 Correct 76 ms 804 KB Output is correct
30 Correct 72 ms 864 KB Output is correct
31 Correct 79 ms 932 KB Output is correct
32 Correct 76 ms 804 KB Output is correct
33 Correct 78 ms 848 KB Output is correct
34 Correct 76 ms 844 KB Output is correct
35 Correct 85 ms 844 KB Output is correct
36 Correct 79 ms 844 KB Output is correct
37 Correct 77 ms 808 KB Output is correct
38 Correct 78 ms 856 KB Output is correct
39 Correct 77 ms 848 KB Output is correct
40 Correct 81 ms 844 KB Output is correct
41 Correct 84 ms 796 KB Output is correct
42 Correct 85 ms 808 KB Output is correct
43 Correct 77 ms 828 KB Output is correct
44 Correct 77 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 824 KB Output is correct
2 Correct 81 ms 888 KB Output is correct
3 Correct 82 ms 824 KB Output is correct
4 Correct 75 ms 844 KB Output is correct
5 Correct 70 ms 1004 KB Output is correct
6 Correct 68 ms 792 KB Output is correct
7 Correct 75 ms 796 KB Output is correct
8 Correct 72 ms 908 KB Output is correct
9 Correct 73 ms 800 KB Output is correct
10 Correct 73 ms 904 KB Output is correct
11 Correct 74 ms 908 KB Output is correct
12 Correct 73 ms 860 KB Output is correct
13 Correct 73 ms 844 KB Output is correct
14 Correct 73 ms 904 KB Output is correct
15 Correct 75 ms 808 KB Output is correct
16 Correct 73 ms 828 KB Output is correct
17 Correct 74 ms 828 KB Output is correct
18 Correct 81 ms 924 KB Output is correct
19 Correct 237 ms 10448 KB Output is correct
20 Correct 234 ms 10428 KB Output is correct
21 Correct 164 ms 10380 KB Output is correct
22 Correct 162 ms 10128 KB Output is correct
23 Correct 116 ms 1544 KB Output is correct
24 Correct 119 ms 1512 KB Output is correct
25 Correct 181 ms 10324 KB Output is correct
26 Correct 175 ms 10404 KB Output is correct
27 Correct 184 ms 10332 KB Output is correct
28 Correct 195 ms 10480 KB Output is correct
29 Correct 189 ms 10476 KB Output is correct
30 Correct 126 ms 1500 KB Output is correct
31 Correct 193 ms 10448 KB Output is correct
32 Correct 198 ms 10316 KB Output is correct
33 Correct 126 ms 1508 KB Output is correct
34 Correct 189 ms 10408 KB Output is correct
35 Correct 181 ms 10036 KB Output is correct
36 Correct 150 ms 1484 KB Output is correct
37 Correct 119 ms 1436 KB Output is correct
38 Correct 210 ms 10476 KB Output is correct
39 Correct 132 ms 10348 KB Output is correct
40 Correct 180 ms 6064 KB Output is correct
41 Correct 302 ms 10636 KB Output is correct
42 Correct 93 ms 10580 KB Output is correct
43 Correct 82 ms 880 KB Output is correct
44 Correct 87 ms 844 KB Output is correct
45 Correct 85 ms 932 KB Output is correct
46 Correct 94 ms 780 KB Output is correct
47 Correct 74 ms 908 KB Output is correct
48 Correct 72 ms 784 KB Output is correct
49 Correct 77 ms 908 KB Output is correct
50 Correct 73 ms 848 KB Output is correct
51 Correct 77 ms 792 KB Output is correct
52 Correct 69 ms 772 KB Output is correct
53 Correct 76 ms 804 KB Output is correct
54 Correct 72 ms 864 KB Output is correct
55 Correct 79 ms 932 KB Output is correct
56 Correct 76 ms 804 KB Output is correct
57 Correct 78 ms 848 KB Output is correct
58 Correct 76 ms 844 KB Output is correct
59 Correct 85 ms 844 KB Output is correct
60 Correct 79 ms 844 KB Output is correct
61 Correct 77 ms 808 KB Output is correct
62 Correct 78 ms 856 KB Output is correct
63 Correct 77 ms 848 KB Output is correct
64 Correct 81 ms 844 KB Output is correct
65 Correct 84 ms 796 KB Output is correct
66 Correct 85 ms 808 KB Output is correct
67 Correct 77 ms 828 KB Output is correct
68 Correct 77 ms 924 KB Output is correct
69 Correct 275 ms 12280 KB Output is correct
70 Correct 313 ms 12960 KB Output is correct
71 Correct 141 ms 1528 KB Output is correct
72 Correct 127 ms 1560 KB Output is correct
73 Correct 118 ms 1504 KB Output is correct
74 Correct 164 ms 10724 KB Output is correct
75 Correct 123 ms 1544 KB Output is correct
76 Correct 238 ms 10824 KB Output is correct
77 Correct 180 ms 10488 KB Output is correct
78 Correct 123 ms 1480 KB Output is correct
79 Correct 121 ms 1552 KB Output is correct
80 Correct 196 ms 11660 KB Output is correct
81 Correct 126 ms 1612 KB Output is correct
82 Correct 231 ms 13044 KB Output is correct
83 Correct 210 ms 13008 KB Output is correct
84 Correct 125 ms 1648 KB Output is correct
85 Correct 129 ms 1584 KB Output is correct
86 Correct 249 ms 11968 KB Output is correct
87 Correct 262 ms 12780 KB Output is correct
88 Correct 138 ms 1768 KB Output is correct
89 Correct 246 ms 12288 KB Output is correct
90 Correct 234 ms 12988 KB Output is correct
91 Correct 147 ms 1572 KB Output is correct
92 Correct 186 ms 11984 KB Output is correct
93 Correct 124 ms 1544 KB Output is correct
94 Correct 123 ms 1528 KB Output is correct
95 Correct 127 ms 1540 KB Output is correct
96 Correct 219 ms 10396 KB Output is correct
97 Correct 187 ms 13000 KB Output is correct
98 Correct 191 ms 7796 KB Output is correct
99 Correct 289 ms 13236 KB Output is correct
100 Correct 139 ms 12968 KB Output is correct