답안 #440426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
440426 2021-07-02T09:07:40 Z Sohsoh84 Crossing (JOI21_crossing) C++14
100 / 100
683 ms 40552 KB
// ¯\_(ツ)_/¯
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)                      (x).begin(),(x).end()
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

vector<array<int, 3>> C = {
	{1, 0, 0},
	{0, 1, 0},
	{0, 0, 1},
	{2, 2, 0},
	{2, 0, 2},
	{0, 2, 2},
	{2, 1, 1},
	{1, 2, 1},
	{1, 1, 2}
};

int A[MAXN][9], n, q, T[MAXN][9], S[MAXN], lz[MAXN];
bool sg[MAXN][9];
string s1, s2, s3, s;

int Cnv(char c) {
	if (c == 'J') return 0;
	if (c == 'O') return 1;
	return 2;
}

void Build(int v, int L, int R) {
	if (L == R) {
		for (int j = 0; j < 9; j++) {
			T[v][j] = A[L][j];
			if (S[L] == A[L][j]) sg[v][j] = true;
		}

		return;
	}

	int mid = (L + R) >> 1;
	Build(v << 1, L, mid);
	Build(v << 1 | 1, mid + 1, R);
	
	for (int i = 0; i < 9; i++) {
		if (T[v << 1][i] == T[v << 1 | 1][i]) T[v][i] = T[v << 1][i];
		else T[v][i] = 4;
		sg[v][i] = sg[v << 1][i] & sg[v << 1 | 1][i];
	}
}

inline void Push(int v) {
	if (lz[v] < 0) return;
	for (int i = 0; i < 9; i++) sg[v][i] = (T[v][i] == lz[v]);
	
	if ((v << 1 | 1) < MAXN) lz[v << 1] = lz[v << 1 | 1] = lz[v];
	lz[v] = -1;
}

void Update(int v, int L, int R, int QL, int QR, int val) {
	Push(v);
	if (QR < QL) return;
	if (QL == L && QR == R) {
		lz[v] = val;
		Push(v);
		return;
	}

	int mid = (L + R) >> 1;
	Update(v << 1, L, mid, QL, min(QR, mid), val);
	Update(v << 1 | 1, mid + 1, R, max(QL, mid + 1), QR, val);
	for (int i = 0; i < 9; i++) sg[v][i] = sg[v << 1][i] & sg[v << 1 | 1][i];
}

inline int Print() {
	for (int i = 0; i < 9; i++) 
		if (sg[1][i])
			return cout << "Yes" << endl, 0;
	return cout << "No" << endl, 0;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s1 >> s2 >> s3;
	for (int i = 1; i <= n; i++) {
		int a[3] = {Cnv(s1[i - 1]), Cnv(s2[i - 1]), Cnv(s3[i - 1])};
		for (int j = 0; j < 9; j++) {
			for (int k = 0; k < 3; k++) A[i][j] += C[j][k] * a[k];
			A[i][j] %= 3;
		}
	}

	cin >> q >> s;
	for (int i = 1; i <= n; i++) S[i] = Cnv(s[i - 1]);	
	Build(1, 1, n);
	fill(lz, lz + MAXN, -1);

	Print();
	while (q--) {
		int L, R;
		char c;
		cin >> L >> R >> c;
		Update(1, 1, n, L, R, Cnv(c));	
		Print();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 6228 KB Output is correct
2 Correct 122 ms 6344 KB Output is correct
3 Correct 130 ms 6244 KB Output is correct
4 Correct 99 ms 6296 KB Output is correct
5 Correct 100 ms 6212 KB Output is correct
6 Correct 99 ms 6156 KB Output is correct
7 Correct 99 ms 6240 KB Output is correct
8 Correct 111 ms 6328 KB Output is correct
9 Correct 130 ms 6352 KB Output is correct
10 Correct 105 ms 6392 KB Output is correct
11 Correct 110 ms 6372 KB Output is correct
12 Correct 108 ms 6396 KB Output is correct
13 Correct 108 ms 6364 KB Output is correct
14 Correct 102 ms 6500 KB Output is correct
15 Correct 106 ms 6276 KB Output is correct
16 Correct 107 ms 6340 KB Output is correct
17 Correct 106 ms 6344 KB Output is correct
18 Correct 118 ms 6248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 6228 KB Output is correct
2 Correct 122 ms 6344 KB Output is correct
3 Correct 130 ms 6244 KB Output is correct
4 Correct 99 ms 6296 KB Output is correct
5 Correct 100 ms 6212 KB Output is correct
6 Correct 99 ms 6156 KB Output is correct
7 Correct 99 ms 6240 KB Output is correct
8 Correct 111 ms 6328 KB Output is correct
9 Correct 130 ms 6352 KB Output is correct
10 Correct 105 ms 6392 KB Output is correct
11 Correct 110 ms 6372 KB Output is correct
12 Correct 108 ms 6396 KB Output is correct
13 Correct 108 ms 6364 KB Output is correct
14 Correct 102 ms 6500 KB Output is correct
15 Correct 106 ms 6276 KB Output is correct
16 Correct 107 ms 6340 KB Output is correct
17 Correct 106 ms 6344 KB Output is correct
18 Correct 118 ms 6248 KB Output is correct
19 Correct 494 ms 40312 KB Output is correct
20 Correct 435 ms 40212 KB Output is correct
21 Correct 299 ms 39620 KB Output is correct
22 Correct 336 ms 38644 KB Output is correct
23 Correct 171 ms 9028 KB Output is correct
24 Correct 167 ms 8980 KB Output is correct
25 Correct 358 ms 40296 KB Output is correct
26 Correct 367 ms 40340 KB Output is correct
27 Correct 370 ms 40344 KB Output is correct
28 Correct 465 ms 40328 KB Output is correct
29 Correct 365 ms 40120 KB Output is correct
30 Correct 243 ms 9028 KB Output is correct
31 Correct 348 ms 40292 KB Output is correct
32 Correct 371 ms 39324 KB Output is correct
33 Correct 175 ms 8952 KB Output is correct
34 Correct 481 ms 40392 KB Output is correct
35 Correct 283 ms 37760 KB Output is correct
36 Correct 166 ms 9000 KB Output is correct
37 Correct 163 ms 9024 KB Output is correct
38 Correct 383 ms 40180 KB Output is correct
39 Correct 209 ms 40404 KB Output is correct
40 Correct 295 ms 25488 KB Output is correct
41 Correct 625 ms 40496 KB Output is correct
42 Correct 89 ms 39700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 6228 KB Output is correct
2 Correct 122 ms 6344 KB Output is correct
3 Correct 130 ms 6244 KB Output is correct
4 Correct 99 ms 6296 KB Output is correct
5 Correct 100 ms 6212 KB Output is correct
6 Correct 99 ms 6156 KB Output is correct
7 Correct 99 ms 6240 KB Output is correct
8 Correct 111 ms 6328 KB Output is correct
9 Correct 130 ms 6352 KB Output is correct
10 Correct 105 ms 6392 KB Output is correct
11 Correct 110 ms 6372 KB Output is correct
12 Correct 108 ms 6396 KB Output is correct
13 Correct 108 ms 6364 KB Output is correct
14 Correct 102 ms 6500 KB Output is correct
15 Correct 106 ms 6276 KB Output is correct
16 Correct 107 ms 6340 KB Output is correct
17 Correct 106 ms 6344 KB Output is correct
18 Correct 118 ms 6248 KB Output is correct
19 Correct 114 ms 6280 KB Output is correct
20 Correct 128 ms 6248 KB Output is correct
21 Correct 103 ms 6356 KB Output is correct
22 Correct 94 ms 6084 KB Output is correct
23 Correct 109 ms 6320 KB Output is correct
24 Correct 100 ms 6280 KB Output is correct
25 Correct 104 ms 6340 KB Output is correct
26 Correct 96 ms 6256 KB Output is correct
27 Correct 107 ms 6316 KB Output is correct
28 Correct 96 ms 6088 KB Output is correct
29 Correct 108 ms 6288 KB Output is correct
30 Correct 92 ms 6216 KB Output is correct
31 Correct 107 ms 6468 KB Output is correct
32 Correct 105 ms 6316 KB Output is correct
33 Correct 106 ms 6340 KB Output is correct
34 Correct 98 ms 6116 KB Output is correct
35 Correct 104 ms 6376 KB Output is correct
36 Correct 113 ms 6340 KB Output is correct
37 Correct 106 ms 6372 KB Output is correct
38 Correct 106 ms 6340 KB Output is correct
39 Correct 107 ms 6304 KB Output is correct
40 Correct 109 ms 6356 KB Output is correct
41 Correct 105 ms 6276 KB Output is correct
42 Correct 109 ms 6316 KB Output is correct
43 Correct 102 ms 6300 KB Output is correct
44 Correct 107 ms 6408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 6228 KB Output is correct
2 Correct 122 ms 6344 KB Output is correct
3 Correct 130 ms 6244 KB Output is correct
4 Correct 99 ms 6296 KB Output is correct
5 Correct 100 ms 6212 KB Output is correct
6 Correct 99 ms 6156 KB Output is correct
7 Correct 99 ms 6240 KB Output is correct
8 Correct 111 ms 6328 KB Output is correct
9 Correct 130 ms 6352 KB Output is correct
10 Correct 105 ms 6392 KB Output is correct
11 Correct 110 ms 6372 KB Output is correct
12 Correct 108 ms 6396 KB Output is correct
13 Correct 108 ms 6364 KB Output is correct
14 Correct 102 ms 6500 KB Output is correct
15 Correct 106 ms 6276 KB Output is correct
16 Correct 107 ms 6340 KB Output is correct
17 Correct 106 ms 6344 KB Output is correct
18 Correct 118 ms 6248 KB Output is correct
19 Correct 494 ms 40312 KB Output is correct
20 Correct 435 ms 40212 KB Output is correct
21 Correct 299 ms 39620 KB Output is correct
22 Correct 336 ms 38644 KB Output is correct
23 Correct 171 ms 9028 KB Output is correct
24 Correct 167 ms 8980 KB Output is correct
25 Correct 358 ms 40296 KB Output is correct
26 Correct 367 ms 40340 KB Output is correct
27 Correct 370 ms 40344 KB Output is correct
28 Correct 465 ms 40328 KB Output is correct
29 Correct 365 ms 40120 KB Output is correct
30 Correct 243 ms 9028 KB Output is correct
31 Correct 348 ms 40292 KB Output is correct
32 Correct 371 ms 39324 KB Output is correct
33 Correct 175 ms 8952 KB Output is correct
34 Correct 481 ms 40392 KB Output is correct
35 Correct 283 ms 37760 KB Output is correct
36 Correct 166 ms 9000 KB Output is correct
37 Correct 163 ms 9024 KB Output is correct
38 Correct 383 ms 40180 KB Output is correct
39 Correct 209 ms 40404 KB Output is correct
40 Correct 295 ms 25488 KB Output is correct
41 Correct 625 ms 40496 KB Output is correct
42 Correct 89 ms 39700 KB Output is correct
43 Correct 114 ms 6280 KB Output is correct
44 Correct 128 ms 6248 KB Output is correct
45 Correct 103 ms 6356 KB Output is correct
46 Correct 94 ms 6084 KB Output is correct
47 Correct 109 ms 6320 KB Output is correct
48 Correct 100 ms 6280 KB Output is correct
49 Correct 104 ms 6340 KB Output is correct
50 Correct 96 ms 6256 KB Output is correct
51 Correct 107 ms 6316 KB Output is correct
52 Correct 96 ms 6088 KB Output is correct
53 Correct 108 ms 6288 KB Output is correct
54 Correct 92 ms 6216 KB Output is correct
55 Correct 107 ms 6468 KB Output is correct
56 Correct 105 ms 6316 KB Output is correct
57 Correct 106 ms 6340 KB Output is correct
58 Correct 98 ms 6116 KB Output is correct
59 Correct 104 ms 6376 KB Output is correct
60 Correct 113 ms 6340 KB Output is correct
61 Correct 106 ms 6372 KB Output is correct
62 Correct 106 ms 6340 KB Output is correct
63 Correct 107 ms 6304 KB Output is correct
64 Correct 109 ms 6356 KB Output is correct
65 Correct 105 ms 6276 KB Output is correct
66 Correct 109 ms 6316 KB Output is correct
67 Correct 102 ms 6300 KB Output is correct
68 Correct 107 ms 6408 KB Output is correct
69 Correct 486 ms 38544 KB Output is correct
70 Correct 440 ms 40172 KB Output is correct
71 Correct 183 ms 9084 KB Output is correct
72 Correct 169 ms 9112 KB Output is correct
73 Correct 184 ms 9156 KB Output is correct
74 Correct 289 ms 38512 KB Output is correct
75 Correct 164 ms 9028 KB Output is correct
76 Correct 318 ms 40332 KB Output is correct
77 Correct 323 ms 38596 KB Output is correct
78 Correct 172 ms 9092 KB Output is correct
79 Correct 170 ms 9312 KB Output is correct
80 Correct 285 ms 37312 KB Output is correct
81 Correct 177 ms 9156 KB Output is correct
82 Correct 315 ms 40300 KB Output is correct
83 Correct 335 ms 39724 KB Output is correct
84 Correct 169 ms 9040 KB Output is correct
85 Correct 186 ms 9000 KB Output is correct
86 Correct 336 ms 37728 KB Output is correct
87 Correct 425 ms 40320 KB Output is correct
88 Correct 196 ms 9024 KB Output is correct
89 Correct 340 ms 38892 KB Output is correct
90 Correct 379 ms 40364 KB Output is correct
91 Correct 181 ms 9156 KB Output is correct
92 Correct 293 ms 37676 KB Output is correct
93 Correct 172 ms 9088 KB Output is correct
94 Correct 172 ms 9028 KB Output is correct
95 Correct 174 ms 9028 KB Output is correct
96 Correct 392 ms 40124 KB Output is correct
97 Correct 233 ms 40340 KB Output is correct
98 Correct 335 ms 25476 KB Output is correct
99 Correct 683 ms 40552 KB Output is correct
100 Correct 121 ms 39740 KB Output is correct