Submission #420015

# Submission time Handle Problem Language Result Execution time Memory
420015 2021-06-07T22:26:50 Z Runtime_error_ Crossing (JOI21_crossing) C++14
100 / 100
950 ms 28520 KB
//JOIOC 2021 p1 crossing
#include <bits/stdc++.h>
#define pb push_back
#define le node+node
#define ri node+node+1
#define mid (l+r)/2
#define all(v) v.begin(),v.end()
using namespace std;
const int inf = 2e5+2,lg = 10;
int n,k,q;
bool ans;
string s;
vector<string> v;
int pre[lg][3][inf];
char ss[inf];
int mp[99];

string in(){
    scanf("%s",ss);
    return string(ss);
}

string cross(string &a,string &b){
    string ret = a;
    for(int i=0;i<n;i++){
        if(a[i] == b[i])
            continue;
        else if(a[i] != 'J' && b[i] != 'J')
            ret[i]= 'J';
        else if(a[i] != 'O' && b[i] != 'O')
            ret[i]= 'O';
        else
            ret[i]= 'I';
    }
    return ret;
}

void go(){
   map<string,bool> s;

    for(int i=0;i<3;i++)
        v.pb(in()),s[v.back()];
    v.pb(cross(v[0],v[1])),s[v.back()];
    v.pb(cross(v[0],v[2])),s[v.back()];
    v.pb(cross(v[1],v[2])),s[v.back()];

    s[cross(v[3],v[2])];
    s[cross(v[4],v[1])];
    s[cross(v[5],v[0])];

    v.clear();
    for(auto o:s)
        v.pb(o.first);
    k = v.size();
    for(int i=0;i<k;i++)
        for(int let=0;let<3;let++)
            for(int j=0;j<n;j++)
                    pre[i][let][j] = (j>0?pre[i][let][j-1]:0) + (mp[v[i][j]] == let);
}
int lazy[inf<<2],tree[inf<<2];

void build(int node,int l,int r){
    lazy[node] = -1;
    if(l == r){
        for(int i=0;i<k;i++)
            if(s[l] == v[i][l])
                tree[node] |= (1<<i);
        return;
    }
    build(le,l,mid);
    build(ri,mid+1,r);
    tree[node] = (tree[le] & tree[ri]);
}

void push(int node,int l,int r){
    if(lazy[node] == -1)
        return ;
    if(l != r)
        lazy[le] = lazy[ri] = lazy[node];

    int sz = r-l+1,let= lazy[node];
    tree[node] = 0;
    for(int i=0;i<k;i++)
        if((pre[i][let][r] - (l>0?pre[i][let][l-1]:0) ) == r-l+1 )
            tree[node] |= (1<<i);
    lazy[node] = -1;
}

void update(int node,int l,int r,int x,int y,int val){
    push(node,l,r);
    if(l>r || r<x || l>y || x>y)
        return ;
    if(l>=x && r<=y){
        lazy[node] = val;
        push(node,l,r);
        return ;
    }
    update(le,l,mid,x,y,val);
    update(ri,mid+1,r,x,y,val);
    tree[node] = (tree[le] & tree[ri]);
}

int main(){
    mp['J'] = 0,mp['O'] = 1,mp['I'] = 2;
    scanf("%d",&n);
    go();
    assert(k<lg);
    scanf("%d",&q);
    s = in();
    ans = 0;
    build(1,0,n-1);
    if(tree[1])
        puts("Yes");
    else
        puts("No");
    while(q--){
        int l,r;
        ans =0;
        char c[2];
        scanf("%d%d",&l,&r);
        scanf("%s",c);
        update(1,0,n-1,l-1,r-1,mp[c[0]]);
    if(tree[1])
        puts("Yes");
    else
        puts("No");
    }
}

Compilation message

Main.cpp: In function 'void go()':
Main.cpp:58:76: warning: array subscript has type 'char' [-Wchar-subscripts]
   58 |                     pre[i][let][j] = (j>0?pre[i][let][j-1]:0) + (mp[v[i][j]] == let);
      |                                                                            ^
Main.cpp: In function 'void push(int, int, int)':
Main.cpp:81:9: warning: unused variable 'sz' [-Wunused-variable]
   81 |     int sz = r-l+1,let= lazy[node];
      |         ^~
Main.cpp: In function 'int main()':
Main.cpp:122:38: warning: array subscript has type 'char' [-Wchar-subscripts]
  122 |         update(1,0,n-1,l-1,r-1,mp[c[0]]);
      |                                   ~~~^
Main.cpp: In function 'std::string in()':
Main.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%s",ss);
      |     ~~~~~^~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:105:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:108:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
Main.cpp:120:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         scanf("%d%d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:121:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         scanf("%s",c);
      |         ~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 145 ms 836 KB Output is correct
2 Correct 108 ms 908 KB Output is correct
3 Correct 109 ms 912 KB Output is correct
4 Correct 91 ms 820 KB Output is correct
5 Correct 97 ms 876 KB Output is correct
6 Correct 92 ms 852 KB Output is correct
7 Correct 105 ms 788 KB Output is correct
8 Correct 95 ms 828 KB Output is correct
9 Correct 111 ms 892 KB Output is correct
10 Correct 119 ms 792 KB Output is correct
11 Correct 99 ms 864 KB Output is correct
12 Correct 101 ms 888 KB Output is correct
13 Correct 103 ms 828 KB Output is correct
14 Correct 117 ms 852 KB Output is correct
15 Correct 142 ms 896 KB Output is correct
16 Correct 104 ms 968 KB Output is correct
17 Correct 98 ms 840 KB Output is correct
18 Correct 101 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 836 KB Output is correct
2 Correct 108 ms 908 KB Output is correct
3 Correct 109 ms 912 KB Output is correct
4 Correct 91 ms 820 KB Output is correct
5 Correct 97 ms 876 KB Output is correct
6 Correct 92 ms 852 KB Output is correct
7 Correct 105 ms 788 KB Output is correct
8 Correct 95 ms 828 KB Output is correct
9 Correct 111 ms 892 KB Output is correct
10 Correct 119 ms 792 KB Output is correct
11 Correct 99 ms 864 KB Output is correct
12 Correct 101 ms 888 KB Output is correct
13 Correct 103 ms 828 KB Output is correct
14 Correct 117 ms 852 KB Output is correct
15 Correct 142 ms 896 KB Output is correct
16 Correct 104 ms 968 KB Output is correct
17 Correct 98 ms 840 KB Output is correct
18 Correct 101 ms 828 KB Output is correct
19 Correct 363 ms 7920 KB Output is correct
20 Correct 321 ms 8036 KB Output is correct
21 Correct 221 ms 7664 KB Output is correct
22 Correct 221 ms 7412 KB Output is correct
23 Correct 145 ms 1348 KB Output is correct
24 Correct 146 ms 1260 KB Output is correct
25 Correct 258 ms 7904 KB Output is correct
26 Correct 308 ms 7932 KB Output is correct
27 Correct 248 ms 7936 KB Output is correct
28 Correct 308 ms 7868 KB Output is correct
29 Correct 256 ms 7856 KB Output is correct
30 Correct 157 ms 1348 KB Output is correct
31 Correct 265 ms 7860 KB Output is correct
32 Correct 261 ms 7672 KB Output is correct
33 Correct 145 ms 1356 KB Output is correct
34 Correct 255 ms 7868 KB Output is correct
35 Correct 203 ms 7136 KB Output is correct
36 Correct 146 ms 1348 KB Output is correct
37 Correct 152 ms 1344 KB Output is correct
38 Correct 269 ms 7952 KB Output is correct
39 Correct 170 ms 7916 KB Output is correct
40 Correct 197 ms 4764 KB Output is correct
41 Correct 347 ms 8112 KB Output is correct
42 Correct 77 ms 8052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 836 KB Output is correct
2 Correct 108 ms 908 KB Output is correct
3 Correct 109 ms 912 KB Output is correct
4 Correct 91 ms 820 KB Output is correct
5 Correct 97 ms 876 KB Output is correct
6 Correct 92 ms 852 KB Output is correct
7 Correct 105 ms 788 KB Output is correct
8 Correct 95 ms 828 KB Output is correct
9 Correct 111 ms 892 KB Output is correct
10 Correct 119 ms 792 KB Output is correct
11 Correct 99 ms 864 KB Output is correct
12 Correct 101 ms 888 KB Output is correct
13 Correct 103 ms 828 KB Output is correct
14 Correct 117 ms 852 KB Output is correct
15 Correct 142 ms 896 KB Output is correct
16 Correct 104 ms 968 KB Output is correct
17 Correct 98 ms 840 KB Output is correct
18 Correct 101 ms 828 KB Output is correct
19 Correct 142 ms 928 KB Output is correct
20 Correct 147 ms 1068 KB Output is correct
21 Correct 106 ms 884 KB Output is correct
22 Correct 92 ms 872 KB Output is correct
23 Correct 107 ms 980 KB Output is correct
24 Correct 99 ms 924 KB Output is correct
25 Correct 105 ms 836 KB Output is correct
26 Correct 99 ms 832 KB Output is correct
27 Correct 103 ms 864 KB Output is correct
28 Correct 92 ms 888 KB Output is correct
29 Correct 103 ms 948 KB Output is correct
30 Correct 94 ms 824 KB Output is correct
31 Correct 122 ms 964 KB Output is correct
32 Correct 170 ms 1064 KB Output is correct
33 Correct 166 ms 1064 KB Output is correct
34 Correct 112 ms 1020 KB Output is correct
35 Correct 123 ms 960 KB Output is correct
36 Correct 192 ms 1008 KB Output is correct
37 Correct 187 ms 960 KB Output is correct
38 Correct 124 ms 1044 KB Output is correct
39 Correct 132 ms 984 KB Output is correct
40 Correct 127 ms 988 KB Output is correct
41 Correct 162 ms 1004 KB Output is correct
42 Correct 149 ms 996 KB Output is correct
43 Correct 123 ms 1044 KB Output is correct
44 Correct 130 ms 944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 836 KB Output is correct
2 Correct 108 ms 908 KB Output is correct
3 Correct 109 ms 912 KB Output is correct
4 Correct 91 ms 820 KB Output is correct
5 Correct 97 ms 876 KB Output is correct
6 Correct 92 ms 852 KB Output is correct
7 Correct 105 ms 788 KB Output is correct
8 Correct 95 ms 828 KB Output is correct
9 Correct 111 ms 892 KB Output is correct
10 Correct 119 ms 792 KB Output is correct
11 Correct 99 ms 864 KB Output is correct
12 Correct 101 ms 888 KB Output is correct
13 Correct 103 ms 828 KB Output is correct
14 Correct 117 ms 852 KB Output is correct
15 Correct 142 ms 896 KB Output is correct
16 Correct 104 ms 968 KB Output is correct
17 Correct 98 ms 840 KB Output is correct
18 Correct 101 ms 828 KB Output is correct
19 Correct 363 ms 7920 KB Output is correct
20 Correct 321 ms 8036 KB Output is correct
21 Correct 221 ms 7664 KB Output is correct
22 Correct 221 ms 7412 KB Output is correct
23 Correct 145 ms 1348 KB Output is correct
24 Correct 146 ms 1260 KB Output is correct
25 Correct 258 ms 7904 KB Output is correct
26 Correct 308 ms 7932 KB Output is correct
27 Correct 248 ms 7936 KB Output is correct
28 Correct 308 ms 7868 KB Output is correct
29 Correct 256 ms 7856 KB Output is correct
30 Correct 157 ms 1348 KB Output is correct
31 Correct 265 ms 7860 KB Output is correct
32 Correct 261 ms 7672 KB Output is correct
33 Correct 145 ms 1356 KB Output is correct
34 Correct 255 ms 7868 KB Output is correct
35 Correct 203 ms 7136 KB Output is correct
36 Correct 146 ms 1348 KB Output is correct
37 Correct 152 ms 1344 KB Output is correct
38 Correct 269 ms 7952 KB Output is correct
39 Correct 170 ms 7916 KB Output is correct
40 Correct 197 ms 4764 KB Output is correct
41 Correct 347 ms 8112 KB Output is correct
42 Correct 77 ms 8052 KB Output is correct
43 Correct 142 ms 928 KB Output is correct
44 Correct 147 ms 1068 KB Output is correct
45 Correct 106 ms 884 KB Output is correct
46 Correct 92 ms 872 KB Output is correct
47 Correct 107 ms 980 KB Output is correct
48 Correct 99 ms 924 KB Output is correct
49 Correct 105 ms 836 KB Output is correct
50 Correct 99 ms 832 KB Output is correct
51 Correct 103 ms 864 KB Output is correct
52 Correct 92 ms 888 KB Output is correct
53 Correct 103 ms 948 KB Output is correct
54 Correct 94 ms 824 KB Output is correct
55 Correct 122 ms 964 KB Output is correct
56 Correct 170 ms 1064 KB Output is correct
57 Correct 166 ms 1064 KB Output is correct
58 Correct 112 ms 1020 KB Output is correct
59 Correct 123 ms 960 KB Output is correct
60 Correct 192 ms 1008 KB Output is correct
61 Correct 187 ms 960 KB Output is correct
62 Correct 124 ms 1044 KB Output is correct
63 Correct 132 ms 984 KB Output is correct
64 Correct 127 ms 988 KB Output is correct
65 Correct 162 ms 1004 KB Output is correct
66 Correct 149 ms 996 KB Output is correct
67 Correct 123 ms 1044 KB Output is correct
68 Correct 130 ms 944 KB Output is correct
69 Correct 950 ms 24636 KB Output is correct
70 Correct 776 ms 28168 KB Output is correct
71 Correct 162 ms 1608 KB Output is correct
72 Correct 168 ms 1684 KB Output is correct
73 Correct 159 ms 1604 KB Output is correct
74 Correct 256 ms 11632 KB Output is correct
75 Correct 158 ms 1588 KB Output is correct
76 Correct 281 ms 13096 KB Output is correct
77 Correct 278 ms 11720 KB Output is correct
78 Correct 157 ms 1560 KB Output is correct
79 Correct 154 ms 1604 KB Output is correct
80 Correct 394 ms 21592 KB Output is correct
81 Correct 190 ms 2512 KB Output is correct
82 Correct 427 ms 28412 KB Output is correct
83 Correct 465 ms 27096 KB Output is correct
84 Correct 189 ms 2544 KB Output is correct
85 Correct 192 ms 2500 KB Output is correct
86 Correct 648 ms 22900 KB Output is correct
87 Correct 653 ms 28504 KB Output is correct
88 Correct 242 ms 2624 KB Output is correct
89 Correct 536 ms 25536 KB Output is correct
90 Correct 552 ms 28340 KB Output is correct
91 Correct 227 ms 2500 KB Output is correct
92 Correct 370 ms 22408 KB Output is correct
93 Correct 195 ms 2504 KB Output is correct
94 Correct 190 ms 2528 KB Output is correct
95 Correct 192 ms 2628 KB Output is correct
96 Correct 260 ms 7844 KB Output is correct
97 Correct 190 ms 28208 KB Output is correct
98 Correct 387 ms 18420 KB Output is correct
99 Correct 802 ms 28520 KB Output is correct
100 Correct 113 ms 28468 KB Output is correct