Submission #866690

# Submission time Handle Problem Language Result Execution time Memory
866690 2023-10-26T18:18:25 Z vjudge1 Crossing (JOI21_crossing) C++17
100 / 100
2282 ms 100836 KB
#include <bits/stdc++.h>
using namespace std;

int const MAXN=2e6, K=(1<<18);

int n, q;
string a, b, c, p;
vector<string> v;
bool tree[10][2*K-1];
char lazy[10][2*K-1];
int jprefix[10][MAXN], oprefix[10][MAXN], iprefix[10][MAXN];

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

    return t;
}

bool goodstring()
{
    for (int j=0; j<v.size(); j++)
        if (tree[j][0])
            return true;

    return false;
}

bool good(int j, int l, int r, char c)
{
    r=min(r, n)-1;
    if (l>r)
        return true;
    int total;
    if (c=='J')
    {
        total=jprefix[j][r];
        if (l!=0)
            total=total-jprefix[j][l-1];
    }
    if (c=='O')
    {
        total=oprefix[j][r];
        if (l!=0)
            total=total-oprefix[j][l-1];
    }
    if (c=='I')
    {
        total=iprefix[j][r];
        if (l!=0)
            total=total-iprefix[j][l-1];
    }

    return total==r-l+1;
}

void propagate(int j, int x, int l, int r)
{
    if (lazy[j][x]=='#')
        return;
    if (r-l==1)
    {
        lazy[j][x]='#';
        return;
    }
    tree[j][2*x+1]=good(j, l, (l+r)/2, lazy[j][x]);
    lazy[j][2*x+1]=lazy[j][x];
    tree[j][2*x+2]=good(j, (l+r)/2, r, lazy[j][x]);
    lazy[j][2*x+2]=lazy[j][x];
    lazy[j][x]='#';

    return;
}

void update(int j, int x, int l, int r, char c, int lt, int rt)
{
    if (l>=rt || r<=lt)
        return;
    if (l>=lt && r<=rt)
    {
        tree[j][x]=good(j, l, r, c);
        lazy[j][x]=c;
        return;
    }
    propagate(j, x, l, r);
    update(j, 2*x+1, l, (l+r)/2, c, lt, rt);
    update(j, 2*x+2, (l+r)/2, r, c, lt, rt);
    if (r-l==1)
    {
        if (l>=n)
            tree[j][x]=true;
        else
            tree[j][x]=(v[j][l]==c);
    }
    else
        tree[j][x]=(tree[j][2*x+1]&tree[j][2*x+2]);

    return;
}

int main()
{
    cin >> n >> a >> b >> c;
    cin >> q >> p;

    set<string> s, snew;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    bool newstring=true;
    while (newstring)
    {
        newstring=false;
        snew.clear();
        for (int i=0; i<v.size(); i++)
            for (int j=i+1; j<v.size(); j++)
            {
                string t=cross(v[i], v[j]);
                if (s.count(t)==0)
                {
                    snew.insert(t);
                    newstring=true;
                }
            }
        for (auto t : snew)
        {
            s.insert(t);
            v.push_back(t);
        }
    }

    for (int j=0; j<v.size(); j++)
        for (int i=0; i<2*K-1; i++)
        {
            tree[j][i]=true;
            lazy[j][i]='#';
        }
    for (int j=0; j<v.size(); j++)
    {
        jprefix[j][0]=0;
        oprefix[j][0]=0;
        iprefix[j][0]=0;
        if (v[j][0]=='J')
            jprefix[j][0]=1;
        if (v[j][0]=='O')
            oprefix[j][0]=1;
        if (v[j][0]=='I')
            iprefix[j][0]=1;
        for (int i=1; i<n; i++)
        {
            jprefix[j][i]=jprefix[j][i-1];
            oprefix[j][i]=oprefix[j][i-1];
            iprefix[j][i]=iprefix[j][i-1];
            if (v[j][i]=='J')
                jprefix[j][i]=jprefix[j][i]+1;
            if (v[j][i]=='O')
                oprefix[j][i]=oprefix[j][i]+1;
            if (v[j][i]=='I')
                iprefix[j][i]=iprefix[j][i]+1;
        }
    }

    for (int j=0; j<v.size(); j++)
        for (int i=0; i<n; i++)
            update(j, 0, 0, K, p[i], i, i+1);
    if (goodstring())
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';

    while (q--)
    {
        int l, r;
        char c;
        cin >> l >> r >> c;
        l=l-1;
        for (int j=0; j<v.size(); j++)
            update(j, 0, 0, K, c, l, r);
        if (goodstring())
            cout << "Yes" << '\n';
        else
            cout << "No" << '\n';
    }

    return 0;
}

Compilation message

Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i=0; i<a.size(); i++)
      |                   ~^~~~~~~~~
Main.cpp: In function 'bool goodstring()':
Main.cpp:35:20: 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]
   35 |     for (int j=0; j<v.size(); j++)
      |                   ~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:131: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]
  131 |         for (int i=0; i<v.size(); i++)
      |                       ~^~~~~~~~~
Main.cpp:132:30: 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]
  132 |             for (int j=i+1; j<v.size(); j++)
      |                             ~^~~~~~~~~
Main.cpp:148:20: 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]
  148 |     for (int j=0; j<v.size(); j++)
      |                   ~^~~~~~~~~
Main.cpp:154:20: 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 j=0; j<v.size(); j++)
      |                   ~^~~~~~~~~
Main.cpp:179:20: 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]
  179 |     for (int j=0; j<v.size(); j++)
      |                   ~^~~~~~~~~
Main.cpp:193: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]
  193 |         for (int j=0; j<v.size(); j++)
      |                       ~^~~~~~~~~
Main.cpp: In function 'bool good(int, int, int, char)':
Main.cpp:67:23: warning: 'total' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |     return total==r-l+1;
      |                       ^
# Verdict Execution time Memory Grader output
1 Correct 436 ms 26412 KB Output is correct
2 Correct 466 ms 26636 KB Output is correct
3 Correct 487 ms 26740 KB Output is correct
4 Correct 444 ms 26644 KB Output is correct
5 Correct 442 ms 26592 KB Output is correct
6 Correct 426 ms 26572 KB Output is correct
7 Correct 448 ms 26628 KB Output is correct
8 Correct 460 ms 26912 KB Output is correct
9 Correct 447 ms 26452 KB Output is correct
10 Correct 454 ms 26584 KB Output is correct
11 Correct 456 ms 26812 KB Output is correct
12 Correct 448 ms 26452 KB Output is correct
13 Correct 462 ms 26756 KB Output is correct
14 Correct 451 ms 26468 KB Output is correct
15 Correct 451 ms 26456 KB Output is correct
16 Correct 451 ms 26708 KB Output is correct
17 Correct 451 ms 26452 KB Output is correct
18 Correct 479 ms 26808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 26412 KB Output is correct
2 Correct 466 ms 26636 KB Output is correct
3 Correct 487 ms 26740 KB Output is correct
4 Correct 444 ms 26644 KB Output is correct
5 Correct 442 ms 26592 KB Output is correct
6 Correct 426 ms 26572 KB Output is correct
7 Correct 448 ms 26628 KB Output is correct
8 Correct 460 ms 26912 KB Output is correct
9 Correct 447 ms 26452 KB Output is correct
10 Correct 454 ms 26584 KB Output is correct
11 Correct 456 ms 26812 KB Output is correct
12 Correct 448 ms 26452 KB Output is correct
13 Correct 462 ms 26756 KB Output is correct
14 Correct 451 ms 26468 KB Output is correct
15 Correct 451 ms 26456 KB Output is correct
16 Correct 451 ms 26708 KB Output is correct
17 Correct 451 ms 26452 KB Output is correct
18 Correct 479 ms 26808 KB Output is correct
19 Correct 877 ms 39772 KB Output is correct
20 Correct 882 ms 39644 KB Output is correct
21 Correct 646 ms 39880 KB Output is correct
22 Correct 611 ms 39676 KB Output is correct
23 Correct 498 ms 27220 KB Output is correct
24 Correct 494 ms 27220 KB Output is correct
25 Correct 698 ms 39880 KB Output is correct
26 Correct 689 ms 40224 KB Output is correct
27 Correct 730 ms 40100 KB Output is correct
28 Correct 727 ms 40376 KB Output is correct
29 Correct 714 ms 39740 KB Output is correct
30 Correct 517 ms 27220 KB Output is correct
31 Correct 727 ms 39704 KB Output is correct
32 Correct 683 ms 39800 KB Output is correct
33 Correct 501 ms 28008 KB Output is correct
34 Correct 713 ms 39656 KB Output is correct
35 Correct 583 ms 37032 KB Output is correct
36 Correct 500 ms 27664 KB Output is correct
37 Correct 491 ms 27220 KB Output is correct
38 Correct 834 ms 40052 KB Output is correct
39 Correct 589 ms 39744 KB Output is correct
40 Correct 622 ms 34952 KB Output is correct
41 Correct 888 ms 39860 KB Output is correct
42 Correct 542 ms 39776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 26412 KB Output is correct
2 Correct 466 ms 26636 KB Output is correct
3 Correct 487 ms 26740 KB Output is correct
4 Correct 444 ms 26644 KB Output is correct
5 Correct 442 ms 26592 KB Output is correct
6 Correct 426 ms 26572 KB Output is correct
7 Correct 448 ms 26628 KB Output is correct
8 Correct 460 ms 26912 KB Output is correct
9 Correct 447 ms 26452 KB Output is correct
10 Correct 454 ms 26584 KB Output is correct
11 Correct 456 ms 26812 KB Output is correct
12 Correct 448 ms 26452 KB Output is correct
13 Correct 462 ms 26756 KB Output is correct
14 Correct 451 ms 26468 KB Output is correct
15 Correct 451 ms 26456 KB Output is correct
16 Correct 451 ms 26708 KB Output is correct
17 Correct 451 ms 26452 KB Output is correct
18 Correct 479 ms 26808 KB Output is correct
19 Correct 789 ms 65840 KB Output is correct
20 Correct 901 ms 65760 KB Output is correct
21 Correct 513 ms 32872 KB Output is correct
22 Correct 463 ms 33104 KB Output is correct
23 Correct 510 ms 33296 KB Output is correct
24 Correct 500 ms 33268 KB Output is correct
25 Correct 503 ms 33108 KB Output is correct
26 Correct 498 ms 33212 KB Output is correct
27 Correct 456 ms 27120 KB Output is correct
28 Correct 412 ms 26964 KB Output is correct
29 Correct 461 ms 27432 KB Output is correct
30 Correct 428 ms 26872 KB Output is correct
31 Correct 772 ms 66388 KB Output is correct
32 Correct 764 ms 66128 KB Output is correct
33 Correct 781 ms 66376 KB Output is correct
34 Correct 744 ms 66156 KB Output is correct
35 Correct 795 ms 66376 KB Output is correct
36 Correct 783 ms 66388 KB Output is correct
37 Correct 790 ms 66500 KB Output is correct
38 Correct 798 ms 66340 KB Output is correct
39 Correct 784 ms 66584 KB Output is correct
40 Correct 816 ms 66168 KB Output is correct
41 Correct 786 ms 66336 KB Output is correct
42 Correct 798 ms 66384 KB Output is correct
43 Correct 781 ms 66336 KB Output is correct
44 Correct 818 ms 66560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 436 ms 26412 KB Output is correct
2 Correct 466 ms 26636 KB Output is correct
3 Correct 487 ms 26740 KB Output is correct
4 Correct 444 ms 26644 KB Output is correct
5 Correct 442 ms 26592 KB Output is correct
6 Correct 426 ms 26572 KB Output is correct
7 Correct 448 ms 26628 KB Output is correct
8 Correct 460 ms 26912 KB Output is correct
9 Correct 447 ms 26452 KB Output is correct
10 Correct 454 ms 26584 KB Output is correct
11 Correct 456 ms 26812 KB Output is correct
12 Correct 448 ms 26452 KB Output is correct
13 Correct 462 ms 26756 KB Output is correct
14 Correct 451 ms 26468 KB Output is correct
15 Correct 451 ms 26456 KB Output is correct
16 Correct 451 ms 26708 KB Output is correct
17 Correct 451 ms 26452 KB Output is correct
18 Correct 479 ms 26808 KB Output is correct
19 Correct 877 ms 39772 KB Output is correct
20 Correct 882 ms 39644 KB Output is correct
21 Correct 646 ms 39880 KB Output is correct
22 Correct 611 ms 39676 KB Output is correct
23 Correct 498 ms 27220 KB Output is correct
24 Correct 494 ms 27220 KB Output is correct
25 Correct 698 ms 39880 KB Output is correct
26 Correct 689 ms 40224 KB Output is correct
27 Correct 730 ms 40100 KB Output is correct
28 Correct 727 ms 40376 KB Output is correct
29 Correct 714 ms 39740 KB Output is correct
30 Correct 517 ms 27220 KB Output is correct
31 Correct 727 ms 39704 KB Output is correct
32 Correct 683 ms 39800 KB Output is correct
33 Correct 501 ms 28008 KB Output is correct
34 Correct 713 ms 39656 KB Output is correct
35 Correct 583 ms 37032 KB Output is correct
36 Correct 500 ms 27664 KB Output is correct
37 Correct 491 ms 27220 KB Output is correct
38 Correct 834 ms 40052 KB Output is correct
39 Correct 589 ms 39744 KB Output is correct
40 Correct 622 ms 34952 KB Output is correct
41 Correct 888 ms 39860 KB Output is correct
42 Correct 542 ms 39776 KB Output is correct
43 Correct 789 ms 65840 KB Output is correct
44 Correct 901 ms 65760 KB Output is correct
45 Correct 513 ms 32872 KB Output is correct
46 Correct 463 ms 33104 KB Output is correct
47 Correct 510 ms 33296 KB Output is correct
48 Correct 500 ms 33268 KB Output is correct
49 Correct 503 ms 33108 KB Output is correct
50 Correct 498 ms 33212 KB Output is correct
51 Correct 456 ms 27120 KB Output is correct
52 Correct 412 ms 26964 KB Output is correct
53 Correct 461 ms 27432 KB Output is correct
54 Correct 428 ms 26872 KB Output is correct
55 Correct 772 ms 66388 KB Output is correct
56 Correct 764 ms 66128 KB Output is correct
57 Correct 781 ms 66376 KB Output is correct
58 Correct 744 ms 66156 KB Output is correct
59 Correct 795 ms 66376 KB Output is correct
60 Correct 783 ms 66388 KB Output is correct
61 Correct 790 ms 66500 KB Output is correct
62 Correct 798 ms 66340 KB Output is correct
63 Correct 784 ms 66584 KB Output is correct
64 Correct 816 ms 66168 KB Output is correct
65 Correct 786 ms 66336 KB Output is correct
66 Correct 798 ms 66384 KB Output is correct
67 Correct 781 ms 66336 KB Output is correct
68 Correct 818 ms 66560 KB Output is correct
69 Correct 2282 ms 95248 KB Output is correct
70 Correct 2229 ms 100836 KB Output is correct
71 Correct 568 ms 34132 KB Output is correct
72 Correct 569 ms 34444 KB Output is correct
73 Correct 570 ms 34384 KB Output is correct
74 Correct 611 ms 41132 KB Output is correct
75 Correct 491 ms 28060 KB Output is correct
76 Correct 670 ms 41816 KB Output is correct
77 Correct 642 ms 41236 KB Output is correct
78 Correct 525 ms 28580 KB Output is correct
79 Correct 494 ms 27984 KB Output is correct
80 Correct 1456 ms 90328 KB Output is correct
81 Correct 876 ms 69420 KB Output is correct
82 Correct 1666 ms 100288 KB Output is correct
83 Correct 1690 ms 97988 KB Output is correct
84 Correct 883 ms 69808 KB Output is correct
85 Correct 866 ms 69456 KB Output is correct
86 Correct 1724 ms 92944 KB Output is correct
87 Correct 1913 ms 100316 KB Output is correct
88 Correct 927 ms 69460 KB Output is correct
89 Correct 1611 ms 95548 KB Output is correct
90 Correct 1827 ms 100676 KB Output is correct
91 Correct 915 ms 69712 KB Output is correct
92 Correct 1362 ms 92764 KB Output is correct
93 Correct 867 ms 69524 KB Output is correct
94 Correct 858 ms 69492 KB Output is correct
95 Correct 863 ms 69716 KB Output is correct
96 Correct 828 ms 41500 KB Output is correct
97 Correct 1240 ms 100368 KB Output is correct
98 Correct 1322 ms 88456 KB Output is correct
99 Correct 2204 ms 100772 KB Output is correct
100 Correct 1156 ms 99776 KB Output is correct