Submission #853823

# Submission time Handle Problem Language Result Execution time Memory
853823 2023-09-25T09:34:54 Z Gtudor Crossing (JOI21_crossing) C++14
100 / 100
809 ms 27784 KB
#include <iostream>

#define NMAX 200000
using namespace std;

//ifstream cin(".in");
//ofstream cout(".out");

string s[10], t;

void add2Strings(int a, int b, int sum, int n) {
  s[sum].resize(n + 1, 0);
  s[sum][0] = ' ';
  for(int i = 1; i <= n; i++) {
    if(s[a][i] == s[b][i]) {
      s[sum][i] = s[a][i];
    } else {
      if('J' != s[a][i] && 'J' != s[b][i])
        s[sum][i] = 'J';
      if('O' != s[a][i] && 'O' != s[b][i])
        s[sum][i] = 'O';
      if('I' != s[a][i] && 'I' != s[b][i])
        s[sum][i] = 'I';
   }
  }
}

void buildAllPosStrings(int n) {
  add2Strings(1, 2, 4, n);
  add2Strings(2, 3, 5, n);
  add2Strings(3, 1, 6, n);
  add2Strings(4, 3, 7, n);
  add2Strings(5, 1, 8, n);
  add2Strings(6, 2, 9, n);
}

struct node{
  bool equal;
  char lazy, specialProp;
}arboriAint[10][NMAX * 4];

void buildArb(int indexS, int p, int lInt, int rInt) {
  if(lInt == rInt) {
    if(s[indexS][lInt] == t[lInt]) {
      arboriAint[indexS][p].equal = 1;
    }
    arboriAint[indexS][p].specialProp = s[indexS][lInt];
    return;
  }

  int med = (lInt + rInt) / 2;

  buildArb(indexS, p * 2, lInt, med);
  buildArb(indexS, p * 2 + 1, med + 1, rInt);
  
  if(arboriAint[indexS][p * 2].equal == arboriAint[indexS][p * 2 + 1].equal && arboriAint[indexS][p * 2].equal == 1)
    arboriAint[indexS][p].equal = 1;
  if(arboriAint[indexS][p * 2].specialProp == arboriAint[indexS][p * 2 + 1].specialProp)
    arboriAint[indexS][p].specialProp = arboriAint[indexS][p * 2].specialProp;
}

void propagate(node aint[], int p) {
  if(aint[p].lazy == 0)
    return;
  aint[p * 2].lazy = aint[p].lazy;
  aint[p * 2 + 1].lazy = aint[p].lazy;
  aint[p * 2].equal = ((aint[p * 2].specialProp == aint[p].lazy) && (aint[p].lazy != 0));
  aint[p * 2 + 1].equal = ((aint[p * 2 + 1].specialProp == aint[p].lazy && (aint[p].lazy != 0)));
  aint[p].lazy = 0;
}

void update(node aint[], int p, int lInt, int rInt, int lTarget, int rTarget, char modValue) {
  if(lInt == rInt) {
    aint[p].equal = (modValue == aint[p].specialProp);
    return;
  }
  propagate(aint, p);
  if(lTarget <= lInt && rInt <= rTarget) {
    aint[p].equal = (modValue == aint[p].specialProp);
    aint[p].lazy = modValue;
    return;
  }

  int med = (lInt + rInt) / 2;

  if(lTarget <= med) {
    update(aint, p * 2, lInt, med, lTarget, rTarget, modValue);
  }
  if(med + 1 <= rTarget) {
    update(aint, p * 2 + 1, med + 1, rInt, lTarget, rTarget, modValue);
  }

  aint[p].equal = ((aint[p * 2].equal == aint[p * 2 + 1].equal) && aint[p * 2].equal == 1);
}

bool isEqual(node aint[]) {
  return aint[1].equal;
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q, l, r, i;
  char ch;
  bool match;

  cin>>n;

  cin>>s[1];
  s[1] = " " + s[1];
  cin>>s[2];
  s[2] = " " + s[2];
  cin>>s[3];
  s[3] = " " + s[3];

  buildAllPosStrings(n);

  cin>>q;
  cin>>t;
  t = " " + t;

  for(i = 1; i <= 9; i++) {
    buildArb(i, 1, 1, n);
  }

  match = 0;
  for(i = 1; i <= 9; i++) {
    if(isEqual(arboriAint[i]) == 1) {
      match = 1;
    }
  }
  if(match) {
    cout<<"Yes\n";
  } else {
    cout<<"No\n";
  }

  while(q--) {
    cin>>l>>r>>ch;

    for(i = 1; i <= 9; i++) {
      update(arboriAint[i], 1, 1, n, l, r, ch);
    }
    match = 0;
    for(i = 1; i <= 9; i++) {
      if(isEqual(arboriAint[i]) == 1) {
        match = 1;
      }
    }
    if(match) {
      cout<<"Yes\n";
    } else {
      cout<<"No\n";
    }
  }

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 171 ms 19280 KB Output is correct
2 Correct 190 ms 20816 KB Output is correct
3 Correct 245 ms 20816 KB Output is correct
4 Correct 148 ms 20816 KB Output is correct
5 Correct 147 ms 20816 KB Output is correct
6 Correct 151 ms 20896 KB Output is correct
7 Correct 152 ms 21072 KB Output is correct
8 Correct 159 ms 20816 KB Output is correct
9 Correct 166 ms 21076 KB Output is correct
10 Correct 160 ms 20824 KB Output is correct
11 Correct 162 ms 20816 KB Output is correct
12 Correct 160 ms 20828 KB Output is correct
13 Correct 162 ms 20808 KB Output is correct
14 Correct 159 ms 20816 KB Output is correct
15 Correct 162 ms 20952 KB Output is correct
16 Correct 161 ms 21040 KB Output is correct
17 Correct 162 ms 20820 KB Output is correct
18 Correct 208 ms 20816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 19280 KB Output is correct
2 Correct 190 ms 20816 KB Output is correct
3 Correct 245 ms 20816 KB Output is correct
4 Correct 148 ms 20816 KB Output is correct
5 Correct 147 ms 20816 KB Output is correct
6 Correct 151 ms 20896 KB Output is correct
7 Correct 152 ms 21072 KB Output is correct
8 Correct 159 ms 20816 KB Output is correct
9 Correct 166 ms 21076 KB Output is correct
10 Correct 160 ms 20824 KB Output is correct
11 Correct 162 ms 20816 KB Output is correct
12 Correct 160 ms 20828 KB Output is correct
13 Correct 162 ms 20808 KB Output is correct
14 Correct 159 ms 20816 KB Output is correct
15 Correct 162 ms 20952 KB Output is correct
16 Correct 161 ms 21040 KB Output is correct
17 Correct 162 ms 20820 KB Output is correct
18 Correct 208 ms 20816 KB Output is correct
19 Correct 696 ms 27324 KB Output is correct
20 Correct 768 ms 27432 KB Output is correct
21 Correct 439 ms 26912 KB Output is correct
22 Correct 391 ms 26596 KB Output is correct
23 Correct 292 ms 21924 KB Output is correct
24 Correct 291 ms 21796 KB Output is correct
25 Correct 405 ms 27224 KB Output is correct
26 Correct 468 ms 27240 KB Output is correct
27 Correct 537 ms 27372 KB Output is correct
28 Correct 547 ms 27536 KB Output is correct
29 Correct 520 ms 27268 KB Output is correct
30 Correct 334 ms 21912 KB Output is correct
31 Correct 545 ms 27260 KB Output is correct
32 Correct 500 ms 26828 KB Output is correct
33 Correct 297 ms 21844 KB Output is correct
34 Correct 557 ms 27784 KB Output is correct
35 Correct 380 ms 26300 KB Output is correct
36 Correct 291 ms 21840 KB Output is correct
37 Correct 295 ms 22096 KB Output is correct
38 Correct 628 ms 27728 KB Output is correct
39 Correct 350 ms 27476 KB Output is correct
40 Correct 377 ms 26184 KB Output is correct
41 Correct 799 ms 27584 KB Output is correct
42 Correct 68 ms 26964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 19280 KB Output is correct
2 Correct 190 ms 20816 KB Output is correct
3 Correct 245 ms 20816 KB Output is correct
4 Correct 148 ms 20816 KB Output is correct
5 Correct 147 ms 20816 KB Output is correct
6 Correct 151 ms 20896 KB Output is correct
7 Correct 152 ms 21072 KB Output is correct
8 Correct 159 ms 20816 KB Output is correct
9 Correct 166 ms 21076 KB Output is correct
10 Correct 160 ms 20824 KB Output is correct
11 Correct 162 ms 20816 KB Output is correct
12 Correct 160 ms 20828 KB Output is correct
13 Correct 162 ms 20808 KB Output is correct
14 Correct 159 ms 20816 KB Output is correct
15 Correct 162 ms 20952 KB Output is correct
16 Correct 161 ms 21040 KB Output is correct
17 Correct 162 ms 20820 KB Output is correct
18 Correct 208 ms 20816 KB Output is correct
19 Correct 181 ms 20796 KB Output is correct
20 Correct 244 ms 20924 KB Output is correct
21 Correct 159 ms 20856 KB Output is correct
22 Correct 138 ms 20672 KB Output is correct
23 Correct 158 ms 20816 KB Output is correct
24 Correct 158 ms 21364 KB Output is correct
25 Correct 162 ms 20816 KB Output is correct
26 Correct 144 ms 20816 KB Output is correct
27 Correct 161 ms 20992 KB Output is correct
28 Correct 143 ms 20812 KB Output is correct
29 Correct 166 ms 21484 KB Output is correct
30 Correct 138 ms 20772 KB Output is correct
31 Correct 160 ms 20828 KB Output is correct
32 Correct 157 ms 20820 KB Output is correct
33 Correct 160 ms 20816 KB Output is correct
34 Correct 151 ms 20896 KB Output is correct
35 Correct 161 ms 20872 KB Output is correct
36 Correct 163 ms 20960 KB Output is correct
37 Correct 159 ms 20816 KB Output is correct
38 Correct 163 ms 20816 KB Output is correct
39 Correct 160 ms 20816 KB Output is correct
40 Correct 170 ms 21332 KB Output is correct
41 Correct 160 ms 21000 KB Output is correct
42 Correct 163 ms 20852 KB Output is correct
43 Correct 150 ms 20816 KB Output is correct
44 Correct 161 ms 20864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 19280 KB Output is correct
2 Correct 190 ms 20816 KB Output is correct
3 Correct 245 ms 20816 KB Output is correct
4 Correct 148 ms 20816 KB Output is correct
5 Correct 147 ms 20816 KB Output is correct
6 Correct 151 ms 20896 KB Output is correct
7 Correct 152 ms 21072 KB Output is correct
8 Correct 159 ms 20816 KB Output is correct
9 Correct 166 ms 21076 KB Output is correct
10 Correct 160 ms 20824 KB Output is correct
11 Correct 162 ms 20816 KB Output is correct
12 Correct 160 ms 20828 KB Output is correct
13 Correct 162 ms 20808 KB Output is correct
14 Correct 159 ms 20816 KB Output is correct
15 Correct 162 ms 20952 KB Output is correct
16 Correct 161 ms 21040 KB Output is correct
17 Correct 162 ms 20820 KB Output is correct
18 Correct 208 ms 20816 KB Output is correct
19 Correct 696 ms 27324 KB Output is correct
20 Correct 768 ms 27432 KB Output is correct
21 Correct 439 ms 26912 KB Output is correct
22 Correct 391 ms 26596 KB Output is correct
23 Correct 292 ms 21924 KB Output is correct
24 Correct 291 ms 21796 KB Output is correct
25 Correct 405 ms 27224 KB Output is correct
26 Correct 468 ms 27240 KB Output is correct
27 Correct 537 ms 27372 KB Output is correct
28 Correct 547 ms 27536 KB Output is correct
29 Correct 520 ms 27268 KB Output is correct
30 Correct 334 ms 21912 KB Output is correct
31 Correct 545 ms 27260 KB Output is correct
32 Correct 500 ms 26828 KB Output is correct
33 Correct 297 ms 21844 KB Output is correct
34 Correct 557 ms 27784 KB Output is correct
35 Correct 380 ms 26300 KB Output is correct
36 Correct 291 ms 21840 KB Output is correct
37 Correct 295 ms 22096 KB Output is correct
38 Correct 628 ms 27728 KB Output is correct
39 Correct 350 ms 27476 KB Output is correct
40 Correct 377 ms 26184 KB Output is correct
41 Correct 799 ms 27584 KB Output is correct
42 Correct 68 ms 26964 KB Output is correct
43 Correct 181 ms 20796 KB Output is correct
44 Correct 244 ms 20924 KB Output is correct
45 Correct 159 ms 20856 KB Output is correct
46 Correct 138 ms 20672 KB Output is correct
47 Correct 158 ms 20816 KB Output is correct
48 Correct 158 ms 21364 KB Output is correct
49 Correct 162 ms 20816 KB Output is correct
50 Correct 144 ms 20816 KB Output is correct
51 Correct 161 ms 20992 KB Output is correct
52 Correct 143 ms 20812 KB Output is correct
53 Correct 166 ms 21484 KB Output is correct
54 Correct 138 ms 20772 KB Output is correct
55 Correct 160 ms 20828 KB Output is correct
56 Correct 157 ms 20820 KB Output is correct
57 Correct 160 ms 20816 KB Output is correct
58 Correct 151 ms 20896 KB Output is correct
59 Correct 161 ms 20872 KB Output is correct
60 Correct 163 ms 20960 KB Output is correct
61 Correct 159 ms 20816 KB Output is correct
62 Correct 163 ms 20816 KB Output is correct
63 Correct 160 ms 20816 KB Output is correct
64 Correct 170 ms 21332 KB Output is correct
65 Correct 160 ms 21000 KB Output is correct
66 Correct 163 ms 20852 KB Output is correct
67 Correct 150 ms 20816 KB Output is correct
68 Correct 161 ms 20864 KB Output is correct
69 Correct 616 ms 26516 KB Output is correct
70 Correct 800 ms 27472 KB Output is correct
71 Correct 297 ms 21840 KB Output is correct
72 Correct 296 ms 21932 KB Output is correct
73 Correct 294 ms 21972 KB Output is correct
74 Correct 426 ms 26536 KB Output is correct
75 Correct 299 ms 21836 KB Output is correct
76 Correct 410 ms 27484 KB Output is correct
77 Correct 438 ms 26828 KB Output is correct
78 Correct 302 ms 22224 KB Output is correct
79 Correct 292 ms 21808 KB Output is correct
80 Correct 378 ms 26192 KB Output is correct
81 Correct 294 ms 21876 KB Output is correct
82 Correct 445 ms 27308 KB Output is correct
83 Correct 420 ms 26876 KB Output is correct
84 Correct 292 ms 21840 KB Output is correct
85 Correct 289 ms 21844 KB Output is correct
86 Correct 501 ms 26708 KB Output is correct
87 Correct 606 ms 27436 KB Output is correct
88 Correct 333 ms 21912 KB Output is correct
89 Correct 476 ms 26612 KB Output is correct
90 Correct 499 ms 27232 KB Output is correct
91 Correct 324 ms 21960 KB Output is correct
92 Correct 404 ms 26572 KB Output is correct
93 Correct 294 ms 21840 KB Output is correct
94 Correct 296 ms 21880 KB Output is correct
95 Correct 302 ms 22216 KB Output is correct
96 Correct 626 ms 27012 KB Output is correct
97 Correct 348 ms 27472 KB Output is correct
98 Correct 387 ms 26188 KB Output is correct
99 Correct 809 ms 27476 KB Output is correct
100 Correct 78 ms 26696 KB Output is correct