답안 #670220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670220 2022-12-08T10:15:20 Z blue Crossing (JOI21_crossing) C++17
100 / 100
347 ms 38460 KB
#include <bits/stdc++.h>
using namespace std;

using vi = vector<int>;
using ll = long long;

const ll mod = 1'000'000'007LL;

const int mx = 200'000;

ll pr[1 + mx];
ll basehash[3][1 + mx];



ll mul(ll a, ll b)
{
	return (a * b) % mod;
}

ll ad(ll a, ll b)
{
	return (a + b) % mod;
}


int N;
vi A, B, C;
vi AB, BC, CA;
vi ABC, BCA, CAB;

int op(int a, int b)
{
	if(a == b)
		return a;
	else
		return 0 + 1 + 2 - a - b;
}

vi op(vi a, vi b)
{
	vi res;
	for(int i = 0; i < N; i++)
		res.push_back(op(a[i], b[i]));
	return res;
}

vi stv(string s)
{
	vi res(N);
	for(int i = 0; i < N; i++)
	{
		if(s[i] == 'J')
			res[i] = 0;
		else if(s[i] == 'O')
			res[i] = 1;
		else
			res[i] = 2;
	}
	return res;
}

ll gethash(vi a)
{
	ll res = 0;
	for(int i = 0; i < N; i++)
		res = ad(res, mul(pr[i], a[i]));
	return res;
}





vi T;


struct segtree
{
	int l;
	int r;

	ll hashval;
	bool homo; //homogenous
	int typ;

	segtree* left = NULL;
	segtree* right = NULL;

	segtree(int L, int R)
	{
		l = L;
		r = R;
		// cerr << "enter " << L << ' ' << R << '\n';
		if(L == R)
		{
			// cerr << "enter if\n";
			hashval = T[L];
			homo = 1;
			typ = T[L];
			// cerr << "check\n";
		}
		else
		{
			int m = (L + R) / 2;
			left = new segtree(L, m);
			right = new segtree(m+1, R);


			hashval = ad(left->hashval, mul(right->hashval, pr[left->r - left->l + 1]));
			homo = 0;
			typ = 0;
		}
		// cerr << "exit " << L << ' ' << R << " with hashval = " << hashval << '\n';
	}

	void update(int L, int R, int C)
	{
		if(R < l || r < L)
			return;
		else if(L <= l && r <= R)
		{
			hashval = basehash[C][r - l + 1];
			homo = 1;
			typ = C;
		}
		else
		{
			if(homo)
			{
				left->update(0, N-1, typ);
				right->update(0, N-1, typ);
			}

			left->update(L, R, C);
			right->update(L, R, C);

			hashval = ad(left->hashval, mul(right->hashval, pr[left->r - left->l + 1]));
			homo = 0;
			typ = 0;
		}

		// cerr << "after update hashval " << L << ' ' << R << " = " << hashval << '\n';
	}

};


// void out(vi a)
// {
// 	for(int u : a)
// 		cerr << u;
// 	cerr << '\n';
// }


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> N;

	pr[0] = 1;
	pr[1] = 11;
	for(int i = 2; i <= N; i++)
		pr[i] = mul(pr[1], pr[i-1]);


	basehash[0][0] = basehash[1][0] = basehash[2][0] = 0;
	for(int i = 1; i <= N; i++)
	{
		for(int c = 0; c < 3; c++)
			basehash[c][i] = ad(basehash[c][i-1], mul(pr[i-1], c));
	}


	string a, b, c;
	cin >> a >> b >> c;

	A = stv(a);
	B = stv(b);
	C = stv(c);
	AB = op(A, B);
	BC = op(B, C);
	CA = op(C, A);
	ABC = op(A, BC);
	BCA = op(B, CA);
	CAB = op(C, AB);

	// cerr << A << ' ' << B << ' ' << C << ' ' << AB << ' ' << BC << ' ' << CA << '\n';// << ' ' << ABC << ' ' << BCA << ' ' << CAB << '\n';

	// out(A);
	// out(B);
	// out(C);
	// out(AB);
	// out(BC);
	// out(CA);
	// out(ABC);
	// out(BCA);
	// out(CAB);

	set<ll> goodhash;
	for(vi f : {A, B, C, AB, BC, CA, ABC, BCA, CAB})
	{
		// cerr << "inserting " << gethash(f) << '\n';
		goodhash.insert(gethash(f));
	}

	int Q;
	cin >> Q;

	string t0;
	cin >> t0;

	T = stv(t0);

	// out(T);

	// cerr << "start segtree\n";
	segtree S(0, N-1);
	// cerr << "end segtree\n";

	// cerr << "check hash : " << S.hashval << '\n';

	if(goodhash.find(S.hashval) != goodhash.end())
		cout << "Yes\n";
	else
		cout << "No\n";


	for(int q = 1; q <= Q; q++)
	{
		int L, R, C;
		char c;
		cin >> L >> R >> c;
		L--;
		R--;
		if(c == 'J')
			C = 0;
		else if(c == 'O')
			C = 1;
		else
			C = 2;

		S.update(L, R, C);

		if(goodhash.find(S.hashval) != goodhash.end())
		cout << "Yes\n";
		else
			cout << "No\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 2252 KB Output is correct
2 Correct 69 ms 2472 KB Output is correct
3 Correct 65 ms 2256 KB Output is correct
4 Correct 61 ms 2404 KB Output is correct
5 Correct 56 ms 2388 KB Output is correct
6 Correct 58 ms 2316 KB Output is correct
7 Correct 58 ms 2452 KB Output is correct
8 Correct 59 ms 2412 KB Output is correct
9 Correct 65 ms 2484 KB Output is correct
10 Correct 65 ms 2384 KB Output is correct
11 Correct 60 ms 2480 KB Output is correct
12 Correct 61 ms 2420 KB Output is correct
13 Correct 69 ms 2564 KB Output is correct
14 Correct 59 ms 2384 KB Output is correct
15 Correct 60 ms 2408 KB Output is correct
16 Correct 63 ms 2380 KB Output is correct
17 Correct 60 ms 2444 KB Output is correct
18 Correct 69 ms 2400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 2252 KB Output is correct
2 Correct 69 ms 2472 KB Output is correct
3 Correct 65 ms 2256 KB Output is correct
4 Correct 61 ms 2404 KB Output is correct
5 Correct 56 ms 2388 KB Output is correct
6 Correct 58 ms 2316 KB Output is correct
7 Correct 58 ms 2452 KB Output is correct
8 Correct 59 ms 2412 KB Output is correct
9 Correct 65 ms 2484 KB Output is correct
10 Correct 65 ms 2384 KB Output is correct
11 Correct 60 ms 2480 KB Output is correct
12 Correct 61 ms 2420 KB Output is correct
13 Correct 69 ms 2564 KB Output is correct
14 Correct 59 ms 2384 KB Output is correct
15 Correct 60 ms 2408 KB Output is correct
16 Correct 63 ms 2380 KB Output is correct
17 Correct 60 ms 2444 KB Output is correct
18 Correct 69 ms 2400 KB Output is correct
19 Correct 347 ms 38312 KB Output is correct
20 Correct 254 ms 38372 KB Output is correct
21 Correct 213 ms 36124 KB Output is correct
22 Correct 212 ms 32740 KB Output is correct
23 Correct 107 ms 5160 KB Output is correct
24 Correct 106 ms 4980 KB Output is correct
25 Correct 234 ms 38300 KB Output is correct
26 Correct 249 ms 38312 KB Output is correct
27 Correct 244 ms 38296 KB Output is correct
28 Correct 269 ms 38336 KB Output is correct
29 Correct 225 ms 37224 KB Output is correct
30 Correct 111 ms 5008 KB Output is correct
31 Correct 248 ms 38376 KB Output is correct
32 Correct 239 ms 35212 KB Output is correct
33 Correct 105 ms 4936 KB Output is correct
34 Correct 272 ms 38428 KB Output is correct
35 Correct 197 ms 29200 KB Output is correct
36 Correct 106 ms 5008 KB Output is correct
37 Correct 119 ms 4896 KB Output is correct
38 Correct 225 ms 38072 KB Output is correct
39 Correct 148 ms 38304 KB Output is correct
40 Correct 201 ms 26468 KB Output is correct
41 Correct 318 ms 38432 KB Output is correct
42 Correct 82 ms 37708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 2252 KB Output is correct
2 Correct 69 ms 2472 KB Output is correct
3 Correct 65 ms 2256 KB Output is correct
4 Correct 61 ms 2404 KB Output is correct
5 Correct 56 ms 2388 KB Output is correct
6 Correct 58 ms 2316 KB Output is correct
7 Correct 58 ms 2452 KB Output is correct
8 Correct 59 ms 2412 KB Output is correct
9 Correct 65 ms 2484 KB Output is correct
10 Correct 65 ms 2384 KB Output is correct
11 Correct 60 ms 2480 KB Output is correct
12 Correct 61 ms 2420 KB Output is correct
13 Correct 69 ms 2564 KB Output is correct
14 Correct 59 ms 2384 KB Output is correct
15 Correct 60 ms 2408 KB Output is correct
16 Correct 63 ms 2380 KB Output is correct
17 Correct 60 ms 2444 KB Output is correct
18 Correct 69 ms 2400 KB Output is correct
19 Correct 69 ms 2356 KB Output is correct
20 Correct 69 ms 2260 KB Output is correct
21 Correct 59 ms 2392 KB Output is correct
22 Correct 53 ms 2176 KB Output is correct
23 Correct 63 ms 2444 KB Output is correct
24 Correct 62 ms 2444 KB Output is correct
25 Correct 62 ms 2396 KB Output is correct
26 Correct 59 ms 2336 KB Output is correct
27 Correct 62 ms 2488 KB Output is correct
28 Correct 56 ms 2252 KB Output is correct
29 Correct 69 ms 2396 KB Output is correct
30 Correct 57 ms 2248 KB Output is correct
31 Correct 65 ms 2380 KB Output is correct
32 Correct 64 ms 2460 KB Output is correct
33 Correct 64 ms 2412 KB Output is correct
34 Correct 62 ms 2244 KB Output is correct
35 Correct 65 ms 2444 KB Output is correct
36 Correct 67 ms 2444 KB Output is correct
37 Correct 64 ms 2480 KB Output is correct
38 Correct 66 ms 2492 KB Output is correct
39 Correct 67 ms 2396 KB Output is correct
40 Correct 64 ms 2380 KB Output is correct
41 Correct 65 ms 2488 KB Output is correct
42 Correct 65 ms 2500 KB Output is correct
43 Correct 62 ms 2372 KB Output is correct
44 Correct 64 ms 2460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 2252 KB Output is correct
2 Correct 69 ms 2472 KB Output is correct
3 Correct 65 ms 2256 KB Output is correct
4 Correct 61 ms 2404 KB Output is correct
5 Correct 56 ms 2388 KB Output is correct
6 Correct 58 ms 2316 KB Output is correct
7 Correct 58 ms 2452 KB Output is correct
8 Correct 59 ms 2412 KB Output is correct
9 Correct 65 ms 2484 KB Output is correct
10 Correct 65 ms 2384 KB Output is correct
11 Correct 60 ms 2480 KB Output is correct
12 Correct 61 ms 2420 KB Output is correct
13 Correct 69 ms 2564 KB Output is correct
14 Correct 59 ms 2384 KB Output is correct
15 Correct 60 ms 2408 KB Output is correct
16 Correct 63 ms 2380 KB Output is correct
17 Correct 60 ms 2444 KB Output is correct
18 Correct 69 ms 2400 KB Output is correct
19 Correct 347 ms 38312 KB Output is correct
20 Correct 254 ms 38372 KB Output is correct
21 Correct 213 ms 36124 KB Output is correct
22 Correct 212 ms 32740 KB Output is correct
23 Correct 107 ms 5160 KB Output is correct
24 Correct 106 ms 4980 KB Output is correct
25 Correct 234 ms 38300 KB Output is correct
26 Correct 249 ms 38312 KB Output is correct
27 Correct 244 ms 38296 KB Output is correct
28 Correct 269 ms 38336 KB Output is correct
29 Correct 225 ms 37224 KB Output is correct
30 Correct 111 ms 5008 KB Output is correct
31 Correct 248 ms 38376 KB Output is correct
32 Correct 239 ms 35212 KB Output is correct
33 Correct 105 ms 4936 KB Output is correct
34 Correct 272 ms 38428 KB Output is correct
35 Correct 197 ms 29200 KB Output is correct
36 Correct 106 ms 5008 KB Output is correct
37 Correct 119 ms 4896 KB Output is correct
38 Correct 225 ms 38072 KB Output is correct
39 Correct 148 ms 38304 KB Output is correct
40 Correct 201 ms 26468 KB Output is correct
41 Correct 318 ms 38432 KB Output is correct
42 Correct 82 ms 37708 KB Output is correct
43 Correct 69 ms 2356 KB Output is correct
44 Correct 69 ms 2260 KB Output is correct
45 Correct 59 ms 2392 KB Output is correct
46 Correct 53 ms 2176 KB Output is correct
47 Correct 63 ms 2444 KB Output is correct
48 Correct 62 ms 2444 KB Output is correct
49 Correct 62 ms 2396 KB Output is correct
50 Correct 59 ms 2336 KB Output is correct
51 Correct 62 ms 2488 KB Output is correct
52 Correct 56 ms 2252 KB Output is correct
53 Correct 69 ms 2396 KB Output is correct
54 Correct 57 ms 2248 KB Output is correct
55 Correct 65 ms 2380 KB Output is correct
56 Correct 64 ms 2460 KB Output is correct
57 Correct 64 ms 2412 KB Output is correct
58 Correct 62 ms 2244 KB Output is correct
59 Correct 65 ms 2444 KB Output is correct
60 Correct 67 ms 2444 KB Output is correct
61 Correct 64 ms 2480 KB Output is correct
62 Correct 66 ms 2492 KB Output is correct
63 Correct 67 ms 2396 KB Output is correct
64 Correct 64 ms 2380 KB Output is correct
65 Correct 65 ms 2488 KB Output is correct
66 Correct 65 ms 2500 KB Output is correct
67 Correct 62 ms 2372 KB Output is correct
68 Correct 64 ms 2460 KB Output is correct
69 Correct 272 ms 32292 KB Output is correct
70 Correct 257 ms 38152 KB Output is correct
71 Correct 108 ms 5000 KB Output is correct
72 Correct 105 ms 4968 KB Output is correct
73 Correct 113 ms 5128 KB Output is correct
74 Correct 198 ms 32428 KB Output is correct
75 Correct 105 ms 4968 KB Output is correct
76 Correct 233 ms 38248 KB Output is correct
77 Correct 221 ms 32492 KB Output is correct
78 Correct 107 ms 4912 KB Output is correct
79 Correct 110 ms 5036 KB Output is correct
80 Correct 201 ms 28296 KB Output is correct
81 Correct 107 ms 4940 KB Output is correct
82 Correct 228 ms 38268 KB Output is correct
83 Correct 225 ms 36244 KB Output is correct
84 Correct 114 ms 4912 KB Output is correct
85 Correct 108 ms 4880 KB Output is correct
86 Correct 230 ms 29748 KB Output is correct
87 Correct 265 ms 38288 KB Output is correct
88 Correct 117 ms 5056 KB Output is correct
89 Correct 230 ms 33964 KB Output is correct
90 Correct 255 ms 38268 KB Output is correct
91 Correct 117 ms 4944 KB Output is correct
92 Correct 207 ms 29360 KB Output is correct
93 Correct 108 ms 4936 KB Output is correct
94 Correct 110 ms 4888 KB Output is correct
95 Correct 111 ms 5008 KB Output is correct
96 Correct 228 ms 38320 KB Output is correct
97 Correct 143 ms 38320 KB Output is correct
98 Correct 204 ms 26428 KB Output is correct
99 Correct 328 ms 38460 KB Output is correct
100 Correct 78 ms 37740 KB Output is correct