답안 #861418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861418 2023-10-16T06:42:22 Z vjudge1 Crossing (JOI21_crossing) C++17
100 / 100
230 ms 15968 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define F
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 13, base = 161;
const int N =  1e6 + 15;
const ll inf = 1e18;
const int off = (1 << 18);
vector<int> s[3];
int T[N];
char str[N];
int n, Q;
struct Sgt {
#define ls (idx<<1)
#define rs (idx<<1|1)
    struct data {
        int pws, val, tag;
        data() : pws(0), val(0), tag(-1) {}
    } t[off * 2];
    void pull(int idx) {
        t[idx].pws = (t[ls].pws + t[rs].pws) % mod;
        t[idx].val = (t[ls].val + t[rs].val) % mod;
        return;
    }
    void push(int idx) {
        if (~t[idx].tag) {
            t[idx].val = 1ll * t[idx].pws * t[idx].tag % mod;

            if (idx < off)
                t[ls].tag = t[rs].tag = t[idx].tag;

            t[idx].tag = ~0;
        }

        return;
    }
    void build() {
        for (int idx = off, p = 1; idx < off * 2; idx++, p = 1ll * p * base % mod) {
            t[idx].pws = p;
            t[idx].val = 1ll * p * T[idx - off] % mod;
            t[idx].tag = ~0;
        }

        for (int idx = off - 1; idx >= 1; idx--) {
            pull(idx);
        }
    }
    void update(int l, int r, int val, int idx = 1, int lo = 0, int hi = off) {
        push(idx);

        if (r <= lo || hi <= l)
            return;

        if (l <= lo && hi <= r) {
            t[idx].tag = val;
            push(idx);
            return;
        }

        int mi = (lo + hi) >> 1;
        update(l, r, val, ls, lo, mi);
        update(l, r, val, rs, mi, hi);
        pull(idx);
    }
#undef ls
#undef rs
} seg;
int hsh(vector<int> cur) {
    int res = 0;

    for (int i = 0, p = 1; i < n; i++, p = 1ll * p * base % mod) {
        res = (res + 1ll * cur[i] * p) % mod;
    }

    return res;
}
vector<int> cross(vector<int> lhs, vector<int> rhs) {
    vector<int> cur(n);

    for (int i = 0, p = 1; i < n; i++, p = 1ll * p * base % mod) {
        int c = 0;

        if (lhs[i] == rhs[i])
            c = lhs[i];
        else if (lhs[i] != 0 && rhs[i] != 0)
            c = 0;
        else if (lhs[i] != 1 && rhs[i] != 1)
            c = 1;
        else if (lhs[i] != 2 && rhs[i] != 2)
            c = 2;

        cur[i] = c;
    }

    return cur;
}
int32_t main() {
    cin >> n;

    for (int k = 0; k < 3; k++) {
        scanf("%s", str);
        s[k].resize(n);

        for (int i = 0; i < n; i++) {
            if (str[i] == 'J')
                s[k][i] = 0;

            if (str[i] == 'O')
                s[k][i] = 1;

            if (str[i] == 'I')
                s[k][i] = 2;
        }
    }

    set<int> st;
    st.insert(hsh(s[0]));
    st.insert(hsh(s[1]));
    st.insert(hsh(s[2]));
    st.insert(hsh(cross(s[0], s[1])));
    st.insert(hsh(cross(s[1], s[2])));
    st.insert(hsh(cross(s[0], s[2])));
    st.insert(hsh(cross(s[0], cross(s[1], s[2]))));
    st.insert(hsh(cross(s[1], cross(s[0], s[2]))));
    st.insert(hsh(cross(s[2], cross(s[0], s[1]))));
    scanf("%d", &Q);
    scanf("%s", str);

    for (int i = 0; i < n; i++) {
        if (str[i] == 'J')
            T[i] = 0;

        if (str[i] == 'O')
            T[i] = 1;

        if (str[i] == 'I')
            T[i] = 2;
    }

    seg.build();

    if (st.find(seg.t[1].val) != st.end()) {
        puts("Yes");
    } else {
        puts("No");
    }

    while (Q--) {
        int L, R;
        char C;
        scanf("%d %d %c", &L, &R, &C);
        int c = 0;

        if (C == 'J')
            c = 0;

        if (C == 'O')
            c = 1;

        if (C == 'I')
            c = 2;

        seg.update(L - 1, R, c);
        int val = seg.t[1].val;

        if (st.find(val) != st.end()) {
            puts("Yes");
        } else {
            puts("No");
        }
    }
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:107:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         scanf("%s", str);
      |         ~~~~~^~~~~~~~~~~
Main.cpp:132:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |     scanf("%d", &Q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:133:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  133 |     scanf("%s", str);
      |     ~~~~~^~~~~~~~~~~
Main.cpp:157:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  157 |         scanf("%d %d %c", &L, &R, &C);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 9320 KB Output is correct
2 Correct 106 ms 9264 KB Output is correct
3 Correct 101 ms 9252 KB Output is correct
4 Correct 93 ms 9220 KB Output is correct
5 Correct 97 ms 9280 KB Output is correct
6 Correct 92 ms 9360 KB Output is correct
7 Correct 91 ms 9184 KB Output is correct
8 Correct 103 ms 9404 KB Output is correct
9 Correct 92 ms 9300 KB Output is correct
10 Correct 98 ms 9516 KB Output is correct
11 Correct 104 ms 9300 KB Output is correct
12 Correct 94 ms 9320 KB Output is correct
13 Correct 105 ms 9264 KB Output is correct
14 Correct 93 ms 9220 KB Output is correct
15 Correct 93 ms 9344 KB Output is correct
16 Correct 91 ms 9296 KB Output is correct
17 Correct 97 ms 9192 KB Output is correct
18 Correct 93 ms 9368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 9320 KB Output is correct
2 Correct 106 ms 9264 KB Output is correct
3 Correct 101 ms 9252 KB Output is correct
4 Correct 93 ms 9220 KB Output is correct
5 Correct 97 ms 9280 KB Output is correct
6 Correct 92 ms 9360 KB Output is correct
7 Correct 91 ms 9184 KB Output is correct
8 Correct 103 ms 9404 KB Output is correct
9 Correct 92 ms 9300 KB Output is correct
10 Correct 98 ms 9516 KB Output is correct
11 Correct 104 ms 9300 KB Output is correct
12 Correct 94 ms 9320 KB Output is correct
13 Correct 105 ms 9264 KB Output is correct
14 Correct 93 ms 9220 KB Output is correct
15 Correct 93 ms 9344 KB Output is correct
16 Correct 91 ms 9296 KB Output is correct
17 Correct 97 ms 9192 KB Output is correct
18 Correct 93 ms 9368 KB Output is correct
19 Correct 188 ms 15316 KB Output is correct
20 Correct 191 ms 15092 KB Output is correct
21 Correct 137 ms 14544 KB Output is correct
22 Correct 148 ms 12132 KB Output is correct
23 Correct 109 ms 9452 KB Output is correct
24 Correct 108 ms 9468 KB Output is correct
25 Correct 141 ms 15004 KB Output is correct
26 Correct 157 ms 15340 KB Output is correct
27 Correct 158 ms 15108 KB Output is correct
28 Correct 158 ms 15112 KB Output is correct
29 Correct 166 ms 14880 KB Output is correct
30 Correct 115 ms 9516 KB Output is correct
31 Correct 158 ms 15108 KB Output is correct
32 Correct 173 ms 14528 KB Output is correct
33 Correct 112 ms 9624 KB Output is correct
34 Correct 152 ms 15040 KB Output is correct
35 Correct 129 ms 11804 KB Output is correct
36 Correct 109 ms 9492 KB Output is correct
37 Correct 108 ms 9440 KB Output is correct
38 Correct 168 ms 15036 KB Output is correct
39 Correct 118 ms 15040 KB Output is correct
40 Correct 130 ms 11592 KB Output is correct
41 Correct 196 ms 15036 KB Output is correct
42 Correct 87 ms 15112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 9320 KB Output is correct
2 Correct 106 ms 9264 KB Output is correct
3 Correct 101 ms 9252 KB Output is correct
4 Correct 93 ms 9220 KB Output is correct
5 Correct 97 ms 9280 KB Output is correct
6 Correct 92 ms 9360 KB Output is correct
7 Correct 91 ms 9184 KB Output is correct
8 Correct 103 ms 9404 KB Output is correct
9 Correct 92 ms 9300 KB Output is correct
10 Correct 98 ms 9516 KB Output is correct
11 Correct 104 ms 9300 KB Output is correct
12 Correct 94 ms 9320 KB Output is correct
13 Correct 105 ms 9264 KB Output is correct
14 Correct 93 ms 9220 KB Output is correct
15 Correct 93 ms 9344 KB Output is correct
16 Correct 91 ms 9296 KB Output is correct
17 Correct 97 ms 9192 KB Output is correct
18 Correct 93 ms 9368 KB Output is correct
19 Correct 103 ms 9384 KB Output is correct
20 Correct 95 ms 9300 KB Output is correct
21 Correct 92 ms 9300 KB Output is correct
22 Correct 88 ms 9320 KB Output is correct
23 Correct 94 ms 9808 KB Output is correct
24 Correct 90 ms 9300 KB Output is correct
25 Correct 92 ms 9176 KB Output is correct
26 Correct 89 ms 9320 KB Output is correct
27 Correct 93 ms 9296 KB Output is correct
28 Correct 92 ms 9300 KB Output is correct
29 Correct 94 ms 9296 KB Output is correct
30 Correct 85 ms 9156 KB Output is correct
31 Correct 95 ms 9208 KB Output is correct
32 Correct 94 ms 9296 KB Output is correct
33 Correct 95 ms 9300 KB Output is correct
34 Correct 88 ms 9176 KB Output is correct
35 Correct 102 ms 9204 KB Output is correct
36 Correct 95 ms 9296 KB Output is correct
37 Correct 95 ms 9296 KB Output is correct
38 Correct 96 ms 9176 KB Output is correct
39 Correct 101 ms 9260 KB Output is correct
40 Correct 95 ms 9552 KB Output is correct
41 Correct 94 ms 9332 KB Output is correct
42 Correct 96 ms 9300 KB Output is correct
43 Correct 93 ms 9344 KB Output is correct
44 Correct 98 ms 9448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 9320 KB Output is correct
2 Correct 106 ms 9264 KB Output is correct
3 Correct 101 ms 9252 KB Output is correct
4 Correct 93 ms 9220 KB Output is correct
5 Correct 97 ms 9280 KB Output is correct
6 Correct 92 ms 9360 KB Output is correct
7 Correct 91 ms 9184 KB Output is correct
8 Correct 103 ms 9404 KB Output is correct
9 Correct 92 ms 9300 KB Output is correct
10 Correct 98 ms 9516 KB Output is correct
11 Correct 104 ms 9300 KB Output is correct
12 Correct 94 ms 9320 KB Output is correct
13 Correct 105 ms 9264 KB Output is correct
14 Correct 93 ms 9220 KB Output is correct
15 Correct 93 ms 9344 KB Output is correct
16 Correct 91 ms 9296 KB Output is correct
17 Correct 97 ms 9192 KB Output is correct
18 Correct 93 ms 9368 KB Output is correct
19 Correct 188 ms 15316 KB Output is correct
20 Correct 191 ms 15092 KB Output is correct
21 Correct 137 ms 14544 KB Output is correct
22 Correct 148 ms 12132 KB Output is correct
23 Correct 109 ms 9452 KB Output is correct
24 Correct 108 ms 9468 KB Output is correct
25 Correct 141 ms 15004 KB Output is correct
26 Correct 157 ms 15340 KB Output is correct
27 Correct 158 ms 15108 KB Output is correct
28 Correct 158 ms 15112 KB Output is correct
29 Correct 166 ms 14880 KB Output is correct
30 Correct 115 ms 9516 KB Output is correct
31 Correct 158 ms 15108 KB Output is correct
32 Correct 173 ms 14528 KB Output is correct
33 Correct 112 ms 9624 KB Output is correct
34 Correct 152 ms 15040 KB Output is correct
35 Correct 129 ms 11804 KB Output is correct
36 Correct 109 ms 9492 KB Output is correct
37 Correct 108 ms 9440 KB Output is correct
38 Correct 168 ms 15036 KB Output is correct
39 Correct 118 ms 15040 KB Output is correct
40 Correct 130 ms 11592 KB Output is correct
41 Correct 196 ms 15036 KB Output is correct
42 Correct 87 ms 15112 KB Output is correct
43 Correct 103 ms 9384 KB Output is correct
44 Correct 95 ms 9300 KB Output is correct
45 Correct 92 ms 9300 KB Output is correct
46 Correct 88 ms 9320 KB Output is correct
47 Correct 94 ms 9808 KB Output is correct
48 Correct 90 ms 9300 KB Output is correct
49 Correct 92 ms 9176 KB Output is correct
50 Correct 89 ms 9320 KB Output is correct
51 Correct 93 ms 9296 KB Output is correct
52 Correct 92 ms 9300 KB Output is correct
53 Correct 94 ms 9296 KB Output is correct
54 Correct 85 ms 9156 KB Output is correct
55 Correct 95 ms 9208 KB Output is correct
56 Correct 94 ms 9296 KB Output is correct
57 Correct 95 ms 9300 KB Output is correct
58 Correct 88 ms 9176 KB Output is correct
59 Correct 102 ms 9204 KB Output is correct
60 Correct 95 ms 9296 KB Output is correct
61 Correct 95 ms 9296 KB Output is correct
62 Correct 96 ms 9176 KB Output is correct
63 Correct 101 ms 9260 KB Output is correct
64 Correct 95 ms 9552 KB Output is correct
65 Correct 94 ms 9332 KB Output is correct
66 Correct 96 ms 9300 KB Output is correct
67 Correct 93 ms 9344 KB Output is correct
68 Correct 98 ms 9448 KB Output is correct
69 Correct 171 ms 14536 KB Output is correct
70 Correct 204 ms 15612 KB Output is correct
71 Correct 114 ms 9556 KB Output is correct
72 Correct 110 ms 9564 KB Output is correct
73 Correct 109 ms 9552 KB Output is correct
74 Correct 138 ms 11944 KB Output is correct
75 Correct 113 ms 9460 KB Output is correct
76 Correct 150 ms 15036 KB Output is correct
77 Correct 142 ms 11976 KB Output is correct
78 Correct 112 ms 9568 KB Output is correct
79 Correct 112 ms 9632 KB Output is correct
80 Correct 154 ms 13784 KB Output is correct
81 Correct 111 ms 9556 KB Output is correct
82 Correct 167 ms 15684 KB Output is correct
83 Correct 152 ms 15220 KB Output is correct
84 Correct 111 ms 9552 KB Output is correct
85 Correct 111 ms 9556 KB Output is correct
86 Correct 194 ms 14116 KB Output is correct
87 Correct 156 ms 15432 KB Output is correct
88 Correct 117 ms 9600 KB Output is correct
89 Correct 180 ms 14744 KB Output is correct
90 Correct 153 ms 15424 KB Output is correct
91 Correct 116 ms 9656 KB Output is correct
92 Correct 143 ms 13864 KB Output is correct
93 Correct 112 ms 9596 KB Output is correct
94 Correct 112 ms 9552 KB Output is correct
95 Correct 112 ms 9552 KB Output is correct
96 Correct 166 ms 15112 KB Output is correct
97 Correct 117 ms 15676 KB Output is correct
98 Correct 139 ms 13444 KB Output is correct
99 Correct 230 ms 15776 KB Output is correct
100 Correct 101 ms 15968 KB Output is correct