Submission #661711

# Submission time Handle Problem Language Result Execution time Memory
661711 2022-11-26T04:12:30 Z LittleCube Crossing (JOI21_crossing) C++14
100 / 100
1020 ms 38296 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

vector<string> v(3);

void prod()
{
    int old;
    for (int t = 1; t <= 4; t++)
    {
        old = v.size();
        for (int i = 0; i < old; i++)
            for (int j = 0; j < old; j++)
            {
                string t;
                for (int k = 0; k < v[i].size(); k++)
                {
                    if (v[i][k] == v[j][k])
                        t.push_back(v[i][k]);
                    else
                    {
                        if (v[i][k] != 'J' && v[j][k] != 'J')
                            t.push_back('J');
                        if (v[i][k] != 'O' && v[j][k] != 'O')
                            t.push_back('O');
                        if (v[i][k] != 'I' && v[j][k] != 'I')
                            t.push_back('I');
                    }
                }
                v.emplace_back(t);
            }
        sort(v.begin(), v.end());
        v.resize(unique(v.begin(), v.end()) - v.begin());
    }
}

int N, Q;
const ll base[2] = {7, 11}, mod[2] = {1234567891, 1611495397};
ll p[2000005][2];

pll operator+(pll p1, pll p2)
{
    return pll((p1.F + p2.F) % mod[0], (p1.S + p2.S) % mod[1]);
}

struct sumSeg
{
    pll seg[800005];
    int lazy[800005];

    pll getval(int i, int L, int R)
    {
        if (lazy[i])
            return pll((p[R][0] - p[L - 1][0] + mod[0]) * lazy[i] % mod[0],
                       (p[R][1] - p[L - 1][1] + mod[1]) * lazy[i] % mod[1]);
        else
            return seg[i];
    }

    void modify(int mL, int mR, int val, int i = 1, int L = 1, int R = N)
    {

        if (R < mL || mR < L)
            return;
        else if (mL <= L && R <= mR)
        {
            lazy[i] = val;
        }
        else
        {
            int mid = (L + R) / 2;
            if (lazy[i])
                lazy[i << 1] = lazy[i << 1 | 1] = lazy[i];
            lazy[i] = 0;
            modify(mL, mR, val, i << 1, L, mid);
            modify(mL, mR, val, i << 1 | 1, mid + 1, R);
            seg[i] = getval(i << 1, L, mid) + getval(i << 1 | 1, mid + 1, R);
        }
    }
} seg;

int JOI(char c)
{
    return (c == 'J' ? 1 : (c == 'O' ? 2 : 3));
}

map<pll, bool> mp;

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

    cin >> N;
    p[0][0] = p[0][1] = 1;
    for (int i = 1; i <= N; i++)
        p[i][0] = p[i - 1][0] * base[0] % mod[0],
        p[i][1] = p[i - 1][1] * base[1] % mod[1];

    cin >> v[0] >> v[1] >> v[2];
    prod();
    for (string s : v)
    {
        pll h = pll(0, 0);
        for (int i = 0; i < N; i++)
            h = h + pll(JOI(s[i]) * p[i + 1][0], JOI(s[i]) * p[i + 1][1]);
        mp[h] = 1;
    }

    for (int i = 1; i <= N; i++)
        p[i][0] = (p[i - 1][0] + p[i][0]) % mod[0],
        p[i][1] = (p[i - 1][1] + p[i][1]) % mod[1];

    cin >> Q;

    string s;
    cin >> s;
    for (int i = 0; i < N; i++)
        seg.modify(i + 1, i + 1, JOI(s[i]));

    cout << ((mp.count(seg.getval(1, 1, N))) ? "Yes\n" : "No\n");

    for (int i = 1; i <= Q; i++)
    {
        int L, R;
        char c;
        cin >> L >> R >> c;
        seg.modify(L, R, JOI(c));
        cout << ((mp.count(seg.getval(1, 1, N))) ? "Yes\n" : "No\n");
    }
}

/*
JJJOJJIOOOIOOJIIIJIIOJJOOII
JJOJJIJOOIOOJOIIJIIOIOIJIOJ
JOJJIJJOIOOJOOIJIIOIIIOIJJO
*/

Compilation message

Main.cpp: In function 'void prod()':
Main.cpp:21:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |                 for (int k = 0; k < v[i].size(); k++)
      |                                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 73 ms 14924 KB Output is correct
2 Correct 79 ms 14924 KB Output is correct
3 Correct 82 ms 14828 KB Output is correct
4 Correct 67 ms 14812 KB Output is correct
5 Correct 68 ms 14796 KB Output is correct
6 Correct 73 ms 14868 KB Output is correct
7 Correct 69 ms 15036 KB Output is correct
8 Correct 76 ms 14956 KB Output is correct
9 Correct 73 ms 14940 KB Output is correct
10 Correct 75 ms 14960 KB Output is correct
11 Correct 76 ms 15052 KB Output is correct
12 Correct 77 ms 14992 KB Output is correct
13 Correct 81 ms 14976 KB Output is correct
14 Correct 73 ms 14884 KB Output is correct
15 Correct 72 ms 14924 KB Output is correct
16 Correct 74 ms 14952 KB Output is correct
17 Correct 73 ms 14916 KB Output is correct
18 Correct 79 ms 14908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 14924 KB Output is correct
2 Correct 79 ms 14924 KB Output is correct
3 Correct 82 ms 14828 KB Output is correct
4 Correct 67 ms 14812 KB Output is correct
5 Correct 68 ms 14796 KB Output is correct
6 Correct 73 ms 14868 KB Output is correct
7 Correct 69 ms 15036 KB Output is correct
8 Correct 76 ms 14956 KB Output is correct
9 Correct 73 ms 14940 KB Output is correct
10 Correct 75 ms 14960 KB Output is correct
11 Correct 76 ms 15052 KB Output is correct
12 Correct 77 ms 14992 KB Output is correct
13 Correct 81 ms 14976 KB Output is correct
14 Correct 73 ms 14884 KB Output is correct
15 Correct 72 ms 14924 KB Output is correct
16 Correct 74 ms 14952 KB Output is correct
17 Correct 73 ms 14916 KB Output is correct
18 Correct 79 ms 14908 KB Output is correct
19 Correct 328 ms 21784 KB Output is correct
20 Correct 291 ms 21736 KB Output is correct
21 Correct 227 ms 21420 KB Output is correct
22 Correct 235 ms 21192 KB Output is correct
23 Correct 120 ms 16088 KB Output is correct
24 Correct 119 ms 16196 KB Output is correct
25 Correct 248 ms 21732 KB Output is correct
26 Correct 260 ms 21732 KB Output is correct
27 Correct 282 ms 21748 KB Output is correct
28 Correct 291 ms 21708 KB Output is correct
29 Correct 251 ms 21664 KB Output is correct
30 Correct 139 ms 16084 KB Output is correct
31 Correct 258 ms 21780 KB Output is correct
32 Correct 248 ms 21332 KB Output is correct
33 Correct 134 ms 16264 KB Output is correct
34 Correct 268 ms 21528 KB Output is correct
35 Correct 243 ms 20432 KB Output is correct
36 Correct 119 ms 15808 KB Output is correct
37 Correct 116 ms 15812 KB Output is correct
38 Correct 272 ms 20952 KB Output is correct
39 Correct 185 ms 20760 KB Output is correct
40 Correct 207 ms 18424 KB Output is correct
41 Correct 392 ms 20860 KB Output is correct
42 Correct 121 ms 20904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 14924 KB Output is correct
2 Correct 79 ms 14924 KB Output is correct
3 Correct 82 ms 14828 KB Output is correct
4 Correct 67 ms 14812 KB Output is correct
5 Correct 68 ms 14796 KB Output is correct
6 Correct 73 ms 14868 KB Output is correct
7 Correct 69 ms 15036 KB Output is correct
8 Correct 76 ms 14956 KB Output is correct
9 Correct 73 ms 14940 KB Output is correct
10 Correct 75 ms 14960 KB Output is correct
11 Correct 76 ms 15052 KB Output is correct
12 Correct 77 ms 14992 KB Output is correct
13 Correct 81 ms 14976 KB Output is correct
14 Correct 73 ms 14884 KB Output is correct
15 Correct 72 ms 14924 KB Output is correct
16 Correct 74 ms 14952 KB Output is correct
17 Correct 73 ms 14916 KB Output is correct
18 Correct 79 ms 14908 KB Output is correct
19 Correct 99 ms 14708 KB Output is correct
20 Correct 91 ms 14744 KB Output is correct
21 Correct 95 ms 14708 KB Output is correct
22 Correct 73 ms 14616 KB Output is correct
23 Correct 78 ms 14736 KB Output is correct
24 Correct 73 ms 14648 KB Output is correct
25 Correct 79 ms 14668 KB Output is correct
26 Correct 69 ms 14668 KB Output is correct
27 Correct 74 ms 14668 KB Output is correct
28 Correct 69 ms 14568 KB Output is correct
29 Correct 80 ms 14780 KB Output is correct
30 Correct 67 ms 14700 KB Output is correct
31 Correct 75 ms 14716 KB Output is correct
32 Correct 79 ms 14668 KB Output is correct
33 Correct 76 ms 14632 KB Output is correct
34 Correct 70 ms 14596 KB Output is correct
35 Correct 81 ms 14724 KB Output is correct
36 Correct 81 ms 14668 KB Output is correct
37 Correct 83 ms 14672 KB Output is correct
38 Correct 81 ms 14808 KB Output is correct
39 Correct 82 ms 14828 KB Output is correct
40 Correct 78 ms 14732 KB Output is correct
41 Correct 79 ms 14704 KB Output is correct
42 Correct 79 ms 14660 KB Output is correct
43 Correct 72 ms 14668 KB Output is correct
44 Correct 79 ms 14668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 14924 KB Output is correct
2 Correct 79 ms 14924 KB Output is correct
3 Correct 82 ms 14828 KB Output is correct
4 Correct 67 ms 14812 KB Output is correct
5 Correct 68 ms 14796 KB Output is correct
6 Correct 73 ms 14868 KB Output is correct
7 Correct 69 ms 15036 KB Output is correct
8 Correct 76 ms 14956 KB Output is correct
9 Correct 73 ms 14940 KB Output is correct
10 Correct 75 ms 14960 KB Output is correct
11 Correct 76 ms 15052 KB Output is correct
12 Correct 77 ms 14992 KB Output is correct
13 Correct 81 ms 14976 KB Output is correct
14 Correct 73 ms 14884 KB Output is correct
15 Correct 72 ms 14924 KB Output is correct
16 Correct 74 ms 14952 KB Output is correct
17 Correct 73 ms 14916 KB Output is correct
18 Correct 79 ms 14908 KB Output is correct
19 Correct 328 ms 21784 KB Output is correct
20 Correct 291 ms 21736 KB Output is correct
21 Correct 227 ms 21420 KB Output is correct
22 Correct 235 ms 21192 KB Output is correct
23 Correct 120 ms 16088 KB Output is correct
24 Correct 119 ms 16196 KB Output is correct
25 Correct 248 ms 21732 KB Output is correct
26 Correct 260 ms 21732 KB Output is correct
27 Correct 282 ms 21748 KB Output is correct
28 Correct 291 ms 21708 KB Output is correct
29 Correct 251 ms 21664 KB Output is correct
30 Correct 139 ms 16084 KB Output is correct
31 Correct 258 ms 21780 KB Output is correct
32 Correct 248 ms 21332 KB Output is correct
33 Correct 134 ms 16264 KB Output is correct
34 Correct 268 ms 21528 KB Output is correct
35 Correct 243 ms 20432 KB Output is correct
36 Correct 119 ms 15808 KB Output is correct
37 Correct 116 ms 15812 KB Output is correct
38 Correct 272 ms 20952 KB Output is correct
39 Correct 185 ms 20760 KB Output is correct
40 Correct 207 ms 18424 KB Output is correct
41 Correct 392 ms 20860 KB Output is correct
42 Correct 121 ms 20904 KB Output is correct
43 Correct 99 ms 14708 KB Output is correct
44 Correct 91 ms 14744 KB Output is correct
45 Correct 95 ms 14708 KB Output is correct
46 Correct 73 ms 14616 KB Output is correct
47 Correct 78 ms 14736 KB Output is correct
48 Correct 73 ms 14648 KB Output is correct
49 Correct 79 ms 14668 KB Output is correct
50 Correct 69 ms 14668 KB Output is correct
51 Correct 74 ms 14668 KB Output is correct
52 Correct 69 ms 14568 KB Output is correct
53 Correct 80 ms 14780 KB Output is correct
54 Correct 67 ms 14700 KB Output is correct
55 Correct 75 ms 14716 KB Output is correct
56 Correct 79 ms 14668 KB Output is correct
57 Correct 76 ms 14632 KB Output is correct
58 Correct 70 ms 14596 KB Output is correct
59 Correct 81 ms 14724 KB Output is correct
60 Correct 81 ms 14668 KB Output is correct
61 Correct 83 ms 14672 KB Output is correct
62 Correct 81 ms 14808 KB Output is correct
63 Correct 82 ms 14828 KB Output is correct
64 Correct 78 ms 14732 KB Output is correct
65 Correct 79 ms 14704 KB Output is correct
66 Correct 79 ms 14660 KB Output is correct
67 Correct 72 ms 14668 KB Output is correct
68 Correct 79 ms 14668 KB Output is correct
69 Correct 940 ms 34712 KB Output is correct
70 Correct 1020 ms 38060 KB Output is correct
71 Correct 119 ms 15216 KB Output is correct
72 Correct 120 ms 15176 KB Output is correct
73 Correct 130 ms 15136 KB Output is correct
74 Correct 300 ms 20388 KB Output is correct
75 Correct 124 ms 15048 KB Output is correct
76 Correct 342 ms 21148 KB Output is correct
77 Correct 315 ms 20292 KB Output is correct
78 Correct 128 ms 15128 KB Output is correct
79 Correct 127 ms 15080 KB Output is correct
80 Correct 736 ms 32164 KB Output is correct
81 Correct 154 ms 15948 KB Output is correct
82 Correct 1002 ms 38020 KB Output is correct
83 Correct 952 ms 36748 KB Output is correct
84 Correct 155 ms 15948 KB Output is correct
85 Correct 176 ms 15920 KB Output is correct
86 Correct 447 ms 33300 KB Output is correct
87 Correct 556 ms 38084 KB Output is correct
88 Correct 149 ms 15964 KB Output is correct
89 Correct 506 ms 35836 KB Output is correct
90 Correct 579 ms 38096 KB Output is correct
91 Correct 148 ms 15876 KB Output is correct
92 Correct 755 ms 32820 KB Output is correct
93 Correct 154 ms 15912 KB Output is correct
94 Correct 163 ms 15916 KB Output is correct
95 Correct 162 ms 15956 KB Output is correct
96 Correct 251 ms 20716 KB Output is correct
97 Correct 442 ms 38140 KB Output is correct
98 Correct 657 ms 30068 KB Output is correct
99 Correct 998 ms 38292 KB Output is correct
100 Correct 771 ms 38296 KB Output is correct