답안 #421890

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421890 2021-06-09T13:19:07 Z hhhhaura Crossing (JOI21_crossing) C++14
100 / 100
368 ms 22244 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	int n, ans, cur; 
	const int C = 37;
	random;
	vector<int> s, c;
	vector<vector<int>> a;
	map<int, int> mp;
	set<int> b;
	int rolling(vector<int> a) {
		int ans = 0;
		rep(i, 1, n) ans = (ans + (c[i] - c[i - 1]) * s[a[i]] % MOD) % MOD;
		return (ans % MOD + MOD) % MOD;
	}
	vector<int> operate(vector<int> a, vector<int> b) {
		vector<int> c(n + 1, 0);
		rep(i, 1, n) {
			if(a[i] == b[i]) c[i] = a[i];
			else if(a[i] != 0 && b[i] != 0) c[i] = 0;
			else if(a[i] != 1 && b[i] != 1) c[i] = 1;
			else c[i] = 2;
		}
		return c;
	}
	void init_(int _n, vector<string> _s) {
		n = _n, ans = 0, cur = 0;
		c.assign(n + 1, 1);
		s.assign(3, 0);
		a.assign(4, vector<int>(n + 1, 0));
		mp.clear();
		rep(i, 0, 2) s[i] = rnd();
		rep(i, 1, n) {
			rep(j, 0, 3) {
				if(_s[j][i - 1] == 'J') a[j][i] = 0;
				else if(_s[j][i - 1] == 'O') a[j][i] = 1;
				else a[j][i] = 2;
			}
			c[i] = c[i - 1] * C % MOD;
		}
		rep(i, 1, n) c[i] = (c[i - 1] + c[i]) % MOD;
		rep(i, 0, 2) b.insert(rolling(a[i]));
		b.insert(rolling(operate(a[0], a[1])));
		b.insert(rolling(operate(a[0], a[2])));
		b.insert(rolling(operate(a[2], a[1])));
		b.insert(rolling(operate(operate(a[0], a[1]), a[2])));
		b.insert(rolling(operate(operate(a[0], a[2]), a[1])));
		b.insert(rolling(operate(operate(a[2], a[1]), a[0])));
		cur = rolling(a[3]);
		ans = bool(b.find(cur) != b.end());
		rep(i, 1, n) mp[i] = a[3][i];
		mp[n + 1] = -1;
		
		return;
	}
	bool query(int L, int R, int x) {
		auto it = mp.upper_bound(L);
		auto temp = it, pre = it;
		bool yes = 1;
		if(pre != mp.begin()) {
			temp = prev(pre);
			int l = L, r = pre -> first - 1;
			if(r >= R) {
				cur -= (c[R] - c[l - 1]) * s[temp -> second] % MOD;
				cur = (cur % MOD + MOD) % MOD;
				if(R + 1 <= r) mp[R + 1] = temp -> second;
				yes = 0;
			}
			else {
				cur -= (c[r] - c[l - 1]) * s[temp -> second] % MOD;
				cur = (cur % MOD + MOD) % MOD;
			}
		}
		while(yes && next(it) != mp.end()) {
			int l = it -> first, r = next(it) -> first - 1;
			if(r >= R) {
				cur -= (c[R] - c[l - 1]) * s[it -> second] % MOD;
				cur = (cur % MOD + MOD) % MOD;
				if(R + 1 <= r) mp[R + 1] = it -> second;
				mp.erase(it);
				break;
			}
			else {
				cur -= (c[r] - c[l - 1]) * s[it -> second] % MOD;
				cur = (cur % MOD + MOD) % MOD;
				temp = it;
				it = next(it);
				mp.erase(temp);
			}
		}
		
		mp[L] = x;
		cur += (c[R] - c[L - 1]) * s[x] % MOD;
		cur = (cur % MOD + MOD) % MOD;
		return b.find(cur) != b.end();	
	}
}; 
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q; cin >> n;
	vector<string> s(4, "");
	rep(i, 0, 2) cin >> s[i];
	cin >> q >> s[3];
	init_(n, s);
	if(ans) cout << "Yes\n";
	else cout << "No\n";
	rep(i, 1, q) {
		int L, R, x; char cc;
		cin >> L >> R >> cc; 
		if(cc == 'J') x = 0;
		else if(cc == 'O') x = 1;
		else x = 2;
		if(query(L, R, x)) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}  

Compilation message

Main.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
Main.cpp:24:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |             ^~~~
Main.cpp:24:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   24 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L; }
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 776 KB Output is correct
2 Correct 101 ms 808 KB Output is correct
3 Correct 86 ms 908 KB Output is correct
4 Correct 110 ms 780 KB Output is correct
5 Correct 90 ms 828 KB Output is correct
6 Correct 98 ms 868 KB Output is correct
7 Correct 92 ms 848 KB Output is correct
8 Correct 96 ms 908 KB Output is correct
9 Correct 98 ms 848 KB Output is correct
10 Correct 96 ms 892 KB Output is correct
11 Correct 105 ms 888 KB Output is correct
12 Correct 97 ms 964 KB Output is correct
13 Correct 97 ms 816 KB Output is correct
14 Correct 101 ms 884 KB Output is correct
15 Correct 99 ms 820 KB Output is correct
16 Correct 100 ms 844 KB Output is correct
17 Correct 101 ms 828 KB Output is correct
18 Correct 76 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 776 KB Output is correct
2 Correct 101 ms 808 KB Output is correct
3 Correct 86 ms 908 KB Output is correct
4 Correct 110 ms 780 KB Output is correct
5 Correct 90 ms 828 KB Output is correct
6 Correct 98 ms 868 KB Output is correct
7 Correct 92 ms 848 KB Output is correct
8 Correct 96 ms 908 KB Output is correct
9 Correct 98 ms 848 KB Output is correct
10 Correct 96 ms 892 KB Output is correct
11 Correct 105 ms 888 KB Output is correct
12 Correct 97 ms 964 KB Output is correct
13 Correct 97 ms 816 KB Output is correct
14 Correct 101 ms 884 KB Output is correct
15 Correct 99 ms 820 KB Output is correct
16 Correct 100 ms 844 KB Output is correct
17 Correct 101 ms 828 KB Output is correct
18 Correct 76 ms 836 KB Output is correct
19 Correct 242 ms 22152 KB Output is correct
20 Correct 234 ms 22132 KB Output is correct
21 Correct 341 ms 20904 KB Output is correct
22 Correct 258 ms 18724 KB Output is correct
23 Correct 165 ms 1952 KB Output is correct
24 Correct 160 ms 1988 KB Output is correct
25 Correct 368 ms 22244 KB Output is correct
26 Correct 312 ms 22220 KB Output is correct
27 Correct 262 ms 22212 KB Output is correct
28 Correct 282 ms 22208 KB Output is correct
29 Correct 232 ms 21648 KB Output is correct
30 Correct 136 ms 1992 KB Output is correct
31 Correct 242 ms 22172 KB Output is correct
32 Correct 235 ms 20256 KB Output is correct
33 Correct 155 ms 2004 KB Output is correct
34 Correct 254 ms 22136 KB Output is correct
35 Correct 259 ms 16620 KB Output is correct
36 Correct 154 ms 1980 KB Output is correct
37 Correct 162 ms 1984 KB Output is correct
38 Correct 185 ms 22124 KB Output is correct
39 Correct 229 ms 22236 KB Output is correct
40 Correct 287 ms 14820 KB Output is correct
41 Correct 207 ms 22228 KB Output is correct
42 Correct 136 ms 22172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 776 KB Output is correct
2 Correct 101 ms 808 KB Output is correct
3 Correct 86 ms 908 KB Output is correct
4 Correct 110 ms 780 KB Output is correct
5 Correct 90 ms 828 KB Output is correct
6 Correct 98 ms 868 KB Output is correct
7 Correct 92 ms 848 KB Output is correct
8 Correct 96 ms 908 KB Output is correct
9 Correct 98 ms 848 KB Output is correct
10 Correct 96 ms 892 KB Output is correct
11 Correct 105 ms 888 KB Output is correct
12 Correct 97 ms 964 KB Output is correct
13 Correct 97 ms 816 KB Output is correct
14 Correct 101 ms 884 KB Output is correct
15 Correct 99 ms 820 KB Output is correct
16 Correct 100 ms 844 KB Output is correct
17 Correct 101 ms 828 KB Output is correct
18 Correct 76 ms 836 KB Output is correct
19 Correct 100 ms 800 KB Output is correct
20 Correct 86 ms 904 KB Output is correct
21 Correct 105 ms 840 KB Output is correct
22 Correct 88 ms 860 KB Output is correct
23 Correct 98 ms 848 KB Output is correct
24 Correct 97 ms 840 KB Output is correct
25 Correct 108 ms 800 KB Output is correct
26 Correct 97 ms 932 KB Output is correct
27 Correct 97 ms 804 KB Output is correct
28 Correct 106 ms 844 KB Output is correct
29 Correct 99 ms 812 KB Output is correct
30 Correct 90 ms 836 KB Output is correct
31 Correct 98 ms 876 KB Output is correct
32 Correct 100 ms 924 KB Output is correct
33 Correct 99 ms 828 KB Output is correct
34 Correct 94 ms 852 KB Output is correct
35 Correct 98 ms 884 KB Output is correct
36 Correct 102 ms 828 KB Output is correct
37 Correct 101 ms 900 KB Output is correct
38 Correct 101 ms 924 KB Output is correct
39 Correct 114 ms 860 KB Output is correct
40 Correct 101 ms 880 KB Output is correct
41 Correct 99 ms 920 KB Output is correct
42 Correct 103 ms 852 KB Output is correct
43 Correct 99 ms 964 KB Output is correct
44 Correct 102 ms 912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 776 KB Output is correct
2 Correct 101 ms 808 KB Output is correct
3 Correct 86 ms 908 KB Output is correct
4 Correct 110 ms 780 KB Output is correct
5 Correct 90 ms 828 KB Output is correct
6 Correct 98 ms 868 KB Output is correct
7 Correct 92 ms 848 KB Output is correct
8 Correct 96 ms 908 KB Output is correct
9 Correct 98 ms 848 KB Output is correct
10 Correct 96 ms 892 KB Output is correct
11 Correct 105 ms 888 KB Output is correct
12 Correct 97 ms 964 KB Output is correct
13 Correct 97 ms 816 KB Output is correct
14 Correct 101 ms 884 KB Output is correct
15 Correct 99 ms 820 KB Output is correct
16 Correct 100 ms 844 KB Output is correct
17 Correct 101 ms 828 KB Output is correct
18 Correct 76 ms 836 KB Output is correct
19 Correct 242 ms 22152 KB Output is correct
20 Correct 234 ms 22132 KB Output is correct
21 Correct 341 ms 20904 KB Output is correct
22 Correct 258 ms 18724 KB Output is correct
23 Correct 165 ms 1952 KB Output is correct
24 Correct 160 ms 1988 KB Output is correct
25 Correct 368 ms 22244 KB Output is correct
26 Correct 312 ms 22220 KB Output is correct
27 Correct 262 ms 22212 KB Output is correct
28 Correct 282 ms 22208 KB Output is correct
29 Correct 232 ms 21648 KB Output is correct
30 Correct 136 ms 1992 KB Output is correct
31 Correct 242 ms 22172 KB Output is correct
32 Correct 235 ms 20256 KB Output is correct
33 Correct 155 ms 2004 KB Output is correct
34 Correct 254 ms 22136 KB Output is correct
35 Correct 259 ms 16620 KB Output is correct
36 Correct 154 ms 1980 KB Output is correct
37 Correct 162 ms 1984 KB Output is correct
38 Correct 185 ms 22124 KB Output is correct
39 Correct 229 ms 22236 KB Output is correct
40 Correct 287 ms 14820 KB Output is correct
41 Correct 207 ms 22228 KB Output is correct
42 Correct 136 ms 22172 KB Output is correct
43 Correct 100 ms 800 KB Output is correct
44 Correct 86 ms 904 KB Output is correct
45 Correct 105 ms 840 KB Output is correct
46 Correct 88 ms 860 KB Output is correct
47 Correct 98 ms 848 KB Output is correct
48 Correct 97 ms 840 KB Output is correct
49 Correct 108 ms 800 KB Output is correct
50 Correct 97 ms 932 KB Output is correct
51 Correct 97 ms 804 KB Output is correct
52 Correct 106 ms 844 KB Output is correct
53 Correct 99 ms 812 KB Output is correct
54 Correct 90 ms 836 KB Output is correct
55 Correct 98 ms 876 KB Output is correct
56 Correct 100 ms 924 KB Output is correct
57 Correct 99 ms 828 KB Output is correct
58 Correct 94 ms 852 KB Output is correct
59 Correct 98 ms 884 KB Output is correct
60 Correct 102 ms 828 KB Output is correct
61 Correct 101 ms 900 KB Output is correct
62 Correct 101 ms 924 KB Output is correct
63 Correct 114 ms 860 KB Output is correct
64 Correct 101 ms 880 KB Output is correct
65 Correct 99 ms 920 KB Output is correct
66 Correct 103 ms 852 KB Output is correct
67 Correct 99 ms 964 KB Output is correct
68 Correct 102 ms 912 KB Output is correct
69 Correct 220 ms 18692 KB Output is correct
70 Correct 230 ms 22148 KB Output is correct
71 Correct 156 ms 1984 KB Output is correct
72 Correct 157 ms 1940 KB Output is correct
73 Correct 158 ms 2036 KB Output is correct
74 Correct 285 ms 19084 KB Output is correct
75 Correct 155 ms 1928 KB Output is correct
76 Correct 355 ms 22156 KB Output is correct
77 Correct 286 ms 18620 KB Output is correct
78 Correct 154 ms 1928 KB Output is correct
79 Correct 152 ms 2092 KB Output is correct
80 Correct 267 ms 15896 KB Output is correct
81 Correct 155 ms 1984 KB Output is correct
82 Correct 324 ms 22216 KB Output is correct
83 Correct 300 ms 21064 KB Output is correct
84 Correct 157 ms 2012 KB Output is correct
85 Correct 165 ms 1920 KB Output is correct
86 Correct 199 ms 16932 KB Output is correct
87 Correct 245 ms 22148 KB Output is correct
88 Correct 164 ms 2004 KB Output is correct
89 Correct 233 ms 19560 KB Output is correct
90 Correct 280 ms 22152 KB Output is correct
91 Correct 176 ms 1940 KB Output is correct
92 Correct 276 ms 16664 KB Output is correct
93 Correct 159 ms 1968 KB Output is correct
94 Correct 162 ms 1936 KB Output is correct
95 Correct 156 ms 1996 KB Output is correct
96 Correct 179 ms 22128 KB Output is correct
97 Correct 206 ms 22136 KB Output is correct
98 Correct 325 ms 14828 KB Output is correct
99 Correct 219 ms 22200 KB Output is correct
100 Correct 146 ms 22152 KB Output is correct