Submission #419836

# Submission time Handle Problem Language Result Execution time Memory
419836 2021-06-07T13:40:22 Z model_code Crossing (JOI21_crossing) C++17
100 / 100
2700 ms 17936 KB
#include <stdio.h>

typedef long long int ll;

int n, q;

char sa[252525], sb[252525], sc[252525];
char t0[252525];

int l[252525], r[252525];
char c[252525];


bool result[252525];
char str[12][252525];
int slen = 0;

ll base = 1 << 18;
ll seg[1 << 19], lazy[1 << 19];
ll memo[1 << 19];

void eval (ll v) {
	if (lazy[v] == -1) return;

	ll val = ((lazy[v] == memo[v]) ? 1 : 0);
	seg[v] = val;

	if (v < base) {
		lazy[v * 2] = lazy[v];
		lazy[v * 2 + 1] = lazy[v];
	}

	lazy[v] = -1;
}
void resetseg (ll v) {
	if (v < base) seg[v] = (seg[v * 2] & seg[v * 2 + 1]);
}
ll find_ (ll l, ll r, ll beg, ll end, ll i) {
	eval(i);
	if (r <= beg || end <= l) return 0;
	if (l <= beg && end <= r) {
		return seg[i];
	}

	ll med = (beg + end) / 2;
	ll vl = find_(l, r, beg, med, i * 2);
	ll vr = find_(l, r, med, end, i * 2 + 1);

	resetseg(i);

	return (vl & vr);
}
ll find (ll l, ll r) {
	return find_(l, r, 0, base, 1);
}
void update_ (ll l, ll r, ll x, ll beg, ll end, ll i) {
	if (l <= beg && end <= r) {
		lazy[i] = x;
		eval(i);
		return;
	}
	eval(i);
	if (r <= beg || end <= l) return;

	ll med = (beg + end) / 2;
	update_(l, r, x, beg, med, i * 2);
	update_(l, r, x, med, end, i * 2 + 1);

	resetseg(i);

}
void update (ll l, ll r, ll x) {
	update_(l, r, x, 0, base, 1);
}

void func (int index) {
	char toc[3] = {'J', 'O', 'I'};
	int toi[128] = {0};
	toi['J'] = 0;
	toi['O'] = 1;
	toi['I'] = 2;

	for (int i = 0; i < base; i++) {
		if (i < n) {
			memo[base + i] = (1 << toi[str[index][i]]);
			seg[base + i] = ((t0[i] == str[index][i]) ? 1 : 0);
		} else {
			memo[base + i] = 0;
			seg[base + i] = 1;
		}
		lazy[base + i] = -1;
	}
	for (int i = base - 1; i; i--) {
		memo[i] = (memo[i * 2] | memo[i * 2 + 1]);
		seg[i] = (seg[i * 2] & seg[i * 2 + 1]);
		lazy[i] = -1;
	}

	int ti = 0;
	while (true) {
		if (find(0, base)) {
			result[ti] = 1;
		}
		if (ti == q) break;

		update(l[ti], r[ti], (1 << toi[c[ti]]));
		ti++;
	}
}

int main (void) {
	scanf("%d", &n);
	scanf("%s", sa);
	scanf("%s", sb);
	scanf("%s", sc);

	scanf("%d", &q);
	scanf("%s", t0);
	for (int i = 0; i < q; i++) {
		scanf("%d%d %c", &l[i], &r[i], &c[i]);
		l[i]--;
	}


	char toc[3] = {'J', 'O', 'I'};
	int toi[128] = {0};
	toi['J'] = 0;
	toi['O'] = 1;
	toi['I'] = 2;

	slen = 9;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			int ki = (6 + 1 - i - j) % 3;

			for (int li = 0; li < n; li++) {
				int sum = 0;
				sum += toi[sa[li]] * i;
				sum += toi[sb[li]] * j;
				sum += toi[sc[li]] * ki;

				str[i * 3 + j][li] = toc[sum %= 3];
			}
		}
	}

	for (int i = 0; i < slen; i++) {
		func(i);
	}
	for (int i = 0; i <= q; i++) {
		puts(result[i] ? "Yes" : "No");
	}

	return 0;
}

Compilation message

Main.cpp: In function 'void func(int)':
Main.cpp:85:43: warning: array subscript has type 'char' [-Wchar-subscripts]
   85 |    memo[base + i] = (1 << toi[str[index][i]]);
      |                               ~~~~~~~~~~~~^
Main.cpp:106:38: warning: array subscript has type 'char' [-Wchar-subscripts]
  106 |   update(l[ti], r[ti], (1 << toi[c[ti]]));
      |                                  ~~~~^
Main.cpp:77:7: warning: unused variable 'toc' [-Wunused-variable]
   77 |  char toc[3] = {'J', 'O', 'I'};
      |       ^~~
Main.cpp: In function 'int main()':
Main.cpp:138:21: warning: array subscript has type 'char' [-Wchar-subscripts]
  138 |     sum += toi[sa[li]] * i;
      |                ~~~~~^
Main.cpp:139:21: warning: array subscript has type 'char' [-Wchar-subscripts]
  139 |     sum += toi[sb[li]] * j;
      |                ~~~~~^
Main.cpp:140:21: warning: array subscript has type 'char' [-Wchar-subscripts]
  140 |     sum += toi[sc[li]] * ki;
      |                ~~~~~^
Main.cpp:112:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
Main.cpp:113:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |  scanf("%s", sa);
      |  ~~~~~^~~~~~~~~~
Main.cpp:114:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |  scanf("%s", sb);
      |  ~~~~~^~~~~~~~~~
Main.cpp:115:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |  scanf("%s", sc);
      |  ~~~~~^~~~~~~~~~
Main.cpp:117:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:118:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |  scanf("%s", t0);
      |  ~~~~~^~~~~~~~~~
Main.cpp:120:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |   scanf("%d%d %c", &l[i], &r[i], &c[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 675 ms 14788 KB Output is correct
2 Correct 747 ms 14912 KB Output is correct
3 Correct 836 ms 14912 KB Output is correct
4 Correct 675 ms 15052 KB Output is correct
5 Correct 652 ms 15044 KB Output is correct
6 Correct 651 ms 15004 KB Output is correct
7 Correct 682 ms 15084 KB Output is correct
8 Correct 673 ms 15120 KB Output is correct
9 Correct 686 ms 15108 KB Output is correct
10 Correct 679 ms 14916 KB Output is correct
11 Correct 685 ms 14912 KB Output is correct
12 Correct 695 ms 14924 KB Output is correct
13 Correct 693 ms 14912 KB Output is correct
14 Correct 679 ms 15016 KB Output is correct
15 Correct 741 ms 14936 KB Output is correct
16 Correct 680 ms 14912 KB Output is correct
17 Correct 685 ms 14916 KB Output is correct
18 Correct 794 ms 15120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 675 ms 14788 KB Output is correct
2 Correct 747 ms 14912 KB Output is correct
3 Correct 836 ms 14912 KB Output is correct
4 Correct 675 ms 15052 KB Output is correct
5 Correct 652 ms 15044 KB Output is correct
6 Correct 651 ms 15004 KB Output is correct
7 Correct 682 ms 15084 KB Output is correct
8 Correct 673 ms 15120 KB Output is correct
9 Correct 686 ms 15108 KB Output is correct
10 Correct 679 ms 14916 KB Output is correct
11 Correct 685 ms 14912 KB Output is correct
12 Correct 695 ms 14924 KB Output is correct
13 Correct 693 ms 14912 KB Output is correct
14 Correct 679 ms 15016 KB Output is correct
15 Correct 741 ms 14936 KB Output is correct
16 Correct 680 ms 14912 KB Output is correct
17 Correct 685 ms 14916 KB Output is correct
18 Correct 794 ms 15120 KB Output is correct
19 Correct 2322 ms 17444 KB Output is correct
20 Correct 1880 ms 17448 KB Output is correct
21 Correct 1389 ms 17216 KB Output is correct
22 Correct 1556 ms 16936 KB Output is correct
23 Correct 904 ms 15160 KB Output is correct
24 Correct 901 ms 15120 KB Output is correct
25 Correct 1397 ms 17500 KB Output is correct
26 Correct 1615 ms 17452 KB Output is correct
27 Correct 1813 ms 17600 KB Output is correct
28 Correct 1941 ms 17568 KB Output is correct
29 Correct 1542 ms 17464 KB Output is correct
30 Correct 1065 ms 15232 KB Output is correct
31 Correct 1619 ms 17580 KB Output is correct
32 Correct 1767 ms 17228 KB Output is correct
33 Correct 947 ms 15120 KB Output is correct
34 Correct 1793 ms 17580 KB Output is correct
35 Correct 1386 ms 16688 KB Output is correct
36 Correct 909 ms 15032 KB Output is correct
37 Correct 945 ms 15032 KB Output is correct
38 Correct 1586 ms 17652 KB Output is correct
39 Correct 791 ms 17644 KB Output is correct
40 Correct 1402 ms 16576 KB Output is correct
41 Correct 2700 ms 17848 KB Output is correct
42 Correct 479 ms 17920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 675 ms 14788 KB Output is correct
2 Correct 747 ms 14912 KB Output is correct
3 Correct 836 ms 14912 KB Output is correct
4 Correct 675 ms 15052 KB Output is correct
5 Correct 652 ms 15044 KB Output is correct
6 Correct 651 ms 15004 KB Output is correct
7 Correct 682 ms 15084 KB Output is correct
8 Correct 673 ms 15120 KB Output is correct
9 Correct 686 ms 15108 KB Output is correct
10 Correct 679 ms 14916 KB Output is correct
11 Correct 685 ms 14912 KB Output is correct
12 Correct 695 ms 14924 KB Output is correct
13 Correct 693 ms 14912 KB Output is correct
14 Correct 679 ms 15016 KB Output is correct
15 Correct 741 ms 14936 KB Output is correct
16 Correct 680 ms 14912 KB Output is correct
17 Correct 685 ms 14916 KB Output is correct
18 Correct 794 ms 15120 KB Output is correct
19 Correct 755 ms 14916 KB Output is correct
20 Correct 821 ms 14908 KB Output is correct
21 Correct 680 ms 15108 KB Output is correct
22 Correct 644 ms 14944 KB Output is correct
23 Correct 686 ms 15112 KB Output is correct
24 Correct 665 ms 15052 KB Output is correct
25 Correct 737 ms 15188 KB Output is correct
26 Correct 677 ms 15044 KB Output is correct
27 Correct 701 ms 15136 KB Output is correct
28 Correct 677 ms 14936 KB Output is correct
29 Correct 688 ms 15172 KB Output is correct
30 Correct 676 ms 14976 KB Output is correct
31 Correct 664 ms 15172 KB Output is correct
32 Correct 682 ms 15144 KB Output is correct
33 Correct 695 ms 15168 KB Output is correct
34 Correct 642 ms 15108 KB Output is correct
35 Correct 727 ms 14996 KB Output is correct
36 Correct 745 ms 14916 KB Output is correct
37 Correct 727 ms 14916 KB Output is correct
38 Correct 686 ms 14976 KB Output is correct
39 Correct 688 ms 14916 KB Output is correct
40 Correct 706 ms 14916 KB Output is correct
41 Correct 704 ms 14912 KB Output is correct
42 Correct 684 ms 14936 KB Output is correct
43 Correct 680 ms 15084 KB Output is correct
44 Correct 700 ms 15172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 675 ms 14788 KB Output is correct
2 Correct 747 ms 14912 KB Output is correct
3 Correct 836 ms 14912 KB Output is correct
4 Correct 675 ms 15052 KB Output is correct
5 Correct 652 ms 15044 KB Output is correct
6 Correct 651 ms 15004 KB Output is correct
7 Correct 682 ms 15084 KB Output is correct
8 Correct 673 ms 15120 KB Output is correct
9 Correct 686 ms 15108 KB Output is correct
10 Correct 679 ms 14916 KB Output is correct
11 Correct 685 ms 14912 KB Output is correct
12 Correct 695 ms 14924 KB Output is correct
13 Correct 693 ms 14912 KB Output is correct
14 Correct 679 ms 15016 KB Output is correct
15 Correct 741 ms 14936 KB Output is correct
16 Correct 680 ms 14912 KB Output is correct
17 Correct 685 ms 14916 KB Output is correct
18 Correct 794 ms 15120 KB Output is correct
19 Correct 2322 ms 17444 KB Output is correct
20 Correct 1880 ms 17448 KB Output is correct
21 Correct 1389 ms 17216 KB Output is correct
22 Correct 1556 ms 16936 KB Output is correct
23 Correct 904 ms 15160 KB Output is correct
24 Correct 901 ms 15120 KB Output is correct
25 Correct 1397 ms 17500 KB Output is correct
26 Correct 1615 ms 17452 KB Output is correct
27 Correct 1813 ms 17600 KB Output is correct
28 Correct 1941 ms 17568 KB Output is correct
29 Correct 1542 ms 17464 KB Output is correct
30 Correct 1065 ms 15232 KB Output is correct
31 Correct 1619 ms 17580 KB Output is correct
32 Correct 1767 ms 17228 KB Output is correct
33 Correct 947 ms 15120 KB Output is correct
34 Correct 1793 ms 17580 KB Output is correct
35 Correct 1386 ms 16688 KB Output is correct
36 Correct 909 ms 15032 KB Output is correct
37 Correct 945 ms 15032 KB Output is correct
38 Correct 1586 ms 17652 KB Output is correct
39 Correct 791 ms 17644 KB Output is correct
40 Correct 1402 ms 16576 KB Output is correct
41 Correct 2700 ms 17848 KB Output is correct
42 Correct 479 ms 17920 KB Output is correct
43 Correct 755 ms 14916 KB Output is correct
44 Correct 821 ms 14908 KB Output is correct
45 Correct 680 ms 15108 KB Output is correct
46 Correct 644 ms 14944 KB Output is correct
47 Correct 686 ms 15112 KB Output is correct
48 Correct 665 ms 15052 KB Output is correct
49 Correct 737 ms 15188 KB Output is correct
50 Correct 677 ms 15044 KB Output is correct
51 Correct 701 ms 15136 KB Output is correct
52 Correct 677 ms 14936 KB Output is correct
53 Correct 688 ms 15172 KB Output is correct
54 Correct 676 ms 14976 KB Output is correct
55 Correct 664 ms 15172 KB Output is correct
56 Correct 682 ms 15144 KB Output is correct
57 Correct 695 ms 15168 KB Output is correct
58 Correct 642 ms 15108 KB Output is correct
59 Correct 727 ms 14996 KB Output is correct
60 Correct 745 ms 14916 KB Output is correct
61 Correct 727 ms 14916 KB Output is correct
62 Correct 686 ms 14976 KB Output is correct
63 Correct 688 ms 14916 KB Output is correct
64 Correct 706 ms 14916 KB Output is correct
65 Correct 704 ms 14912 KB Output is correct
66 Correct 684 ms 14936 KB Output is correct
67 Correct 680 ms 15084 KB Output is correct
68 Correct 700 ms 15172 KB Output is correct
69 Correct 2133 ms 16884 KB Output is correct
70 Correct 1945 ms 17452 KB Output is correct
71 Correct 904 ms 15116 KB Output is correct
72 Correct 981 ms 15112 KB Output is correct
73 Correct 940 ms 15080 KB Output is correct
74 Correct 1271 ms 16900 KB Output is correct
75 Correct 880 ms 15172 KB Output is correct
76 Correct 1447 ms 17460 KB Output is correct
77 Correct 1459 ms 16952 KB Output is correct
78 Correct 891 ms 15116 KB Output is correct
79 Correct 917 ms 15124 KB Output is correct
80 Correct 1324 ms 16580 KB Output is correct
81 Correct 884 ms 15208 KB Output is correct
82 Correct 1511 ms 17656 KB Output is correct
83 Correct 1688 ms 17220 KB Output is correct
84 Correct 889 ms 15196 KB Output is correct
85 Correct 890 ms 15196 KB Output is correct
86 Correct 1639 ms 16912 KB Output is correct
87 Correct 1711 ms 17616 KB Output is correct
88 Correct 969 ms 15180 KB Output is correct
89 Correct 1584 ms 17172 KB Output is correct
90 Correct 1681 ms 17732 KB Output is correct
91 Correct 964 ms 15316 KB Output is correct
92 Correct 1254 ms 16696 KB Output is correct
93 Correct 888 ms 15044 KB Output is correct
94 Correct 901 ms 15044 KB Output is correct
95 Correct 875 ms 15116 KB Output is correct
96 Correct 1549 ms 17652 KB Output is correct
97 Correct 746 ms 17644 KB Output is correct
98 Correct 1422 ms 16584 KB Output is correct
99 Correct 2514 ms 17904 KB Output is correct
100 Correct 483 ms 17936 KB Output is correct