답안 #419615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
419615 2021-06-07T10:15:10 Z Kevin_Zhang_TW Crossing (JOI21_crossing) C++17
100 / 100
1649 ms 45812 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 300010;

int n, q;
vector<string> s(3);
string t;

char trans(char a, char b) { if (a == b) return a; return 'J' + 'O' + 'I' - a - b; }

string comb(string a, const string &b) {
	for (int i = 0;i < a.size();++i)
		a[i] = trans(a[i], b[i]);
	return a;
}

string yn(bool t) { return t ? "Yes" : "No"; }

struct sgt {
	int n;
	struct node {
		int sym, bad, tg;
		node () : sym(-1), bad(0), tg(-1) {}
		void operator = (int c) {
			tg = c;
			bad = sym != c;
		}
		node (node a, node b) {
			if (a.sym == b.sym) sym = a.sym;
			else sym = -1;
			bad = a.bad + b.bad;
			tg = -1;
		}
	};
	vector<node> val;
	void upd(int i) {
		if (i >= n) return;
		push(i);
		val[i] = node(val[i<<1], val[i<<1|1]);
	}
	void push(int i) {
		if (i >= n || val[i].tg == -1) return;
		int &t = val[i].tg;
		val[i<<1] = t, val[i<<1|1] = t;
		t = -1;
	}
	sgt(string s, string t) {
		n = s.size();
		val.resize(n<<1);
		for (int i = 0;i < n;++i) {
			val[i+n].sym = s[i];
			val[i+n] = t[i];
		}
		for (int i = n-1;i > 0;--i) {
			upd(i);
		}
	}
	bool ok() {
		return val[1].bad == 0;
		int l = 0, r = n, bad = 0;
		l += n, r += n;
		for (int i = 18;i > 0;--i) push(l>>i), push(r>>i);
		for (;l < r;l>>=1, r>>=1) {
			if (l&1) bad += val[l++].bad;
			if (r&1) bad += val[--r].bad;
		}
		return bad == 0;
	}
	//bool ok() { DE(val[1].bad); return val[1].bad == 0; }
	void modify(int l, int r, int c) {
		int sl = l += n, sr = r += n;
		for (int i = 18;i > 0;--i) push(l>>i), push(r>>i);
		for (;l < r;l>>=1, r>>=1) {
			if (l&1) val[l++] = c;
			if (r&1) val[--r] = c;
		}
		for (;sl>>=1, sr>>=1;) upd(sl), upd(sr);
	}
};

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (auto &i : s) cin >> i;


	for (int i = 0;i < s.size();++i)
		for (int j = i+1;j < s.size();++j) {
			string x = comb(s[i], s[j]);
			if (!count(AI(s), x))
				s.pb(x);
			assert(s.size() <= 9);
		}


	cin >> q >> t;

	vector<sgt> tree;
	for (int i = 0;i < s.size();++i)
		tree.pb(sgt(s[i], t));

	auto exist = [&]() {
		for (int i = 0;i < s.size();++i)
			if (tree[i].ok()) return true;
		return false;
	};

	cout << yn(exist()) << '\n';

	while (q--) {
		int l, r;
		char c;
		cin >> l >> r >> c; --l;

		for (int i = 0;i < s.size();++i) 
			tree[i].modify(l, r, c);

		cout << yn(exist()) << '\n';
	}
}

Compilation message

Main.cpp: In function 'std::string comb(std::string, const string&)':
Main.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for (int i = 0;i < a.size();++i)
      |                 ~~^~~~~~~~~~
Main.cpp: In function 'int32_t main()':
Main.cpp:102:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |  for (int i = 0;i < s.size();++i)
      |                 ~~^~~~~~~~~~
Main.cpp:103:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |   for (int j = i+1;j < s.size();++j) {
      |                    ~~^~~~~~~~~~
Main.cpp:114:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |  for (int i = 0;i < s.size();++i)
      |                 ~~^~~~~~~~~~
Main.cpp: In lambda function:
Main.cpp:118:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |   for (int i = 0;i < s.size();++i)
      |                  ~~^~~~~~~~~~
Main.cpp: In function 'int32_t main()':
Main.cpp:130:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |   for (int i = 0;i < s.size();++i)
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 908 KB Output is correct
2 Correct 161 ms 864 KB Output is correct
3 Correct 168 ms 892 KB Output is correct
4 Correct 153 ms 820 KB Output is correct
5 Correct 136 ms 836 KB Output is correct
6 Correct 147 ms 772 KB Output is correct
7 Correct 143 ms 904 KB Output is correct
8 Correct 159 ms 868 KB Output is correct
9 Correct 154 ms 924 KB Output is correct
10 Correct 145 ms 836 KB Output is correct
11 Correct 144 ms 836 KB Output is correct
12 Correct 144 ms 864 KB Output is correct
13 Correct 168 ms 888 KB Output is correct
14 Correct 157 ms 836 KB Output is correct
15 Correct 177 ms 860 KB Output is correct
16 Correct 153 ms 888 KB Output is correct
17 Correct 148 ms 836 KB Output is correct
18 Correct 153 ms 880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 908 KB Output is correct
2 Correct 161 ms 864 KB Output is correct
3 Correct 168 ms 892 KB Output is correct
4 Correct 153 ms 820 KB Output is correct
5 Correct 136 ms 836 KB Output is correct
6 Correct 147 ms 772 KB Output is correct
7 Correct 143 ms 904 KB Output is correct
8 Correct 159 ms 868 KB Output is correct
9 Correct 154 ms 924 KB Output is correct
10 Correct 145 ms 836 KB Output is correct
11 Correct 144 ms 836 KB Output is correct
12 Correct 144 ms 864 KB Output is correct
13 Correct 168 ms 888 KB Output is correct
14 Correct 157 ms 836 KB Output is correct
15 Correct 177 ms 860 KB Output is correct
16 Correct 153 ms 888 KB Output is correct
17 Correct 148 ms 836 KB Output is correct
18 Correct 153 ms 880 KB Output is correct
19 Correct 467 ms 16280 KB Output is correct
20 Correct 399 ms 16168 KB Output is correct
21 Correct 304 ms 15204 KB Output is correct
22 Correct 313 ms 13744 KB Output is correct
23 Correct 217 ms 1664 KB Output is correct
24 Correct 206 ms 1628 KB Output is correct
25 Correct 334 ms 16092 KB Output is correct
26 Correct 354 ms 16168 KB Output is correct
27 Correct 372 ms 16060 KB Output is correct
28 Correct 409 ms 16140 KB Output is correct
29 Correct 383 ms 15732 KB Output is correct
30 Correct 215 ms 1672 KB Output is correct
31 Correct 376 ms 16148 KB Output is correct
32 Correct 381 ms 14732 KB Output is correct
33 Correct 204 ms 1688 KB Output is correct
34 Correct 357 ms 16164 KB Output is correct
35 Correct 284 ms 12216 KB Output is correct
36 Correct 203 ms 1696 KB Output is correct
37 Correct 199 ms 1604 KB Output is correct
38 Correct 374 ms 16172 KB Output is correct
39 Correct 230 ms 16156 KB Output is correct
40 Correct 300 ms 11012 KB Output is correct
41 Correct 507 ms 16364 KB Output is correct
42 Correct 236 ms 16292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 908 KB Output is correct
2 Correct 161 ms 864 KB Output is correct
3 Correct 168 ms 892 KB Output is correct
4 Correct 153 ms 820 KB Output is correct
5 Correct 136 ms 836 KB Output is correct
6 Correct 147 ms 772 KB Output is correct
7 Correct 143 ms 904 KB Output is correct
8 Correct 159 ms 868 KB Output is correct
9 Correct 154 ms 924 KB Output is correct
10 Correct 145 ms 836 KB Output is correct
11 Correct 144 ms 836 KB Output is correct
12 Correct 144 ms 864 KB Output is correct
13 Correct 168 ms 888 KB Output is correct
14 Correct 157 ms 836 KB Output is correct
15 Correct 177 ms 860 KB Output is correct
16 Correct 153 ms 888 KB Output is correct
17 Correct 148 ms 836 KB Output is correct
18 Correct 153 ms 880 KB Output is correct
19 Correct 319 ms 788 KB Output is correct
20 Correct 335 ms 888 KB Output is correct
21 Correct 188 ms 916 KB Output is correct
22 Correct 155 ms 1028 KB Output is correct
23 Correct 170 ms 836 KB Output is correct
24 Correct 166 ms 820 KB Output is correct
25 Correct 172 ms 836 KB Output is correct
26 Correct 162 ms 776 KB Output is correct
27 Correct 145 ms 836 KB Output is correct
28 Correct 138 ms 788 KB Output is correct
29 Correct 148 ms 812 KB Output is correct
30 Correct 127 ms 760 KB Output is correct
31 Correct 321 ms 896 KB Output is correct
32 Correct 300 ms 988 KB Output is correct
33 Correct 303 ms 836 KB Output is correct
34 Correct 275 ms 888 KB Output is correct
35 Correct 305 ms 868 KB Output is correct
36 Correct 307 ms 888 KB Output is correct
37 Correct 309 ms 896 KB Output is correct
38 Correct 314 ms 880 KB Output is correct
39 Correct 314 ms 976 KB Output is correct
40 Correct 315 ms 920 KB Output is correct
41 Correct 300 ms 836 KB Output is correct
42 Correct 303 ms 892 KB Output is correct
43 Correct 290 ms 992 KB Output is correct
44 Correct 303 ms 884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 908 KB Output is correct
2 Correct 161 ms 864 KB Output is correct
3 Correct 168 ms 892 KB Output is correct
4 Correct 153 ms 820 KB Output is correct
5 Correct 136 ms 836 KB Output is correct
6 Correct 147 ms 772 KB Output is correct
7 Correct 143 ms 904 KB Output is correct
8 Correct 159 ms 868 KB Output is correct
9 Correct 154 ms 924 KB Output is correct
10 Correct 145 ms 836 KB Output is correct
11 Correct 144 ms 836 KB Output is correct
12 Correct 144 ms 864 KB Output is correct
13 Correct 168 ms 888 KB Output is correct
14 Correct 157 ms 836 KB Output is correct
15 Correct 177 ms 860 KB Output is correct
16 Correct 153 ms 888 KB Output is correct
17 Correct 148 ms 836 KB Output is correct
18 Correct 153 ms 880 KB Output is correct
19 Correct 467 ms 16280 KB Output is correct
20 Correct 399 ms 16168 KB Output is correct
21 Correct 304 ms 15204 KB Output is correct
22 Correct 313 ms 13744 KB Output is correct
23 Correct 217 ms 1664 KB Output is correct
24 Correct 206 ms 1628 KB Output is correct
25 Correct 334 ms 16092 KB Output is correct
26 Correct 354 ms 16168 KB Output is correct
27 Correct 372 ms 16060 KB Output is correct
28 Correct 409 ms 16140 KB Output is correct
29 Correct 383 ms 15732 KB Output is correct
30 Correct 215 ms 1672 KB Output is correct
31 Correct 376 ms 16148 KB Output is correct
32 Correct 381 ms 14732 KB Output is correct
33 Correct 204 ms 1688 KB Output is correct
34 Correct 357 ms 16164 KB Output is correct
35 Correct 284 ms 12216 KB Output is correct
36 Correct 203 ms 1696 KB Output is correct
37 Correct 199 ms 1604 KB Output is correct
38 Correct 374 ms 16172 KB Output is correct
39 Correct 230 ms 16156 KB Output is correct
40 Correct 300 ms 11012 KB Output is correct
41 Correct 507 ms 16364 KB Output is correct
42 Correct 236 ms 16292 KB Output is correct
43 Correct 319 ms 788 KB Output is correct
44 Correct 335 ms 888 KB Output is correct
45 Correct 188 ms 916 KB Output is correct
46 Correct 155 ms 1028 KB Output is correct
47 Correct 170 ms 836 KB Output is correct
48 Correct 166 ms 820 KB Output is correct
49 Correct 172 ms 836 KB Output is correct
50 Correct 162 ms 776 KB Output is correct
51 Correct 145 ms 836 KB Output is correct
52 Correct 138 ms 788 KB Output is correct
53 Correct 148 ms 812 KB Output is correct
54 Correct 127 ms 760 KB Output is correct
55 Correct 321 ms 896 KB Output is correct
56 Correct 300 ms 988 KB Output is correct
57 Correct 303 ms 836 KB Output is correct
58 Correct 275 ms 888 KB Output is correct
59 Correct 305 ms 868 KB Output is correct
60 Correct 307 ms 888 KB Output is correct
61 Correct 309 ms 896 KB Output is correct
62 Correct 314 ms 880 KB Output is correct
63 Correct 314 ms 976 KB Output is correct
64 Correct 315 ms 920 KB Output is correct
65 Correct 300 ms 836 KB Output is correct
66 Correct 303 ms 892 KB Output is correct
67 Correct 290 ms 992 KB Output is correct
68 Correct 303 ms 884 KB Output is correct
69 Correct 1265 ms 38264 KB Output is correct
70 Correct 1096 ms 45608 KB Output is correct
71 Correct 264 ms 1860 KB Output is correct
72 Correct 249 ms 1896 KB Output is correct
73 Correct 254 ms 1988 KB Output is correct
74 Correct 291 ms 13492 KB Output is correct
75 Correct 201 ms 1604 KB Output is correct
76 Correct 336 ms 16244 KB Output is correct
77 Correct 316 ms 13620 KB Output is correct
78 Correct 197 ms 1604 KB Output is correct
79 Correct 197 ms 1728 KB Output is correct
80 Correct 912 ms 32752 KB Output is correct
81 Correct 476 ms 3220 KB Output is correct
82 Correct 1002 ms 45528 KB Output is correct
83 Correct 991 ms 42828 KB Output is correct
84 Correct 492 ms 3140 KB Output is correct
85 Correct 482 ms 3248 KB Output is correct
86 Correct 1066 ms 34904 KB Output is correct
87 Correct 1176 ms 45584 KB Output is correct
88 Correct 528 ms 3256 KB Output is correct
89 Correct 1088 ms 40220 KB Output is correct
90 Correct 1122 ms 45512 KB Output is correct
91 Correct 508 ms 3196 KB Output is correct
92 Correct 914 ms 34576 KB Output is correct
93 Correct 496 ms 3144 KB Output is correct
94 Correct 490 ms 3144 KB Output is correct
95 Correct 522 ms 3164 KB Output is correct
96 Correct 387 ms 16284 KB Output is correct
97 Correct 591 ms 45544 KB Output is correct
98 Correct 1050 ms 30316 KB Output is correct
99 Correct 1649 ms 45812 KB Output is correct
100 Correct 668 ms 45652 KB Output is correct