답안 #643922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643922 2022-09-23T08:51:03 Z boris_mihov Crossing (JOI21_crossing) C++17
49 / 100
7000 ms 190788 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <set>

typedef long long llong;
const int MAXN = 200000 + 10;

int n, q;
int code[256];
std::string s[3], t;
std::vector <std::string> all;
std::set <std::string> allS;
struct Node
{
    std::vector <bool> equalTo;
    std::vector <bool> allLetters[3];
    int lazy;

    Node()
    {
        lazy = -1;
        equalTo.resize(all.size());
        allLetters[0].resize(all.size());
        allLetters[1].resize(all.size());
        allLetters[2].resize(all.size());
        std::fill(equalTo.begin(), equalTo.end(), false);
        std::fill(allLetters[0].begin(), allLetters[0].end(), false);
        std::fill(allLetters[1].begin(), allLetters[1].end(), false);
        std::fill(allLetters[2].begin(), allLetters[2].end(), false);
    }
    
} tree[4*MAXN];

std::string xorOfStrings(const std::string &a, const std::string &b)
{
    if (a.empty()) return b;
   
    int letterXor = 'J' ^ 'O' ^ 'I';
    std::string res; res.reserve(n);
    for (int i = 0 ; i <= n-1 ; ++i)
    {
        if (a[i] == b[i]) res += a[i];
        else res += letterXor ^ a[i] ^ b[i];
    }

    return res;
}

Node combine(Node left, Node right)
{
    Node res;
    for (int i = 0 ; i < all.size() ; ++i)
    {
        res.equalTo[i] = left.equalTo[i] && right.equalTo[i];
        for (int j = 0 ; j < 3 ; ++j)
        {
            res.allLetters[j][i] = left.allLetters[j][i] && right.allLetters[j][i];
        }
    }

    return res;
}

void build(int l, int r, int node)
{
    tree[node] = Node();
    if (l == r)
    {
        for (int i = 0 ; i < all.size() ; ++i)
        {
            tree[node].allLetters[code[all[i][l]]][i] = true;
            if (all[i][l] == t[l]) tree[node].equalTo[i] = true;
        }

        return;
    }

    int mid = (l + r) / 2;
    build(l, mid, 2*node);
    build(mid + 1, r, 2*node + 1);
    tree[node] = combine(tree[2*node], tree[2*node + 1]);
}

void push(int node, int l, int r)
{
    if (tree[node].lazy == -1) return;

    std::fill(tree[node].equalTo.begin(), tree[node].equalTo.end(), false);
    for (int i = 0 ; i < all.size() ; ++i)
    {
        if (tree[node].allLetters[tree[node].lazy][i])
        {
            tree[node].equalTo[i] = true;
        }
    }

    if (l < r)
    {
        tree[2*node].lazy = tree[node].lazy;
        tree[2*node + 1].lazy = tree[node].lazy;
    }

    tree[node].lazy = -1;
}

void update(int l, int r, int node, int queryL, int queryR, int queryVal)
{
    push(node, l, r);
    if (queryR <  l || r  < queryL) return;
    if (queryL <= l && r <= queryR)
    {
        tree[node].lazy = queryVal;
        push(node, l, r);
        return;
    }

    int mid = (l + r) / 2;
    update(l, mid, 2*node, queryL, queryR, queryVal);
    update(mid + 1, r, 2*node + 1, queryL, queryR, queryVal);
    tree[node] = combine(tree[2*node], tree[2*node + 1]);
}

void solve()
{
    code['J'] = 0;
    code['O'] = 1;
    code['I'] = 2;
    all.push_back(s[0]);
    all.push_back(s[1]);
    all.push_back(s[2]);
    allS.insert(s[0]);
    allS.insert(s[1]);
    allS.insert(s[2]);

    for (std::string s1 : allS)
    {
        for (std::string s2 : allS)
        {
            std::string curr = xorOfStrings(s1, s2);
            if (!allS.count(curr))
            {
                allS.insert(curr);
                all.push_back(curr);
            }
        }
    }

    int l, r;
    char qType;
    build(0, n-1, 1);
    bool can = false;
    for (int i = 0 ; i < all.size() ; ++i)
    {
        can |= tree[1].equalTo[i];
    }

    if (can) std::cout << "Yes\n";
    else std::cout << "No\n";
    for (int i = 1 ; i <= q ; ++i)
    {
        std::cin >> l >> r >> qType; --l; --r;
        update(0, n-1, 1, l, r, code[qType]);
        bool can = false;
        for (int i = 0 ; i < all.size() ; ++i)
        {
            can |= tree[1].equalTo[i];
        }

        if (can) std::cout << "Yes\n";
        else std::cout << "No\n";
    }
}

void read()
{
    std::cin >> n;
    std::cin >> s[0];
    std::cin >> s[1];
    std::cin >> s[2];
    std::cin >> q;
    std::cin >> t;
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}

Compilation message

Main.cpp: In function 'Node combine(Node, Node)':
Main.cpp:54:24: 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]
   54 |     for (int i = 0 ; i < all.size() ; ++i)
      |                      ~~^~~~~~~~~~~~
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:71:28: 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]
   71 |         for (int i = 0 ; i < all.size() ; ++i)
      |                          ~~^~~~~~~~~~~~
Main.cpp:73:49: warning: array subscript has type 'char' [-Wchar-subscripts]
   73 |             tree[node].allLetters[code[all[i][l]]][i] = true;
      |                                                 ^
Main.cpp: In function 'void push(int, int, int)':
Main.cpp:91:24: 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]
   91 |     for (int i = 0 ; i < all.size() ; ++i)
      |                      ~~^~~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:154:24: 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]
  154 |     for (int i = 0 ; i < all.size() ; ++i)
      |                      ~~^~~~~~~~~~~~
Main.cpp:164:38: warning: array subscript has type 'char' [-Wchar-subscripts]
  164 |         update(0, n-1, 1, l, r, code[qType]);
      |                                      ^~~~~
Main.cpp:166:28: 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]
  166 |         for (int i = 0 ; i < all.size() ; ++i)
      |                          ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 133752 KB Output is correct
2 Correct 971 ms 134032 KB Output is correct
3 Correct 1060 ms 133880 KB Output is correct
4 Correct 773 ms 133856 KB Output is correct
5 Correct 747 ms 133844 KB Output is correct
6 Correct 778 ms 133836 KB Output is correct
7 Correct 775 ms 134032 KB Output is correct
8 Correct 859 ms 133888 KB Output is correct
9 Correct 845 ms 133876 KB Output is correct
10 Correct 837 ms 134104 KB Output is correct
11 Correct 835 ms 134044 KB Output is correct
12 Correct 880 ms 134068 KB Output is correct
13 Correct 865 ms 133968 KB Output is correct
14 Correct 813 ms 133964 KB Output is correct
15 Correct 829 ms 133964 KB Output is correct
16 Correct 812 ms 133920 KB Output is correct
17 Correct 851 ms 134024 KB Output is correct
18 Correct 891 ms 133972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 133752 KB Output is correct
2 Correct 971 ms 134032 KB Output is correct
3 Correct 1060 ms 133880 KB Output is correct
4 Correct 773 ms 133856 KB Output is correct
5 Correct 747 ms 133844 KB Output is correct
6 Correct 778 ms 133836 KB Output is correct
7 Correct 775 ms 134032 KB Output is correct
8 Correct 859 ms 133888 KB Output is correct
9 Correct 845 ms 133876 KB Output is correct
10 Correct 837 ms 134104 KB Output is correct
11 Correct 835 ms 134044 KB Output is correct
12 Correct 880 ms 134068 KB Output is correct
13 Correct 865 ms 133968 KB Output is correct
14 Correct 813 ms 133964 KB Output is correct
15 Correct 829 ms 133964 KB Output is correct
16 Correct 812 ms 133920 KB Output is correct
17 Correct 851 ms 134024 KB Output is correct
18 Correct 891 ms 133972 KB Output is correct
19 Correct 4660 ms 187940 KB Output is correct
20 Correct 4261 ms 187896 KB Output is correct
21 Correct 3629 ms 184472 KB Output is correct
22 Correct 3179 ms 179320 KB Output is correct
23 Correct 1802 ms 137476 KB Output is correct
24 Correct 1739 ms 137436 KB Output is correct
25 Correct 3618 ms 187912 KB Output is correct
26 Correct 3524 ms 188104 KB Output is correct
27 Correct 3977 ms 187812 KB Output is correct
28 Correct 4161 ms 187804 KB Output is correct
29 Correct 3934 ms 186264 KB Output is correct
30 Correct 1911 ms 137436 KB Output is correct
31 Correct 3963 ms 187864 KB Output is correct
32 Correct 3895 ms 183080 KB Output is correct
33 Correct 1765 ms 137464 KB Output is correct
34 Correct 4075 ms 187840 KB Output is correct
35 Correct 3138 ms 174132 KB Output is correct
36 Correct 1713 ms 137364 KB Output is correct
37 Correct 1773 ms 137316 KB Output is correct
38 Correct 3582 ms 187592 KB Output is correct
39 Correct 2199 ms 187852 KB Output is correct
40 Correct 3527 ms 169632 KB Output is correct
41 Correct 5174 ms 188204 KB Output is correct
42 Correct 370 ms 187188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 133752 KB Output is correct
2 Correct 971 ms 134032 KB Output is correct
3 Correct 1060 ms 133880 KB Output is correct
4 Correct 773 ms 133856 KB Output is correct
5 Correct 747 ms 133844 KB Output is correct
6 Correct 778 ms 133836 KB Output is correct
7 Correct 775 ms 134032 KB Output is correct
8 Correct 859 ms 133888 KB Output is correct
9 Correct 845 ms 133876 KB Output is correct
10 Correct 837 ms 134104 KB Output is correct
11 Correct 835 ms 134044 KB Output is correct
12 Correct 880 ms 134068 KB Output is correct
13 Correct 865 ms 133968 KB Output is correct
14 Correct 813 ms 133964 KB Output is correct
15 Correct 829 ms 133964 KB Output is correct
16 Correct 812 ms 133920 KB Output is correct
17 Correct 851 ms 134024 KB Output is correct
18 Correct 891 ms 133972 KB Output is correct
19 Correct 1210 ms 133908 KB Output is correct
20 Correct 1384 ms 133832 KB Output is correct
21 Correct 859 ms 133916 KB Output is correct
22 Correct 716 ms 133676 KB Output is correct
23 Correct 857 ms 133992 KB Output is correct
24 Correct 814 ms 133832 KB Output is correct
25 Correct 879 ms 133964 KB Output is correct
26 Correct 780 ms 133972 KB Output is correct
27 Correct 804 ms 133880 KB Output is correct
28 Correct 724 ms 133704 KB Output is correct
29 Correct 820 ms 133980 KB Output is correct
30 Correct 701 ms 133812 KB Output is correct
31 Correct 1072 ms 133964 KB Output is correct
32 Correct 1065 ms 133904 KB Output is correct
33 Correct 1101 ms 134176 KB Output is correct
34 Correct 937 ms 133792 KB Output is correct
35 Correct 1066 ms 133960 KB Output is correct
36 Correct 1082 ms 133988 KB Output is correct
37 Correct 1073 ms 134168 KB Output is correct
38 Correct 1064 ms 134152 KB Output is correct
39 Correct 1063 ms 133972 KB Output is correct
40 Correct 1080 ms 134196 KB Output is correct
41 Correct 1067 ms 133980 KB Output is correct
42 Correct 1122 ms 134156 KB Output is correct
43 Correct 1026 ms 133920 KB Output is correct
44 Correct 1082 ms 134124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 834 ms 133752 KB Output is correct
2 Correct 971 ms 134032 KB Output is correct
3 Correct 1060 ms 133880 KB Output is correct
4 Correct 773 ms 133856 KB Output is correct
5 Correct 747 ms 133844 KB Output is correct
6 Correct 778 ms 133836 KB Output is correct
7 Correct 775 ms 134032 KB Output is correct
8 Correct 859 ms 133888 KB Output is correct
9 Correct 845 ms 133876 KB Output is correct
10 Correct 837 ms 134104 KB Output is correct
11 Correct 835 ms 134044 KB Output is correct
12 Correct 880 ms 134068 KB Output is correct
13 Correct 865 ms 133968 KB Output is correct
14 Correct 813 ms 133964 KB Output is correct
15 Correct 829 ms 133964 KB Output is correct
16 Correct 812 ms 133920 KB Output is correct
17 Correct 851 ms 134024 KB Output is correct
18 Correct 891 ms 133972 KB Output is correct
19 Correct 4660 ms 187940 KB Output is correct
20 Correct 4261 ms 187896 KB Output is correct
21 Correct 3629 ms 184472 KB Output is correct
22 Correct 3179 ms 179320 KB Output is correct
23 Correct 1802 ms 137476 KB Output is correct
24 Correct 1739 ms 137436 KB Output is correct
25 Correct 3618 ms 187912 KB Output is correct
26 Correct 3524 ms 188104 KB Output is correct
27 Correct 3977 ms 187812 KB Output is correct
28 Correct 4161 ms 187804 KB Output is correct
29 Correct 3934 ms 186264 KB Output is correct
30 Correct 1911 ms 137436 KB Output is correct
31 Correct 3963 ms 187864 KB Output is correct
32 Correct 3895 ms 183080 KB Output is correct
33 Correct 1765 ms 137464 KB Output is correct
34 Correct 4075 ms 187840 KB Output is correct
35 Correct 3138 ms 174132 KB Output is correct
36 Correct 1713 ms 137364 KB Output is correct
37 Correct 1773 ms 137316 KB Output is correct
38 Correct 3582 ms 187592 KB Output is correct
39 Correct 2199 ms 187852 KB Output is correct
40 Correct 3527 ms 169632 KB Output is correct
41 Correct 5174 ms 188204 KB Output is correct
42 Correct 370 ms 187188 KB Output is correct
43 Correct 1210 ms 133908 KB Output is correct
44 Correct 1384 ms 133832 KB Output is correct
45 Correct 859 ms 133916 KB Output is correct
46 Correct 716 ms 133676 KB Output is correct
47 Correct 857 ms 133992 KB Output is correct
48 Correct 814 ms 133832 KB Output is correct
49 Correct 879 ms 133964 KB Output is correct
50 Correct 780 ms 133972 KB Output is correct
51 Correct 804 ms 133880 KB Output is correct
52 Correct 724 ms 133704 KB Output is correct
53 Correct 820 ms 133980 KB Output is correct
54 Correct 701 ms 133812 KB Output is correct
55 Correct 1072 ms 133964 KB Output is correct
56 Correct 1065 ms 133904 KB Output is correct
57 Correct 1101 ms 134176 KB Output is correct
58 Correct 937 ms 133792 KB Output is correct
59 Correct 1066 ms 133960 KB Output is correct
60 Correct 1082 ms 133988 KB Output is correct
61 Correct 1073 ms 134168 KB Output is correct
62 Correct 1064 ms 134152 KB Output is correct
63 Correct 1063 ms 133972 KB Output is correct
64 Correct 1080 ms 134196 KB Output is correct
65 Correct 1067 ms 133980 KB Output is correct
66 Correct 1122 ms 134156 KB Output is correct
67 Correct 1026 ms 133920 KB Output is correct
68 Correct 1082 ms 134124 KB Output is correct
69 Correct 5393 ms 181352 KB Output is correct
70 Correct 5904 ms 190560 KB Output is correct
71 Correct 1855 ms 137488 KB Output is correct
72 Correct 1877 ms 137820 KB Output is correct
73 Correct 1847 ms 137552 KB Output is correct
74 Correct 3317 ms 179232 KB Output is correct
75 Correct 1734 ms 137380 KB Output is correct
76 Correct 3642 ms 188396 KB Output is correct
77 Correct 3213 ms 179248 KB Output is correct
78 Correct 1729 ms 137420 KB Output is correct
79 Correct 1758 ms 137612 KB Output is correct
80 Correct 4114 ms 174596 KB Output is correct
81 Correct 2295 ms 137604 KB Output is correct
82 Correct 4878 ms 190468 KB Output is correct
83 Correct 4632 ms 187076 KB Output is correct
84 Correct 2296 ms 137652 KB Output is correct
85 Correct 2267 ms 137580 KB Output is correct
86 Correct 5049 ms 177160 KB Output is correct
87 Correct 5807 ms 190596 KB Output is correct
88 Correct 2546 ms 137580 KB Output is correct
89 Correct 5134 ms 183956 KB Output is correct
90 Correct 5581 ms 190624 KB Output is correct
91 Correct 2524 ms 137428 KB Output is correct
92 Correct 4330 ms 176504 KB Output is correct
93 Correct 2274 ms 137672 KB Output is correct
94 Correct 2265 ms 137496 KB Output is correct
95 Correct 2285 ms 137572 KB Output is correct
96 Correct 3582 ms 187612 KB Output is correct
97 Correct 3004 ms 190664 KB Output is correct
98 Correct 4287 ms 171532 KB Output is correct
99 Execution timed out 7030 ms 190788 KB Time limit exceeded
100 Halted 0 ms 0 KB -