답안 #467936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467936 2021-08-25T16:07:11 Z LittlePants Crossing (JOI21_crossing) C++17
100 / 100
576 ms 20568 KB
#define ll loli
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define push emplace
#define sz(x) (int)(x.size())
#define re(x) reverse(all(x))
#define uni(x) x.resize(unique(all(x)) - x.begin())
#define all(x) x.begin(), x.end()
#define mem(x, v) memset(x, v, sizeof x); 
#define int long long
#define pii pair<int, int>
#define inf 1e9
#define INF 1e18
#define mod 1000000007
#define F first
#define S second
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
void trace_() {cerr << "\n";}
template<typename T1, typename... T2> void trace_(T1 t1, T2... t2) {cerr << ' ' << t1; trace_(t2...); }
#define trace(...) cerr << "[" << #__VA_ARGS__ << "] :", trace_(__VA_ARGS__);

const int mxN = 2e5 + 5, p = 17;
int n, q, h[mxN], ppow[mxN], sump[mxN], mp[300];
string s[3], t;
set<int> st;

string cross(string a, string b) {
	string s;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) s.pb(a[i]);
		else {
			if ('J' != a[i] and 'J' != b[i]) s.pb('J');
			if ('O' != a[i] and 'O' != b[i]) s.pb('O');
			if ('I' != a[i] and 'I' != b[i]) s.pb('I');
		}
	}
	return s;
}

#define ls x<<1
#define rs x<<1|1
#define mid ((l+r)>>1)

int seg[mxN * 4], tag[mxN * 4];
inline void up(int x) {
	seg[x] = (seg[ls] + seg[rs]) % mod;
}

void build(int l = 1, int r = n, int x = 1) {
	if(l == r) {
		seg[x] = h[l];
		return;
	}
	build(l, mid, ls);	build(mid+1, r, rs);
	up(x);
}

void down(int l, int r, int x) {
	if(!tag[x]) return;
	seg[ls] = tag[x] * (sump[mid] - sump[l - 1] + mod) % mod;
	seg[rs] = tag[x] * (sump[r] - sump[mid] + mod) % mod;
	tag[ls] = tag[x];
	tag[rs] = tag[x];
	tag[x] = 0;
}

void modify(int a, int b, int v, int l = 1, int r = n, int x = 1) {
	if (l != r)	down(l, r, x);
	if(a <= l and r <= b) {
		seg[x] = v * (sump[r] - sump[l - 1] + mod) % mod;
		tag[x] = v;
		return;
	}
	if(a <= mid) modify(a, b, v, l, mid, ls);
	if(b > mid) modify(a, b, v, mid+1, r, rs);
	up(x);
}

inline int H(string s) {
	int tmp = 0;
	for (int i = 1; i <= n; i++) {
		tmp = (tmp + (mp[s[i - 1]] * ppow[i]) % mod) % mod;
	}
	return tmp;
}


signed main() {
	IO;	
	cin >> n >> s[0] >> s[1] >> s[2] >> q >> t;
	mp['J'] = 1; mp['O'] = 2; mp['I'] = 3;
	ppow[0] = 1;
	for (int i = 1; i <= n; i++) {
		ppow[i] = (ppow[i - 1] * p) % mod;
		sump[i] = (sump[i - 1] + ppow[i]) % mod;
	}

	vector<string> v;
	v.pb(s[0]); v.pb(s[1]); v.pb(s[2]);
	st.insert(H(s[0]));
	st.insert(H(s[1]));
	st.insert(H(s[2]));

	for (int i = 0; i < sz(v); i++) {
		for (int j = i + 1; j < sz(v); j++) {
			string t = cross(v[i], v[j]);
			int ht = H(t);
			if (!st.count(ht)) {
				st.insert(ht);
				v.pb(t);
			}
		}
	}


	for (int i = 1; i <= n; i++) {
		h[i] = (mp[t[i - 1]] * ppow[i]) % mod; 
	}
	build();
	
	if (st.count(seg[1])) cout << "Yes\n";
	else cout << "No\n";

	while (q--) {
		int l, r; char c;
		cin >> l >> r >> c;	
		modify(l, r, mp[c]);
		if (st.count(seg[1])) cout << "Yes\n";
		else cout << "No\n";
	}
}

Compilation message

Main.cpp: In function 'long long int H(std::string)':
Main.cpp:84:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   84 |   tmp = (tmp + (mp[s[i - 1]] * ppow[i]) % mod) % mod;
      |                            ^
Main.cpp: In function 'int main()':
Main.cpp:119:22: warning: array subscript has type 'char' [-Wchar-subscripts]
  119 |   h[i] = (mp[t[i - 1]] * ppow[i]) % mod;
      |                      ^
Main.cpp:129:19: warning: array subscript has type 'char' [-Wchar-subscripts]
  129 |   modify(l, r, mp[c]);
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2228 KB Output is correct
2 Correct 88 ms 2380 KB Output is correct
3 Correct 101 ms 2244 KB Output is correct
4 Correct 74 ms 2320 KB Output is correct
5 Correct 73 ms 2372 KB Output is correct
6 Correct 78 ms 2252 KB Output is correct
7 Correct 75 ms 2564 KB Output is correct
8 Correct 93 ms 2372 KB Output is correct
9 Correct 79 ms 2412 KB Output is correct
10 Correct 80 ms 2500 KB Output is correct
11 Correct 82 ms 2420 KB Output is correct
12 Correct 78 ms 2420 KB Output is correct
13 Correct 82 ms 2424 KB Output is correct
14 Correct 79 ms 2420 KB Output is correct
15 Correct 80 ms 2452 KB Output is correct
16 Correct 79 ms 2396 KB Output is correct
17 Correct 80 ms 2392 KB Output is correct
18 Correct 94 ms 2368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2228 KB Output is correct
2 Correct 88 ms 2380 KB Output is correct
3 Correct 101 ms 2244 KB Output is correct
4 Correct 74 ms 2320 KB Output is correct
5 Correct 73 ms 2372 KB Output is correct
6 Correct 78 ms 2252 KB Output is correct
7 Correct 75 ms 2564 KB Output is correct
8 Correct 93 ms 2372 KB Output is correct
9 Correct 79 ms 2412 KB Output is correct
10 Correct 80 ms 2500 KB Output is correct
11 Correct 82 ms 2420 KB Output is correct
12 Correct 78 ms 2420 KB Output is correct
13 Correct 82 ms 2424 KB Output is correct
14 Correct 79 ms 2420 KB Output is correct
15 Correct 80 ms 2452 KB Output is correct
16 Correct 79 ms 2396 KB Output is correct
17 Correct 80 ms 2392 KB Output is correct
18 Correct 94 ms 2368 KB Output is correct
19 Correct 314 ms 19520 KB Output is correct
20 Correct 308 ms 16132 KB Output is correct
21 Correct 195 ms 18772 KB Output is correct
22 Correct 249 ms 17968 KB Output is correct
23 Correct 131 ms 4164 KB Output is correct
24 Correct 125 ms 4124 KB Output is correct
25 Correct 235 ms 19320 KB Output is correct
26 Correct 206 ms 19436 KB Output is correct
27 Correct 243 ms 19400 KB Output is correct
28 Correct 275 ms 19348 KB Output is correct
29 Correct 252 ms 19088 KB Output is correct
30 Correct 140 ms 4164 KB Output is correct
31 Correct 284 ms 19380 KB Output is correct
32 Correct 237 ms 18692 KB Output is correct
33 Correct 136 ms 4192 KB Output is correct
34 Correct 260 ms 19344 KB Output is correct
35 Correct 184 ms 17368 KB Output is correct
36 Correct 121 ms 4164 KB Output is correct
37 Correct 122 ms 4156 KB Output is correct
38 Correct 263 ms 15912 KB Output is correct
39 Correct 143 ms 15336 KB Output is correct
40 Correct 180 ms 12696 KB Output is correct
41 Correct 360 ms 19696 KB Output is correct
42 Correct 71 ms 14632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2228 KB Output is correct
2 Correct 88 ms 2380 KB Output is correct
3 Correct 101 ms 2244 KB Output is correct
4 Correct 74 ms 2320 KB Output is correct
5 Correct 73 ms 2372 KB Output is correct
6 Correct 78 ms 2252 KB Output is correct
7 Correct 75 ms 2564 KB Output is correct
8 Correct 93 ms 2372 KB Output is correct
9 Correct 79 ms 2412 KB Output is correct
10 Correct 80 ms 2500 KB Output is correct
11 Correct 82 ms 2420 KB Output is correct
12 Correct 78 ms 2420 KB Output is correct
13 Correct 82 ms 2424 KB Output is correct
14 Correct 79 ms 2420 KB Output is correct
15 Correct 80 ms 2452 KB Output is correct
16 Correct 79 ms 2396 KB Output is correct
17 Correct 80 ms 2392 KB Output is correct
18 Correct 94 ms 2368 KB Output is correct
19 Correct 104 ms 2288 KB Output is correct
20 Correct 106 ms 2328 KB Output is correct
21 Correct 79 ms 2424 KB Output is correct
22 Correct 74 ms 2308 KB Output is correct
23 Correct 79 ms 2372 KB Output is correct
24 Correct 90 ms 2372 KB Output is correct
25 Correct 80 ms 2372 KB Output is correct
26 Correct 75 ms 2316 KB Output is correct
27 Correct 84 ms 2464 KB Output is correct
28 Correct 73 ms 2204 KB Output is correct
29 Correct 83 ms 2504 KB Output is correct
30 Correct 71 ms 2296 KB Output is correct
31 Correct 80 ms 2476 KB Output is correct
32 Correct 80 ms 2368 KB Output is correct
33 Correct 84 ms 2372 KB Output is correct
34 Correct 75 ms 2284 KB Output is correct
35 Correct 81 ms 2376 KB Output is correct
36 Correct 81 ms 2460 KB Output is correct
37 Correct 99 ms 2372 KB Output is correct
38 Correct 83 ms 2476 KB Output is correct
39 Correct 87 ms 2508 KB Output is correct
40 Correct 83 ms 2504 KB Output is correct
41 Correct 88 ms 2496 KB Output is correct
42 Correct 89 ms 2372 KB Output is correct
43 Correct 77 ms 2368 KB Output is correct
44 Correct 82 ms 2484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 2228 KB Output is correct
2 Correct 88 ms 2380 KB Output is correct
3 Correct 101 ms 2244 KB Output is correct
4 Correct 74 ms 2320 KB Output is correct
5 Correct 73 ms 2372 KB Output is correct
6 Correct 78 ms 2252 KB Output is correct
7 Correct 75 ms 2564 KB Output is correct
8 Correct 93 ms 2372 KB Output is correct
9 Correct 79 ms 2412 KB Output is correct
10 Correct 80 ms 2500 KB Output is correct
11 Correct 82 ms 2420 KB Output is correct
12 Correct 78 ms 2420 KB Output is correct
13 Correct 82 ms 2424 KB Output is correct
14 Correct 79 ms 2420 KB Output is correct
15 Correct 80 ms 2452 KB Output is correct
16 Correct 79 ms 2396 KB Output is correct
17 Correct 80 ms 2392 KB Output is correct
18 Correct 94 ms 2368 KB Output is correct
19 Correct 314 ms 19520 KB Output is correct
20 Correct 308 ms 16132 KB Output is correct
21 Correct 195 ms 18772 KB Output is correct
22 Correct 249 ms 17968 KB Output is correct
23 Correct 131 ms 4164 KB Output is correct
24 Correct 125 ms 4124 KB Output is correct
25 Correct 235 ms 19320 KB Output is correct
26 Correct 206 ms 19436 KB Output is correct
27 Correct 243 ms 19400 KB Output is correct
28 Correct 275 ms 19348 KB Output is correct
29 Correct 252 ms 19088 KB Output is correct
30 Correct 140 ms 4164 KB Output is correct
31 Correct 284 ms 19380 KB Output is correct
32 Correct 237 ms 18692 KB Output is correct
33 Correct 136 ms 4192 KB Output is correct
34 Correct 260 ms 19344 KB Output is correct
35 Correct 184 ms 17368 KB Output is correct
36 Correct 121 ms 4164 KB Output is correct
37 Correct 122 ms 4156 KB Output is correct
38 Correct 263 ms 15912 KB Output is correct
39 Correct 143 ms 15336 KB Output is correct
40 Correct 180 ms 12696 KB Output is correct
41 Correct 360 ms 19696 KB Output is correct
42 Correct 71 ms 14632 KB Output is correct
43 Correct 104 ms 2288 KB Output is correct
44 Correct 106 ms 2328 KB Output is correct
45 Correct 79 ms 2424 KB Output is correct
46 Correct 74 ms 2308 KB Output is correct
47 Correct 79 ms 2372 KB Output is correct
48 Correct 90 ms 2372 KB Output is correct
49 Correct 80 ms 2372 KB Output is correct
50 Correct 75 ms 2316 KB Output is correct
51 Correct 84 ms 2464 KB Output is correct
52 Correct 73 ms 2204 KB Output is correct
53 Correct 83 ms 2504 KB Output is correct
54 Correct 71 ms 2296 KB Output is correct
55 Correct 80 ms 2476 KB Output is correct
56 Correct 80 ms 2368 KB Output is correct
57 Correct 84 ms 2372 KB Output is correct
58 Correct 75 ms 2284 KB Output is correct
59 Correct 81 ms 2376 KB Output is correct
60 Correct 81 ms 2460 KB Output is correct
61 Correct 99 ms 2372 KB Output is correct
62 Correct 83 ms 2476 KB Output is correct
63 Correct 87 ms 2508 KB Output is correct
64 Correct 83 ms 2504 KB Output is correct
65 Correct 88 ms 2496 KB Output is correct
66 Correct 89 ms 2372 KB Output is correct
67 Correct 77 ms 2368 KB Output is correct
68 Correct 82 ms 2484 KB Output is correct
69 Correct 405 ms 18656 KB Output is correct
70 Correct 471 ms 17012 KB Output is correct
71 Correct 121 ms 4104 KB Output is correct
72 Correct 124 ms 4116 KB Output is correct
73 Correct 123 ms 4256 KB Output is correct
74 Correct 189 ms 18072 KB Output is correct
75 Correct 125 ms 4100 KB Output is correct
76 Correct 236 ms 19296 KB Output is correct
77 Correct 199 ms 18176 KB Output is correct
78 Correct 125 ms 4112 KB Output is correct
79 Correct 134 ms 4176 KB Output is correct
80 Correct 308 ms 17628 KB Output is correct
81 Correct 133 ms 4216 KB Output is correct
82 Correct 379 ms 20308 KB Output is correct
83 Correct 353 ms 19716 KB Output is correct
84 Correct 136 ms 4164 KB Output is correct
85 Correct 133 ms 4120 KB Output is correct
86 Correct 295 ms 18160 KB Output is correct
87 Correct 354 ms 20364 KB Output is correct
88 Correct 145 ms 4168 KB Output is correct
89 Correct 316 ms 19168 KB Output is correct
90 Correct 337 ms 20388 KB Output is correct
91 Correct 140 ms 4104 KB Output is correct
92 Correct 302 ms 18108 KB Output is correct
93 Correct 163 ms 4164 KB Output is correct
94 Correct 130 ms 4152 KB Output is correct
95 Correct 131 ms 4320 KB Output is correct
96 Correct 258 ms 15888 KB Output is correct
97 Correct 224 ms 16292 KB Output is correct
98 Correct 282 ms 13312 KB Output is correct
99 Correct 576 ms 20568 KB Output is correct
100 Correct 215 ms 15752 KB Output is correct