Submission #421864

# Submission time Handle Problem Language Result Execution time Memory
421864 2021-06-09T13:06:13 Z schse Crossing (JOI21_crossing) C++17
100 / 100
6388 ms 73296 KB
#include <bits/stdc++.h>
#pragma GCC optimize "O3"
using namespace std;

// die lösung ist etwas langsam, kann je nach judege alles lösen

string combine(const string &a, const string &b)
{
    string c = a;
    for (int i = 0; i < a.size(); i++)
    {
        if (a[i] == b[i])
            c[i] = a[i];
        else if (a[i] == 'J')
            c[i] = (b[i] == 'I' ? 'O' : 'I');
        else if (a[i] == 'O')
            c[i] = (b[i] == 'I' ? 'J' : 'I');
        else if (a[i] == 'I')
            c[i] = (b[i] == 'J' ? 'O' : 'J');
    }
    return c;
}

struct treenode
{
    pair<bool, char> target;
    char lazzy = ' ';
    vector<pair<bool, char>> strings; //singelchar, char
    vector<bool> isidentical;
};

pair<bool, char> operator+(const pair<bool, char> &a, const pair<bool, char> &b)
{
    return {a.first && b.first && a.second == b.second, a.second};
}

vector<pair<bool, char>> operator+(const vector<pair<bool, char>> &a, const vector<pair<bool, char>> &b)
{
    vector<pair<bool, char>> c;
    for (int i = 0; i < a.size(); i++)
        c.push_back(a[i] + b[i]);
    return c;
}

vector<bool> operator&&(const vector<bool> &a, const vector<bool> &b)
{
    vector<bool> c;
    for (int i = 0; i < a.size(); i++)
        c.push_back(a[i] && b[i]);
    return c;
}

treenode operator+(treenode a, treenode b)
{
    return {
        a.target + b.target,
        ' ',
        a.strings + b.strings,
        a.isidentical && b.isidentical,
    };
}

struct setgtree
{
    vector<treenode> tree = vector<treenode>(524288 + 5);

    void pushdown(int i)
    {
        if (tree[i].lazzy == ' ')
            return;
        tree[i * 2].lazzy = tree[i * 2 + 1].lazzy = tree[i].lazzy;
        tree[i * 2].target = tree[i * 2 + 1].target = {true, tree[i].lazzy};

        for (int e = 0; e < tree[i * 2].strings.size(); e++)
            tree[i * 2].isidentical[e] = tree[i * 2].strings[e] == tree[i * 2].target;
        for (int e = 0; e < tree[i * 2 + 1].strings.size(); e++)
            tree[i * 2 + 1].isidentical[e] = tree[i * 2 + 1].strings[e] == tree[i * 2 + 1].target;

        tree[i].lazzy = ' ';
    }

    treenode init(int index, int b, int e, const string &T, const vector<string> &S)
    {
        if (e - b == 1)
        {
            tree[index].target = {true, T[b]};
            for (int i = 0; i < S.size(); i++)
            {
                tree[index].strings.push_back({true, S[i][b]});
                tree[index].isidentical.push_back(S[i][b] == T[b]);
            }
            return tree[index];
        }
        init(index * 2, b, (e + b) / 2, T, S);
        init(index * 2 + 1, (b + e) / 2, e, T, S);
        tree[index] = tree[index * 2] + tree[index * 2 + 1];
        return tree[index];
    }

    treenode upd(int index, int b, int e, int l, int r, char c)
    {
        if (l <= b && e <= r)
        {
            tree[index].target = {true, c};
            for (int i = 0; i < tree[index].strings.size(); i++)
                tree[index].isidentical[i] = tree[index].strings[i] == tree[index].target;
            tree[index].lazzy = c;
            return tree[index];
        }
        if (r <= b || e <= l)
            return tree[index];
        pushdown(index);
        upd(index * 2, b, (e + b) / 2, l, r, c);
        upd(index * 2 + 1, (b + e) / 2, e, l, r, c);
        tree[index] = tree[index * 2] + tree[index * 2 + 1];
        return tree[index];
    }
} tree;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    set<string> str;
    vector<string> vs;
    string s;
    cin >> N >> s;
    if (str.insert(s).second)
        vs.push_back(s);
    cin >> s;
    if (str.insert(s).second)
        vs.push_back(s);
    cin >> s >> Q;
    if (str.insert(s).second)
        vs.push_back(s);
    for (int i = 0; i < vs.size(); i++)
    {
        for (int e = 0; e < i; e++)
        {
            if (e != i && str.insert(combine(vs[i], vs[e])).second)
                vs.push_back(combine(vs[i], vs[e]));
        }
    }

    string T;
    cin >> T;

    tree.init(1, 0, N, T, vs);
    bool b = false;
    for (const bool &s : tree.tree[1].isidentical)
        b |= s;
    if (b)
        cout << "Yes\n";
    else
        cout << "No\n";
    for (int i = 0, b, e; i < Q; i++)
    {
        char c;
        cin >> b >> e >> c;
        tree.upd(1, 0, N, b - 1, e, c);
        bool x = false;
        for (const bool &s : tree.tree[1].isidentical)
            x |= s;
        if (x)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}

Compilation message

Main.cpp: In function 'std::string combine(const string&, const string&)':
Main.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'std::vector<std::pair<bool, char> > operator+(const std::vector<std::pair<bool, char> >&, const std::vector<std::pair<bool, char> >&)':
Main.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<bool, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'std::vector<bool> operator&&(const std::vector<bool>&, const std::vector<bool>&)':
Main.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < a.size(); i++)
      |                     ~~^~~~~~~~~~
Main.cpp: In member function 'void setgtree::pushdown(int)':
Main.cpp:74:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<bool, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for (int e = 0; e < tree[i * 2].strings.size(); e++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:76:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<bool, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for (int e = 0; e < tree[i * 2 + 1].strings.size(); e++)
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In member function 'treenode setgtree::init(int, int, int, const string&, const std::vector<std::__cxx11::basic_string<char> >&)':
Main.cpp:87:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |             for (int i = 0; i < S.size(); i++)
      |                             ~~^~~~~~~~~~
Main.cpp: In member function 'treenode setgtree::upd(int, int, int, int, int, char)':
Main.cpp:105:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<bool, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |             for (int i = 0; i < tree[index].strings.size(); i++)
      |                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:138:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  138 |     for (int i = 0; i < vs.size(); i++)
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 619 ms 37812 KB Output is correct
2 Correct 685 ms 37940 KB Output is correct
3 Correct 785 ms 37864 KB Output is correct
4 Correct 579 ms 37792 KB Output is correct
5 Correct 573 ms 37800 KB Output is correct
6 Correct 583 ms 37752 KB Output is correct
7 Correct 583 ms 37788 KB Output is correct
8 Correct 631 ms 37840 KB Output is correct
9 Correct 606 ms 37836 KB Output is correct
10 Correct 614 ms 37816 KB Output is correct
11 Correct 621 ms 37796 KB Output is correct
12 Correct 611 ms 37940 KB Output is correct
13 Correct 648 ms 37924 KB Output is correct
14 Correct 610 ms 37852 KB Output is correct
15 Correct 609 ms 37776 KB Output is correct
16 Correct 644 ms 37796 KB Output is correct
17 Correct 607 ms 37864 KB Output is correct
18 Correct 640 ms 37880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 37812 KB Output is correct
2 Correct 685 ms 37940 KB Output is correct
3 Correct 785 ms 37864 KB Output is correct
4 Correct 579 ms 37792 KB Output is correct
5 Correct 573 ms 37800 KB Output is correct
6 Correct 583 ms 37752 KB Output is correct
7 Correct 583 ms 37788 KB Output is correct
8 Correct 631 ms 37840 KB Output is correct
9 Correct 606 ms 37836 KB Output is correct
10 Correct 614 ms 37816 KB Output is correct
11 Correct 621 ms 37796 KB Output is correct
12 Correct 611 ms 37940 KB Output is correct
13 Correct 648 ms 37924 KB Output is correct
14 Correct 610 ms 37852 KB Output is correct
15 Correct 609 ms 37776 KB Output is correct
16 Correct 644 ms 37796 KB Output is correct
17 Correct 607 ms 37864 KB Output is correct
18 Correct 640 ms 37880 KB Output is correct
19 Correct 2851 ms 63708 KB Output is correct
20 Correct 2979 ms 63588 KB Output is correct
21 Correct 2296 ms 62092 KB Output is correct
22 Correct 2013 ms 59592 KB Output is correct
23 Correct 1317 ms 39100 KB Output is correct
24 Correct 1296 ms 39104 KB Output is correct
25 Correct 2208 ms 63656 KB Output is correct
26 Correct 2225 ms 63624 KB Output is correct
27 Correct 2486 ms 63600 KB Output is correct
28 Correct 2483 ms 63796 KB Output is correct
29 Correct 2411 ms 63044 KB Output is correct
30 Correct 1363 ms 39296 KB Output is correct
31 Correct 2475 ms 63784 KB Output is correct
32 Correct 2376 ms 61300 KB Output is correct
33 Correct 1241 ms 39188 KB Output is correct
34 Correct 2418 ms 64044 KB Output is correct
35 Correct 1843 ms 57116 KB Output is correct
36 Correct 1243 ms 39128 KB Output is correct
37 Correct 1248 ms 39100 KB Output is correct
38 Correct 2265 ms 63768 KB Output is correct
39 Correct 1577 ms 63732 KB Output is correct
40 Correct 1953 ms 54820 KB Output is correct
41 Correct 3065 ms 63912 KB Output is correct
42 Correct 203 ms 63760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 37812 KB Output is correct
2 Correct 685 ms 37940 KB Output is correct
3 Correct 785 ms 37864 KB Output is correct
4 Correct 579 ms 37792 KB Output is correct
5 Correct 573 ms 37800 KB Output is correct
6 Correct 583 ms 37752 KB Output is correct
7 Correct 583 ms 37788 KB Output is correct
8 Correct 631 ms 37840 KB Output is correct
9 Correct 606 ms 37836 KB Output is correct
10 Correct 614 ms 37816 KB Output is correct
11 Correct 621 ms 37796 KB Output is correct
12 Correct 611 ms 37940 KB Output is correct
13 Correct 648 ms 37924 KB Output is correct
14 Correct 610 ms 37852 KB Output is correct
15 Correct 609 ms 37776 KB Output is correct
16 Correct 644 ms 37796 KB Output is correct
17 Correct 607 ms 37864 KB Output is correct
18 Correct 640 ms 37880 KB Output is correct
19 Correct 1318 ms 37952 KB Output is correct
20 Correct 1484 ms 37904 KB Output is correct
21 Correct 763 ms 37864 KB Output is correct
22 Correct 650 ms 37872 KB Output is correct
23 Correct 740 ms 37828 KB Output is correct
24 Correct 752 ms 37868 KB Output is correct
25 Correct 778 ms 37912 KB Output is correct
26 Correct 682 ms 37760 KB Output is correct
27 Correct 775 ms 37780 KB Output is correct
28 Correct 676 ms 37752 KB Output is correct
29 Correct 774 ms 37800 KB Output is correct
30 Correct 638 ms 37776 KB Output is correct
31 Correct 1170 ms 37924 KB Output is correct
32 Correct 1141 ms 37984 KB Output is correct
33 Correct 1156 ms 37804 KB Output is correct
34 Correct 1036 ms 37844 KB Output is correct
35 Correct 1178 ms 37792 KB Output is correct
36 Correct 1219 ms 37804 KB Output is correct
37 Correct 1212 ms 37824 KB Output is correct
38 Correct 1222 ms 37832 KB Output is correct
39 Correct 1230 ms 37808 KB Output is correct
40 Correct 1266 ms 37912 KB Output is correct
41 Correct 1251 ms 37796 KB Output is correct
42 Correct 1243 ms 37852 KB Output is correct
43 Correct 1181 ms 37840 KB Output is correct
44 Correct 1331 ms 37852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 37812 KB Output is correct
2 Correct 685 ms 37940 KB Output is correct
3 Correct 785 ms 37864 KB Output is correct
4 Correct 579 ms 37792 KB Output is correct
5 Correct 573 ms 37800 KB Output is correct
6 Correct 583 ms 37752 KB Output is correct
7 Correct 583 ms 37788 KB Output is correct
8 Correct 631 ms 37840 KB Output is correct
9 Correct 606 ms 37836 KB Output is correct
10 Correct 614 ms 37816 KB Output is correct
11 Correct 621 ms 37796 KB Output is correct
12 Correct 611 ms 37940 KB Output is correct
13 Correct 648 ms 37924 KB Output is correct
14 Correct 610 ms 37852 KB Output is correct
15 Correct 609 ms 37776 KB Output is correct
16 Correct 644 ms 37796 KB Output is correct
17 Correct 607 ms 37864 KB Output is correct
18 Correct 640 ms 37880 KB Output is correct
19 Correct 2851 ms 63708 KB Output is correct
20 Correct 2979 ms 63588 KB Output is correct
21 Correct 2296 ms 62092 KB Output is correct
22 Correct 2013 ms 59592 KB Output is correct
23 Correct 1317 ms 39100 KB Output is correct
24 Correct 1296 ms 39104 KB Output is correct
25 Correct 2208 ms 63656 KB Output is correct
26 Correct 2225 ms 63624 KB Output is correct
27 Correct 2486 ms 63600 KB Output is correct
28 Correct 2483 ms 63796 KB Output is correct
29 Correct 2411 ms 63044 KB Output is correct
30 Correct 1363 ms 39296 KB Output is correct
31 Correct 2475 ms 63784 KB Output is correct
32 Correct 2376 ms 61300 KB Output is correct
33 Correct 1241 ms 39188 KB Output is correct
34 Correct 2418 ms 64044 KB Output is correct
35 Correct 1843 ms 57116 KB Output is correct
36 Correct 1243 ms 39128 KB Output is correct
37 Correct 1248 ms 39100 KB Output is correct
38 Correct 2265 ms 63768 KB Output is correct
39 Correct 1577 ms 63732 KB Output is correct
40 Correct 1953 ms 54820 KB Output is correct
41 Correct 3065 ms 63912 KB Output is correct
42 Correct 203 ms 63760 KB Output is correct
43 Correct 1318 ms 37952 KB Output is correct
44 Correct 1484 ms 37904 KB Output is correct
45 Correct 763 ms 37864 KB Output is correct
46 Correct 650 ms 37872 KB Output is correct
47 Correct 740 ms 37828 KB Output is correct
48 Correct 752 ms 37868 KB Output is correct
49 Correct 778 ms 37912 KB Output is correct
50 Correct 682 ms 37760 KB Output is correct
51 Correct 775 ms 37780 KB Output is correct
52 Correct 676 ms 37752 KB Output is correct
53 Correct 774 ms 37800 KB Output is correct
54 Correct 638 ms 37776 KB Output is correct
55 Correct 1170 ms 37924 KB Output is correct
56 Correct 1141 ms 37984 KB Output is correct
57 Correct 1156 ms 37804 KB Output is correct
58 Correct 1036 ms 37844 KB Output is correct
59 Correct 1178 ms 37792 KB Output is correct
60 Correct 1219 ms 37804 KB Output is correct
61 Correct 1212 ms 37824 KB Output is correct
62 Correct 1222 ms 37832 KB Output is correct
63 Correct 1230 ms 37808 KB Output is correct
64 Correct 1266 ms 37912 KB Output is correct
65 Correct 1251 ms 37796 KB Output is correct
66 Correct 1243 ms 37852 KB Output is correct
67 Correct 1181 ms 37840 KB Output is correct
68 Correct 1331 ms 37852 KB Output is correct
69 Correct 5391 ms 67288 KB Output is correct
70 Correct 6202 ms 73060 KB Output is correct
71 Correct 1632 ms 39204 KB Output is correct
72 Correct 1672 ms 39216 KB Output is correct
73 Correct 1606 ms 39160 KB Output is correct
74 Correct 2419 ms 60036 KB Output is correct
75 Correct 1852 ms 39172 KB Output is correct
76 Correct 2875 ms 64596 KB Output is correct
77 Correct 2619 ms 59956 KB Output is correct
78 Correct 1578 ms 39256 KB Output is correct
79 Correct 1695 ms 39172 KB Output is correct
80 Correct 3671 ms 62816 KB Output is correct
81 Correct 2457 ms 39740 KB Output is correct
82 Correct 4318 ms 72980 KB Output is correct
83 Correct 3939 ms 70824 KB Output is correct
84 Correct 2630 ms 39628 KB Output is correct
85 Correct 2518 ms 39608 KB Output is correct
86 Correct 4649 ms 64692 KB Output is correct
87 Correct 5123 ms 73092 KB Output is correct
88 Correct 2666 ms 39668 KB Output is correct
89 Correct 4740 ms 68852 KB Output is correct
90 Correct 4799 ms 73120 KB Output is correct
91 Correct 2646 ms 39620 KB Output is correct
92 Correct 3885 ms 64160 KB Output is correct
93 Correct 2640 ms 39548 KB Output is correct
94 Correct 2452 ms 39620 KB Output is correct
95 Correct 2607 ms 39628 KB Output is correct
96 Correct 2452 ms 63612 KB Output is correct
97 Correct 3274 ms 73104 KB Output is correct
98 Correct 3922 ms 61012 KB Output is correct
99 Correct 6388 ms 73296 KB Output is correct
100 Correct 427 ms 73204 KB Output is correct