Submission #871873

# Submission time Handle Problem Language Result Execution time Memory
871873 2023-11-11T18:37:05 Z serifefedartar Crossing (JOI21_crossing) C++17
49 / 100
299 ms 27492 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20; 
const ll MAXN = 2e5 + 100;

const ll P = 31;
ll powP[2*MAXN];
ll inv;
struct Node {
	ll len, hash;
	Node() { }
	Node(ll _len, ll _hash) : len(_len), hash(_hash) { }
};

Node merge(Node A, Node B) {
	Node new_node;
	new_node.hash = (A.hash * powP[B.len] + B.hash) % MOD;
	new_node.len = A.len + B.len;
	return new_node;
}

set<ll> hashes;
vector<int> new_seq;
vector<int> cross(vector<int> A, vector<int> B) {
	int n = A.size();
	vector<int> q;
	for (int i = 0; i < n; i++)
		q.push_back((2 * (A[i] + B[i])) % 3);
	return q;
}

Node sg[4*MAXN];
ll lazy[4*MAXN];
ll expo(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 2) 
			res = (res * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}

void push(int k, int a, int b) {
	if (lazy[k] != -1) {
		int l = sg[k].len;
		sg[k].hash = (lazy[k] * (((powP[l] - 1) * inv) % MOD)) % MOD;
		if (a != b) {
			lazy[2*k] = lazy[k];
			lazy[2*k+1] = lazy[k];
		}
		lazy[k] = -1;
	}
}

void init(int k, int a, int b) {
	if (a == b) {
		sg[k].len = 1;
		sg[k].hash = new_seq[a-1] + 1;
		return ;
	}
	init(2*k, a, (a+b)/2);
	init(2*k+1, (a+b)/2+1, b);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}

void update(int k, int a, int b, int q_l, int q_r, int val) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return ;
	if (q_l <= a && b <= q_r) {
		lazy[k] = val;
		push(k, a, b);
		return ;
	}
	update(2*k, a, (a+b)/2, q_l, q_r, val);
	update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}

int main() {
	fast
	inv = expo(P-1, MOD-2);
	powP[0] = 1;
	for (int i = 1; i < 2*MAXN; i++)
		powP[i] = (powP[i-1] * P) % MOD;
	memset(lazy, -1, sizeof(lazy));
	int N;
	cin >> N;

	vector<int> s[3];
	for (int seq = 0; seq < 3; seq++)
		for (int i = 0; i < N; i++) {
		char ch;
		cin >> ch;
		s[seq].push_back(ch == 'J' ? 0 : (ch == 'O' ? 1 : 2));
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (i == j && j == k)
					continue;
				vector<int> c = cross(s[i], s[j]);
				c = cross(c, s[k]);

				ll hash = 0;
				for (int i = 0; i < N; i++)
					hash = (hash * P + (c[i] + 1)) % MOD;
				hashes.insert(hash);
			}
		}
	}

	int q;
	cin >> q;
	for (int i = 0; i < N; i++) {
		char ch;
		cin >> ch;
		new_seq.push_back(ch == 'J' ? 0 : (ch == 'O' ? 1 : 2));
	}
	init(1, 1, N);
	push(1, 1, N);

	if (hashes.count(sg[1].hash))
		cout << "Yes\n";
	else
		cout << "No\n";

	while (q--) {
		int l, r, val; char ch;
		cin >> l >> r >> ch;
		val = ch == 'J' ? 0 : (ch == 'O' ? 1 : 2);
		update(1, 1, N, l, r, val + 1);

		push(1, 1, N);
		if (hashes.count(sg[1].hash))
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11892 KB Output is correct
2 Correct 66 ms 11952 KB Output is correct
3 Correct 69 ms 11860 KB Output is correct
4 Correct 73 ms 12112 KB Output is correct
5 Correct 56 ms 11860 KB Output is correct
6 Correct 56 ms 11952 KB Output is correct
7 Correct 57 ms 12116 KB Output is correct
8 Correct 68 ms 11964 KB Output is correct
9 Correct 60 ms 12112 KB Output is correct
10 Correct 57 ms 12116 KB Output is correct
11 Correct 61 ms 12108 KB Output is correct
12 Correct 62 ms 11972 KB Output is correct
13 Correct 60 ms 12112 KB Output is correct
14 Correct 60 ms 12116 KB Output is correct
15 Correct 77 ms 12100 KB Output is correct
16 Correct 61 ms 12120 KB Output is correct
17 Correct 63 ms 12112 KB Output is correct
18 Correct 64 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11892 KB Output is correct
2 Correct 66 ms 11952 KB Output is correct
3 Correct 69 ms 11860 KB Output is correct
4 Correct 73 ms 12112 KB Output is correct
5 Correct 56 ms 11860 KB Output is correct
6 Correct 56 ms 11952 KB Output is correct
7 Correct 57 ms 12116 KB Output is correct
8 Correct 68 ms 11964 KB Output is correct
9 Correct 60 ms 12112 KB Output is correct
10 Correct 57 ms 12116 KB Output is correct
11 Correct 61 ms 12108 KB Output is correct
12 Correct 62 ms 11972 KB Output is correct
13 Correct 60 ms 12112 KB Output is correct
14 Correct 60 ms 12116 KB Output is correct
15 Correct 77 ms 12100 KB Output is correct
16 Correct 61 ms 12120 KB Output is correct
17 Correct 63 ms 12112 KB Output is correct
18 Correct 64 ms 12116 KB Output is correct
19 Correct 263 ms 27260 KB Output is correct
20 Correct 269 ms 27320 KB Output is correct
21 Correct 199 ms 26744 KB Output is correct
22 Correct 181 ms 25992 KB Output is correct
23 Correct 96 ms 15564 KB Output is correct
24 Correct 96 ms 15308 KB Output is correct
25 Correct 203 ms 27136 KB Output is correct
26 Correct 209 ms 27492 KB Output is correct
27 Correct 224 ms 27264 KB Output is correct
28 Correct 216 ms 27216 KB Output is correct
29 Correct 234 ms 26872 KB Output is correct
30 Correct 104 ms 15240 KB Output is correct
31 Correct 216 ms 27060 KB Output is correct
32 Correct 211 ms 26544 KB Output is correct
33 Correct 99 ms 15312 KB Output is correct
34 Correct 226 ms 27464 KB Output is correct
35 Correct 171 ms 25576 KB Output is correct
36 Correct 96 ms 15316 KB Output is correct
37 Correct 96 ms 15312 KB Output is correct
38 Correct 234 ms 26872 KB Output is correct
39 Correct 181 ms 27336 KB Output is correct
40 Correct 172 ms 21004 KB Output is correct
41 Correct 299 ms 27464 KB Output is correct
42 Correct 104 ms 26488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11892 KB Output is correct
2 Correct 66 ms 11952 KB Output is correct
3 Correct 69 ms 11860 KB Output is correct
4 Correct 73 ms 12112 KB Output is correct
5 Correct 56 ms 11860 KB Output is correct
6 Correct 56 ms 11952 KB Output is correct
7 Correct 57 ms 12116 KB Output is correct
8 Correct 68 ms 11964 KB Output is correct
9 Correct 60 ms 12112 KB Output is correct
10 Correct 57 ms 12116 KB Output is correct
11 Correct 61 ms 12108 KB Output is correct
12 Correct 62 ms 11972 KB Output is correct
13 Correct 60 ms 12112 KB Output is correct
14 Correct 60 ms 12116 KB Output is correct
15 Correct 77 ms 12100 KB Output is correct
16 Correct 61 ms 12120 KB Output is correct
17 Correct 63 ms 12112 KB Output is correct
18 Correct 64 ms 12116 KB Output is correct
19 Correct 73 ms 12240 KB Output is correct
20 Correct 78 ms 12076 KB Output is correct
21 Correct 61 ms 12116 KB Output is correct
22 Correct 55 ms 11840 KB Output is correct
23 Correct 62 ms 12076 KB Output is correct
24 Correct 59 ms 12116 KB Output is correct
25 Correct 62 ms 12112 KB Output is correct
26 Correct 58 ms 11856 KB Output is correct
27 Correct 62 ms 12112 KB Output is correct
28 Correct 53 ms 11856 KB Output is correct
29 Correct 65 ms 12156 KB Output is correct
30 Correct 57 ms 11860 KB Output is correct
31 Correct 64 ms 12120 KB Output is correct
32 Correct 68 ms 12008 KB Output is correct
33 Correct 63 ms 12112 KB Output is correct
34 Correct 61 ms 12024 KB Output is correct
35 Correct 63 ms 12176 KB Output is correct
36 Correct 65 ms 12368 KB Output is correct
37 Correct 83 ms 12116 KB Output is correct
38 Correct 65 ms 12112 KB Output is correct
39 Correct 63 ms 12112 KB Output is correct
40 Correct 64 ms 12172 KB Output is correct
41 Correct 78 ms 12200 KB Output is correct
42 Correct 67 ms 12116 KB Output is correct
43 Correct 60 ms 12112 KB Output is correct
44 Correct 66 ms 12112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 11892 KB Output is correct
2 Correct 66 ms 11952 KB Output is correct
3 Correct 69 ms 11860 KB Output is correct
4 Correct 73 ms 12112 KB Output is correct
5 Correct 56 ms 11860 KB Output is correct
6 Correct 56 ms 11952 KB Output is correct
7 Correct 57 ms 12116 KB Output is correct
8 Correct 68 ms 11964 KB Output is correct
9 Correct 60 ms 12112 KB Output is correct
10 Correct 57 ms 12116 KB Output is correct
11 Correct 61 ms 12108 KB Output is correct
12 Correct 62 ms 11972 KB Output is correct
13 Correct 60 ms 12112 KB Output is correct
14 Correct 60 ms 12116 KB Output is correct
15 Correct 77 ms 12100 KB Output is correct
16 Correct 61 ms 12120 KB Output is correct
17 Correct 63 ms 12112 KB Output is correct
18 Correct 64 ms 12116 KB Output is correct
19 Correct 263 ms 27260 KB Output is correct
20 Correct 269 ms 27320 KB Output is correct
21 Correct 199 ms 26744 KB Output is correct
22 Correct 181 ms 25992 KB Output is correct
23 Correct 96 ms 15564 KB Output is correct
24 Correct 96 ms 15308 KB Output is correct
25 Correct 203 ms 27136 KB Output is correct
26 Correct 209 ms 27492 KB Output is correct
27 Correct 224 ms 27264 KB Output is correct
28 Correct 216 ms 27216 KB Output is correct
29 Correct 234 ms 26872 KB Output is correct
30 Correct 104 ms 15240 KB Output is correct
31 Correct 216 ms 27060 KB Output is correct
32 Correct 211 ms 26544 KB Output is correct
33 Correct 99 ms 15312 KB Output is correct
34 Correct 226 ms 27464 KB Output is correct
35 Correct 171 ms 25576 KB Output is correct
36 Correct 96 ms 15316 KB Output is correct
37 Correct 96 ms 15312 KB Output is correct
38 Correct 234 ms 26872 KB Output is correct
39 Correct 181 ms 27336 KB Output is correct
40 Correct 172 ms 21004 KB Output is correct
41 Correct 299 ms 27464 KB Output is correct
42 Correct 104 ms 26488 KB Output is correct
43 Correct 73 ms 12240 KB Output is correct
44 Correct 78 ms 12076 KB Output is correct
45 Correct 61 ms 12116 KB Output is correct
46 Correct 55 ms 11840 KB Output is correct
47 Correct 62 ms 12076 KB Output is correct
48 Correct 59 ms 12116 KB Output is correct
49 Correct 62 ms 12112 KB Output is correct
50 Correct 58 ms 11856 KB Output is correct
51 Correct 62 ms 12112 KB Output is correct
52 Correct 53 ms 11856 KB Output is correct
53 Correct 65 ms 12156 KB Output is correct
54 Correct 57 ms 11860 KB Output is correct
55 Correct 64 ms 12120 KB Output is correct
56 Correct 68 ms 12008 KB Output is correct
57 Correct 63 ms 12112 KB Output is correct
58 Correct 61 ms 12024 KB Output is correct
59 Correct 63 ms 12176 KB Output is correct
60 Correct 65 ms 12368 KB Output is correct
61 Correct 83 ms 12116 KB Output is correct
62 Correct 65 ms 12112 KB Output is correct
63 Correct 63 ms 12112 KB Output is correct
64 Correct 64 ms 12172 KB Output is correct
65 Correct 78 ms 12200 KB Output is correct
66 Correct 67 ms 12116 KB Output is correct
67 Correct 60 ms 12112 KB Output is correct
68 Correct 66 ms 12112 KB Output is correct
69 Correct 243 ms 26012 KB Output is correct
70 Correct 292 ms 27192 KB Output is correct
71 Correct 99 ms 15204 KB Output is correct
72 Correct 103 ms 15144 KB Output is correct
73 Correct 99 ms 15376 KB Output is correct
74 Correct 178 ms 26052 KB Output is correct
75 Correct 98 ms 15316 KB Output is correct
76 Incorrect 202 ms 27156 KB Output isn't correct
77 Halted 0 ms 0 KB -