Submission #423433

# Submission time Handle Problem Language Result Execution time Memory
423433 2021-06-11T06:04:51 Z 송준혁(#7517) Crossing (JOI21_crossing) C++17
100 / 100
660 ms 38724 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define MOD 1000000007
#define INF (1ll<<62)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, Q;
int A[202020][10], S[202020];
int X[808080][10], lz[808080];
bool T[808080][10];

void init(int id, int s, int e){
	if (s == e){
		for (int i=0; i<9; i++) X[id][i] = A[s][i];
		for (int i=0; i<9; i++) if (X[id][i] == S[s]) T[id][i] = true;
		return;
	}
	int m=s+e>>1;
	init(id*2, s, m), init(id*2+1, m+1, e);
	for (int i=0; i<9; i++){
		T[id][i] = T[id*2][i] && T[id*2+1][i];
		if (X[id*2][i] == X[id*2+1][i]) X[id][i] = X[id*2][i];
		else X[id][i] = -1;
	}
}

void busy(int id){
	if (lz[id] < 0) return;
	for (int i=0; i<9; i++){
		T[id*2][i] = (X[id*2][i] == lz[id]);
		T[id*2+1][i] = (X[id*2+1][i] == lz[id]);
	}
	lz[id*2] = lz[id*2+1] = lz[id];
	lz[id] = -1;
}

void upd(int id, int s, int e, int ts, int te, int v){
	if (e < ts || te < s) return;
	if (ts <= s && e <= te){
		for (int i=0; i<9; i++) T[id][i] = (X[id][i] == v);
		lz[id] = v;
		return;
	}
	busy(id);
	int m=s+e>>1;
	upd(id*2, s, m, ts, te, v);
	upd(id*2+1, m+1, e, ts, te, v);
	for (int i=0; i<9; i++) T[id][i] = T[id*2][i] && T[id*2+1][i];
}

int main(){
	char ch;
	scanf("%d", &N);
	for (int i=1; i<=N; i++){
		scanf(" %c", &ch);
		if (ch == 'J') A[i][0] = 0;
		if (ch == 'O') A[i][0] = 1;
		if (ch == 'I') A[i][0] = 2;
	}
	for (int i=1; i<=N; i++){
		scanf(" %c", &ch);
		if (ch == 'J') A[i][1] = 0;
		if (ch == 'O') A[i][1] = 1;
		if (ch == 'I') A[i][1] = 2;
	}
	for (int i=1; i<=N; i++){
		scanf(" %c", &ch);
		if (ch == 'J') A[i][2] = 0;
		if (ch == 'O') A[i][2] = 1;
		if (ch == 'I') A[i][2] = 2;
	}
	for (int i=1; i<=N; i++) A[i][3] = (2*A[i][0] + 1*A[i][1] + 1*A[i][2])%3;
	for (int i=1; i<=N; i++) A[i][4] = (1*A[i][0] + 2*A[i][1] + 1*A[i][2])%3;
	for (int i=1; i<=N; i++) A[i][5] = (1*A[i][0] + 1*A[i][1] + 2*A[i][2])%3;
	for (int i=1; i<=N; i++) A[i][6] = (0*A[i][0] + 2*A[i][1] + 2*A[i][2])%3;
	for (int i=1; i<=N; i++) A[i][7] = (2*A[i][0] + 0*A[i][1] + 2*A[i][2])%3;
	for (int i=1; i<=N; i++) A[i][8] = (2*A[i][0] + 2*A[i][1] + 0*A[i][2])%3;
	scanf("%d", &Q);
	for (int i=1; i<=N; i++){
		scanf(" %c", &ch);
		if (ch == 'J') S[i] = 0;
		if (ch == 'O') S[i] = 1;
		if (ch == 'I') S[i] = 2;
	}
	memset(lz, -1, sizeof lz);
	init(1, 1, N);
	bool tf=false;
	for (int i=0; i<9; i++) tf = tf || T[1][i];
	puts(tf?"Yes":"No");
	while (Q--){
		int l, r, v;
		scanf("%d %d %c", &l, &r, &ch);
		if (ch == 'J') v = 0;
		if (ch == 'O') v = 1;
		if (ch == 'I') v = 2;
		upd(1, 1, N, l, r, v);
		tf = false;
		for (int i=0; i<9; i++) tf = tf || T[1][i];
		puts(tf?"Yes":"No");
	}
	return 0;
}

Compilation message

Main.cpp: In function 'void init(int, int, int)':
Main.cpp:23:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |  int m=s+e>>1;
      |        ~^~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:50:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |  int m=s+e>>1;
      |        ~^~
Main.cpp: In function 'int main()':
Main.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Main.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf(" %c", &ch);
      |   ~~~~~^~~~~~~~~~~~
Main.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf(" %c", &ch);
      |   ~~~~~^~~~~~~~~~~~
Main.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |   scanf(" %c", &ch);
      |   ~~~~~^~~~~~~~~~~~
Main.cpp:83:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |   scanf(" %c", &ch);
      |   ~~~~~^~~~~~~~~~~~
Main.cpp:97:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |   scanf("%d %d %c", &l, &r, &ch);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:96:13: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |   int l, r, v;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4060 KB Output is correct
2 Correct 125 ms 4060 KB Output is correct
3 Correct 129 ms 4032 KB Output is correct
4 Correct 113 ms 4036 KB Output is correct
5 Correct 108 ms 3960 KB Output is correct
6 Correct 108 ms 4080 KB Output is correct
7 Correct 109 ms 4008 KB Output is correct
8 Correct 110 ms 4036 KB Output is correct
9 Correct 113 ms 4024 KB Output is correct
10 Correct 112 ms 4012 KB Output is correct
11 Correct 111 ms 4036 KB Output is correct
12 Correct 109 ms 4088 KB Output is correct
13 Correct 114 ms 3992 KB Output is correct
14 Correct 111 ms 4012 KB Output is correct
15 Correct 114 ms 3996 KB Output is correct
16 Correct 123 ms 4040 KB Output is correct
17 Correct 110 ms 4064 KB Output is correct
18 Correct 124 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4060 KB Output is correct
2 Correct 125 ms 4060 KB Output is correct
3 Correct 129 ms 4032 KB Output is correct
4 Correct 113 ms 4036 KB Output is correct
5 Correct 108 ms 3960 KB Output is correct
6 Correct 108 ms 4080 KB Output is correct
7 Correct 109 ms 4008 KB Output is correct
8 Correct 110 ms 4036 KB Output is correct
9 Correct 113 ms 4024 KB Output is correct
10 Correct 112 ms 4012 KB Output is correct
11 Correct 111 ms 4036 KB Output is correct
12 Correct 109 ms 4088 KB Output is correct
13 Correct 114 ms 3992 KB Output is correct
14 Correct 111 ms 4012 KB Output is correct
15 Correct 114 ms 3996 KB Output is correct
16 Correct 123 ms 4040 KB Output is correct
17 Correct 110 ms 4064 KB Output is correct
18 Correct 124 ms 4036 KB Output is correct
19 Correct 572 ms 38256 KB Output is correct
20 Correct 492 ms 38208 KB Output is correct
21 Correct 337 ms 37700 KB Output is correct
22 Correct 357 ms 37060 KB Output is correct
23 Correct 185 ms 6108 KB Output is correct
24 Correct 180 ms 6048 KB Output is correct
25 Correct 406 ms 38312 KB Output is correct
26 Correct 393 ms 38272 KB Output is correct
27 Correct 442 ms 38260 KB Output is correct
28 Correct 461 ms 38236 KB Output is correct
29 Correct 413 ms 38108 KB Output is correct
30 Correct 208 ms 6024 KB Output is correct
31 Correct 436 ms 38304 KB Output is correct
32 Correct 419 ms 37556 KB Output is correct
33 Correct 182 ms 6084 KB Output is correct
34 Correct 471 ms 38296 KB Output is correct
35 Correct 327 ms 36060 KB Output is correct
36 Correct 189 ms 6036 KB Output is correct
37 Correct 181 ms 6084 KB Output is correct
38 Correct 418 ms 38316 KB Output is correct
39 Correct 249 ms 38316 KB Output is correct
40 Correct 319 ms 22512 KB Output is correct
41 Correct 588 ms 38476 KB Output is correct
42 Correct 153 ms 38468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4060 KB Output is correct
2 Correct 125 ms 4060 KB Output is correct
3 Correct 129 ms 4032 KB Output is correct
4 Correct 113 ms 4036 KB Output is correct
5 Correct 108 ms 3960 KB Output is correct
6 Correct 108 ms 4080 KB Output is correct
7 Correct 109 ms 4008 KB Output is correct
8 Correct 110 ms 4036 KB Output is correct
9 Correct 113 ms 4024 KB Output is correct
10 Correct 112 ms 4012 KB Output is correct
11 Correct 111 ms 4036 KB Output is correct
12 Correct 109 ms 4088 KB Output is correct
13 Correct 114 ms 3992 KB Output is correct
14 Correct 111 ms 4012 KB Output is correct
15 Correct 114 ms 3996 KB Output is correct
16 Correct 123 ms 4040 KB Output is correct
17 Correct 110 ms 4064 KB Output is correct
18 Correct 124 ms 4036 KB Output is correct
19 Correct 125 ms 4020 KB Output is correct
20 Correct 137 ms 4036 KB Output is correct
21 Correct 112 ms 4052 KB Output is correct
22 Correct 100 ms 4036 KB Output is correct
23 Correct 112 ms 4072 KB Output is correct
24 Correct 108 ms 4040 KB Output is correct
25 Correct 113 ms 4080 KB Output is correct
26 Correct 105 ms 4056 KB Output is correct
27 Correct 121 ms 4032 KB Output is correct
28 Correct 109 ms 3972 KB Output is correct
29 Correct 114 ms 4032 KB Output is correct
30 Correct 103 ms 4024 KB Output is correct
31 Correct 116 ms 3968 KB Output is correct
32 Correct 118 ms 4088 KB Output is correct
33 Correct 120 ms 4164 KB Output is correct
34 Correct 106 ms 4004 KB Output is correct
35 Correct 115 ms 4048 KB Output is correct
36 Correct 123 ms 4016 KB Output is correct
37 Correct 118 ms 4000 KB Output is correct
38 Correct 119 ms 4072 KB Output is correct
39 Correct 120 ms 4036 KB Output is correct
40 Correct 126 ms 4020 KB Output is correct
41 Correct 128 ms 4096 KB Output is correct
42 Correct 123 ms 4028 KB Output is correct
43 Correct 111 ms 3996 KB Output is correct
44 Correct 123 ms 4036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4060 KB Output is correct
2 Correct 125 ms 4060 KB Output is correct
3 Correct 129 ms 4032 KB Output is correct
4 Correct 113 ms 4036 KB Output is correct
5 Correct 108 ms 3960 KB Output is correct
6 Correct 108 ms 4080 KB Output is correct
7 Correct 109 ms 4008 KB Output is correct
8 Correct 110 ms 4036 KB Output is correct
9 Correct 113 ms 4024 KB Output is correct
10 Correct 112 ms 4012 KB Output is correct
11 Correct 111 ms 4036 KB Output is correct
12 Correct 109 ms 4088 KB Output is correct
13 Correct 114 ms 3992 KB Output is correct
14 Correct 111 ms 4012 KB Output is correct
15 Correct 114 ms 3996 KB Output is correct
16 Correct 123 ms 4040 KB Output is correct
17 Correct 110 ms 4064 KB Output is correct
18 Correct 124 ms 4036 KB Output is correct
19 Correct 572 ms 38256 KB Output is correct
20 Correct 492 ms 38208 KB Output is correct
21 Correct 337 ms 37700 KB Output is correct
22 Correct 357 ms 37060 KB Output is correct
23 Correct 185 ms 6108 KB Output is correct
24 Correct 180 ms 6048 KB Output is correct
25 Correct 406 ms 38312 KB Output is correct
26 Correct 393 ms 38272 KB Output is correct
27 Correct 442 ms 38260 KB Output is correct
28 Correct 461 ms 38236 KB Output is correct
29 Correct 413 ms 38108 KB Output is correct
30 Correct 208 ms 6024 KB Output is correct
31 Correct 436 ms 38304 KB Output is correct
32 Correct 419 ms 37556 KB Output is correct
33 Correct 182 ms 6084 KB Output is correct
34 Correct 471 ms 38296 KB Output is correct
35 Correct 327 ms 36060 KB Output is correct
36 Correct 189 ms 6036 KB Output is correct
37 Correct 181 ms 6084 KB Output is correct
38 Correct 418 ms 38316 KB Output is correct
39 Correct 249 ms 38316 KB Output is correct
40 Correct 319 ms 22512 KB Output is correct
41 Correct 588 ms 38476 KB Output is correct
42 Correct 153 ms 38468 KB Output is correct
43 Correct 125 ms 4020 KB Output is correct
44 Correct 137 ms 4036 KB Output is correct
45 Correct 112 ms 4052 KB Output is correct
46 Correct 100 ms 4036 KB Output is correct
47 Correct 112 ms 4072 KB Output is correct
48 Correct 108 ms 4040 KB Output is correct
49 Correct 113 ms 4080 KB Output is correct
50 Correct 105 ms 4056 KB Output is correct
51 Correct 121 ms 4032 KB Output is correct
52 Correct 109 ms 3972 KB Output is correct
53 Correct 114 ms 4032 KB Output is correct
54 Correct 103 ms 4024 KB Output is correct
55 Correct 116 ms 3968 KB Output is correct
56 Correct 118 ms 4088 KB Output is correct
57 Correct 120 ms 4164 KB Output is correct
58 Correct 106 ms 4004 KB Output is correct
59 Correct 115 ms 4048 KB Output is correct
60 Correct 123 ms 4016 KB Output is correct
61 Correct 118 ms 4000 KB Output is correct
62 Correct 119 ms 4072 KB Output is correct
63 Correct 120 ms 4036 KB Output is correct
64 Correct 126 ms 4020 KB Output is correct
65 Correct 128 ms 4096 KB Output is correct
66 Correct 123 ms 4028 KB Output is correct
67 Correct 111 ms 3996 KB Output is correct
68 Correct 123 ms 4036 KB Output is correct
69 Correct 496 ms 36868 KB Output is correct
70 Correct 499 ms 38320 KB Output is correct
71 Correct 187 ms 6072 KB Output is correct
72 Correct 185 ms 6080 KB Output is correct
73 Correct 186 ms 6084 KB Output is correct
74 Correct 364 ms 36812 KB Output is correct
75 Correct 183 ms 6104 KB Output is correct
76 Correct 367 ms 38212 KB Output is correct
77 Correct 367 ms 36864 KB Output is correct
78 Correct 182 ms 6136 KB Output is correct
79 Correct 188 ms 6112 KB Output is correct
80 Correct 338 ms 35812 KB Output is correct
81 Correct 185 ms 6004 KB Output is correct
82 Correct 409 ms 38304 KB Output is correct
83 Correct 395 ms 37712 KB Output is correct
84 Correct 185 ms 6084 KB Output is correct
85 Correct 188 ms 6084 KB Output is correct
86 Correct 443 ms 36292 KB Output is correct
87 Correct 487 ms 38312 KB Output is correct
88 Correct 221 ms 6080 KB Output is correct
89 Correct 426 ms 37268 KB Output is correct
90 Correct 451 ms 38308 KB Output is correct
91 Correct 225 ms 6084 KB Output is correct
92 Correct 323 ms 36088 KB Output is correct
93 Correct 184 ms 6084 KB Output is correct
94 Correct 189 ms 6080 KB Output is correct
95 Correct 215 ms 6116 KB Output is correct
96 Correct 431 ms 38348 KB Output is correct
97 Correct 276 ms 38268 KB Output is correct
98 Correct 335 ms 22616 KB Output is correct
99 Correct 660 ms 38724 KB Output is correct
100 Correct 172 ms 38480 KB Output is correct