Submission #420374

# Submission time Handle Problem Language Result Execution time Memory
420374 2021-06-08T10:15:28 Z InternetPerson10 Crossing (JOI21_crossing) C++17
100 / 100
1938 ms 66672 KB
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

const ll MOD = 1000000007;

vector<int> nums[3];
vector<int> anss[9];
vector<int> tar;
vector<pair<pair<int, int>, int>> qs;
bool good[300001];
ll pow3[300001][4], sum3[300001][4];
ll ha[9][4];
vector<ll> ps = {1000000007, 1000000009, 1000000021, 1000000033};

vector<int> combine(vector<int> v1, vector<int> v2) {
	vector<int> v;
	v.resize(v1.size());
	for(int i = 0; i < v.size(); i++) v[i] = (6 - v1[i] - v2[i])%3;
	return v;
}

struct segTree {
	ll prime; int typ;
	vector<ll> nums, ops;
	int size = 1;
	void init(int n, ll p, int t) {
		while(size < n) size *= 2;
		vector<ll>().swap(nums);
		nums.resize(2*size, 0);
		ops.resize(2*size, -1);
		prime = p;
		typ = t;
	}
	void prop(int n, int d) {
		if(ops[n] == -1) return;
		if(n >= size) {
			nums[n] = ops[n];
			ops[n] = -1;
			return;
		}
		ops[2*n+1] = ops[n];
		ops[2*n+2] = ops[n];
		nums[n] = (ops[n] * sum3[d-1][typ])%prime;
		ops[n] = -1;
		return;
	}
	void set(int l, int r, int v, int n, int lx, int rx) {
		prop(n, rx - lx);
		if(l >= rx || lx >= r) return;
		if(l <= lx && rx <= r) {
			ops[n] = v;
			nums[n] = (ops[n] * sum3[rx-lx-1][typ])%prime;
			return;
		}
		int mid = (lx + rx)/2;
		set(l, r, v, 2*n+1, lx, mid);
		set(l, r, v, 2*n+2, mid, rx);
		nums[n] = (pow3[mid - lx][typ] * nums[2*n+1] + nums[2*n+2])%prime;
		return;
	}
	void set(int l, int r, int v) {
		set(l, r, v, 0, 0, size);
	}
	ll get() {
		prop(0, size);
		return nums[0];
	}
};

segTree st[4];

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

bool check() {
	for(int i = 0; i < 9; i++) {
		bool sad = false;
		for(int z = 0; z < 4; z++) {
			if(st[z].get() != ha[i][z]) sad = true;
			// cout << st[z].get() << ' ';
		}
		// cout << '\n';
		if(!sad) return true;
	}
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll k = 1;
	for(int z = 0; z < 4; z++) {
		k = 1;
		for(int i = 0; i <= 300000; i++) {
			pow3[i][z] = k;
			k *= 3;
			if(k > ps[z]) k %= ps[z];
			if(i == 0) sum3[i][z] = pow3[i][z];
			else sum3[i][z] = (sum3[i-1][z] + pow3[i][z])%ps[z];
		}
	}
	int n, q;
	int size = 1;
	string s;
	cin >> n;
	while(size < n) {
		size *= 2;
	}
	for(int i = 0; i < 3; i++) {
		cin >> s;
		nums[i].resize(n);
		for(int j = 0; j < n; j++) {
			if(s.at(j) == 'J') nums[i][j] = 0;
			else if(s.at(j) == 'O') nums[i][j] = 1;
			else nums[i][j] = 2;
		}
		anss[i] = nums[i];
	}
	anss[3] = combine(nums[0], nums[1]);
	anss[4] = combine(nums[1], nums[2]);
	anss[5] = combine(nums[0], nums[2]);
	anss[6] = combine(anss[3], nums[2]);
	anss[7] = combine(anss[4], nums[0]);
	anss[8] = combine(anss[5], nums[1]);
	for(int z = 0; z < 4; z++) {
		for(int i = 0; i < 9; i++) {
			ll k = 0;
			for(int j = 0; j < size; j++) {
				k *= 3;
				if(j < anss[i].size()) k += anss[i][j];
				k %= ps[z];
			}
			ha[i][z] = k;
			// cout << ha[i][z] << ' ';
		}
		// cout << '\n';
	}
	cin >> q >> s;
	tar.resize(n);
	qs.resize(q);
	for(int z = 0; z < 4; z++) {
		st[z].init(n, ps[z], z);
	}
	for(int z = 0; z < 4; z++) {
		for(int i = 0; i < n; i++) {
			st[z].set(i, i+1, getChar(s.at(i)));
		}
	}
	good[0] = check();
	for(int i = 0; i < q; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		int z;
		if(c == 'J') z = 0;
		else if(c == 'O') z = 1;
		else z = 2;
		for(int m = 0; m < 4; m++) st[m].set(x-1, y, z);
		good[i+1] = check();
	}
	for(int i = 0; i <= q; i++) {
		if(good[i]) cout << "Yes\n";
		else cout << "No\n";
	}
}

Compilation message

Main.cpp: In function 'std::vector<int> combine(std::vector<int>, std::vector<int>)':
Main.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i = 0; i < v.size(); i++) v[i] = (6 - v1[i] - v2[i])%3;
      |                 ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:135:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |     if(j < anss[i].size()) k += anss[i][j];
      |        ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 293 ms 21956 KB Output is correct
2 Correct 307 ms 22168 KB Output is correct
3 Correct 342 ms 22192 KB Output is correct
4 Correct 268 ms 22092 KB Output is correct
5 Correct 256 ms 22184 KB Output is correct
6 Correct 250 ms 21992 KB Output is correct
7 Correct 275 ms 22116 KB Output is correct
8 Correct 259 ms 22248 KB Output is correct
9 Correct 261 ms 22184 KB Output is correct
10 Correct 266 ms 22356 KB Output is correct
11 Correct 264 ms 22252 KB Output is correct
12 Correct 262 ms 22144 KB Output is correct
13 Correct 264 ms 22212 KB Output is correct
14 Correct 266 ms 22276 KB Output is correct
15 Correct 268 ms 22468 KB Output is correct
16 Correct 261 ms 22212 KB Output is correct
17 Correct 267 ms 22232 KB Output is correct
18 Correct 329 ms 22188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 21956 KB Output is correct
2 Correct 307 ms 22168 KB Output is correct
3 Correct 342 ms 22192 KB Output is correct
4 Correct 268 ms 22092 KB Output is correct
5 Correct 256 ms 22184 KB Output is correct
6 Correct 250 ms 21992 KB Output is correct
7 Correct 275 ms 22116 KB Output is correct
8 Correct 259 ms 22248 KB Output is correct
9 Correct 261 ms 22184 KB Output is correct
10 Correct 266 ms 22356 KB Output is correct
11 Correct 264 ms 22252 KB Output is correct
12 Correct 262 ms 22144 KB Output is correct
13 Correct 264 ms 22212 KB Output is correct
14 Correct 266 ms 22276 KB Output is correct
15 Correct 268 ms 22468 KB Output is correct
16 Correct 261 ms 22212 KB Output is correct
17 Correct 267 ms 22232 KB Output is correct
18 Correct 329 ms 22188 KB Output is correct
19 Correct 1800 ms 66196 KB Output is correct
20 Correct 1617 ms 66252 KB Output is correct
21 Correct 1280 ms 65496 KB Output is correct
22 Correct 1223 ms 64276 KB Output is correct
23 Correct 532 ms 24812 KB Output is correct
24 Correct 521 ms 24844 KB Output is correct
25 Correct 1312 ms 66276 KB Output is correct
26 Correct 1404 ms 66332 KB Output is correct
27 Correct 1537 ms 66364 KB Output is correct
28 Correct 1497 ms 66280 KB Output is correct
29 Correct 1451 ms 65848 KB Output is correct
30 Correct 601 ms 24844 KB Output is correct
31 Correct 1484 ms 66408 KB Output is correct
32 Correct 1434 ms 65212 KB Output is correct
33 Correct 525 ms 24824 KB Output is correct
34 Correct 1534 ms 66196 KB Output is correct
35 Correct 1177 ms 63360 KB Output is correct
36 Correct 527 ms 24900 KB Output is correct
37 Correct 517 ms 24868 KB Output is correct
38 Correct 1503 ms 66196 KB Output is correct
39 Correct 936 ms 66324 KB Output is correct
40 Correct 1138 ms 46036 KB Output is correct
41 Correct 1938 ms 66400 KB Output is correct
42 Correct 771 ms 66592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 21956 KB Output is correct
2 Correct 307 ms 22168 KB Output is correct
3 Correct 342 ms 22192 KB Output is correct
4 Correct 268 ms 22092 KB Output is correct
5 Correct 256 ms 22184 KB Output is correct
6 Correct 250 ms 21992 KB Output is correct
7 Correct 275 ms 22116 KB Output is correct
8 Correct 259 ms 22248 KB Output is correct
9 Correct 261 ms 22184 KB Output is correct
10 Correct 266 ms 22356 KB Output is correct
11 Correct 264 ms 22252 KB Output is correct
12 Correct 262 ms 22144 KB Output is correct
13 Correct 264 ms 22212 KB Output is correct
14 Correct 266 ms 22276 KB Output is correct
15 Correct 268 ms 22468 KB Output is correct
16 Correct 261 ms 22212 KB Output is correct
17 Correct 267 ms 22232 KB Output is correct
18 Correct 329 ms 22188 KB Output is correct
19 Correct 292 ms 22100 KB Output is correct
20 Correct 345 ms 22148 KB Output is correct
21 Correct 274 ms 22240 KB Output is correct
22 Correct 240 ms 21956 KB Output is correct
23 Correct 280 ms 22212 KB Output is correct
24 Correct 258 ms 22072 KB Output is correct
25 Correct 271 ms 22268 KB Output is correct
26 Correct 259 ms 22056 KB Output is correct
27 Correct 266 ms 22224 KB Output is correct
28 Correct 246 ms 21920 KB Output is correct
29 Correct 268 ms 22224 KB Output is correct
30 Correct 245 ms 21928 KB Output is correct
31 Correct 273 ms 22300 KB Output is correct
32 Correct 269 ms 22264 KB Output is correct
33 Correct 271 ms 22140 KB Output is correct
34 Correct 247 ms 22104 KB Output is correct
35 Correct 262 ms 22168 KB Output is correct
36 Correct 267 ms 22212 KB Output is correct
37 Correct 263 ms 22212 KB Output is correct
38 Correct 273 ms 22244 KB Output is correct
39 Correct 273 ms 22168 KB Output is correct
40 Correct 265 ms 22160 KB Output is correct
41 Correct 269 ms 22212 KB Output is correct
42 Correct 266 ms 22192 KB Output is correct
43 Correct 257 ms 22228 KB Output is correct
44 Correct 268 ms 22176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 21956 KB Output is correct
2 Correct 307 ms 22168 KB Output is correct
3 Correct 342 ms 22192 KB Output is correct
4 Correct 268 ms 22092 KB Output is correct
5 Correct 256 ms 22184 KB Output is correct
6 Correct 250 ms 21992 KB Output is correct
7 Correct 275 ms 22116 KB Output is correct
8 Correct 259 ms 22248 KB Output is correct
9 Correct 261 ms 22184 KB Output is correct
10 Correct 266 ms 22356 KB Output is correct
11 Correct 264 ms 22252 KB Output is correct
12 Correct 262 ms 22144 KB Output is correct
13 Correct 264 ms 22212 KB Output is correct
14 Correct 266 ms 22276 KB Output is correct
15 Correct 268 ms 22468 KB Output is correct
16 Correct 261 ms 22212 KB Output is correct
17 Correct 267 ms 22232 KB Output is correct
18 Correct 329 ms 22188 KB Output is correct
19 Correct 1800 ms 66196 KB Output is correct
20 Correct 1617 ms 66252 KB Output is correct
21 Correct 1280 ms 65496 KB Output is correct
22 Correct 1223 ms 64276 KB Output is correct
23 Correct 532 ms 24812 KB Output is correct
24 Correct 521 ms 24844 KB Output is correct
25 Correct 1312 ms 66276 KB Output is correct
26 Correct 1404 ms 66332 KB Output is correct
27 Correct 1537 ms 66364 KB Output is correct
28 Correct 1497 ms 66280 KB Output is correct
29 Correct 1451 ms 65848 KB Output is correct
30 Correct 601 ms 24844 KB Output is correct
31 Correct 1484 ms 66408 KB Output is correct
32 Correct 1434 ms 65212 KB Output is correct
33 Correct 525 ms 24824 KB Output is correct
34 Correct 1534 ms 66196 KB Output is correct
35 Correct 1177 ms 63360 KB Output is correct
36 Correct 527 ms 24900 KB Output is correct
37 Correct 517 ms 24868 KB Output is correct
38 Correct 1503 ms 66196 KB Output is correct
39 Correct 936 ms 66324 KB Output is correct
40 Correct 1138 ms 46036 KB Output is correct
41 Correct 1938 ms 66400 KB Output is correct
42 Correct 771 ms 66592 KB Output is correct
43 Correct 292 ms 22100 KB Output is correct
44 Correct 345 ms 22148 KB Output is correct
45 Correct 274 ms 22240 KB Output is correct
46 Correct 240 ms 21956 KB Output is correct
47 Correct 280 ms 22212 KB Output is correct
48 Correct 258 ms 22072 KB Output is correct
49 Correct 271 ms 22268 KB Output is correct
50 Correct 259 ms 22056 KB Output is correct
51 Correct 266 ms 22224 KB Output is correct
52 Correct 246 ms 21920 KB Output is correct
53 Correct 268 ms 22224 KB Output is correct
54 Correct 245 ms 21928 KB Output is correct
55 Correct 273 ms 22300 KB Output is correct
56 Correct 269 ms 22264 KB Output is correct
57 Correct 271 ms 22140 KB Output is correct
58 Correct 247 ms 22104 KB Output is correct
59 Correct 262 ms 22168 KB Output is correct
60 Correct 267 ms 22212 KB Output is correct
61 Correct 263 ms 22212 KB Output is correct
62 Correct 273 ms 22244 KB Output is correct
63 Correct 273 ms 22168 KB Output is correct
64 Correct 265 ms 22160 KB Output is correct
65 Correct 269 ms 22212 KB Output is correct
66 Correct 266 ms 22192 KB Output is correct
67 Correct 257 ms 22228 KB Output is correct
68 Correct 268 ms 22176 KB Output is correct
69 Correct 1562 ms 64300 KB Output is correct
70 Correct 1734 ms 66428 KB Output is correct
71 Correct 518 ms 24820 KB Output is correct
72 Correct 514 ms 24888 KB Output is correct
73 Correct 530 ms 24836 KB Output is correct
74 Correct 1184 ms 64276 KB Output is correct
75 Correct 512 ms 24996 KB Output is correct
76 Correct 1359 ms 66248 KB Output is correct
77 Correct 1247 ms 64304 KB Output is correct
78 Correct 530 ms 24948 KB Output is correct
79 Correct 519 ms 24872 KB Output is correct
80 Correct 1165 ms 62848 KB Output is correct
81 Correct 522 ms 24836 KB Output is correct
82 Correct 1332 ms 66312 KB Output is correct
83 Correct 1296 ms 65504 KB Output is correct
84 Correct 511 ms 24900 KB Output is correct
85 Correct 515 ms 24788 KB Output is correct
86 Correct 1372 ms 63344 KB Output is correct
87 Correct 1514 ms 66400 KB Output is correct
88 Correct 558 ms 24860 KB Output is correct
89 Correct 1366 ms 64780 KB Output is correct
90 Correct 1467 ms 66204 KB Output is correct
91 Correct 556 ms 24916 KB Output is correct
92 Correct 1170 ms 63628 KB Output is correct
93 Correct 533 ms 24900 KB Output is correct
94 Correct 524 ms 24892 KB Output is correct
95 Correct 511 ms 24904 KB Output is correct
96 Correct 1458 ms 66336 KB Output is correct
97 Correct 934 ms 66208 KB Output is correct
98 Correct 1142 ms 46180 KB Output is correct
99 Correct 1916 ms 66672 KB Output is correct
100 Correct 797 ms 66384 KB Output is correct