답안 #420065

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420065 2021-06-08T04:41:39 Z oolimry Crossing (JOI21_crossing) C++17
100 / 100
897 ms 38320 KB
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define cnt second
#define hash first
typedef unsigned long long lint;
typedef pair<lint,lint> ii;

const lint prime = 16127;
const lint mod = 1000000007;
lint P[200005];

lint roll[7][200005];
const int dummy = 10;

inline ii merge(ii a, ii b){
	ii res = {b.hash, a.cnt+b.cnt};
	res.hash += a.hash * P[b.cnt];
	res.hash %= mod;
	return res;
}

struct node{
	int s, e, m;
	ii val;
	lint lazy = dummy;
	node *l, *r;
	
	node(int S, int E){
		s = S, e = E, m = (s+e)/2;
		val = ii(0, e-s+1);
		if(s != e){
			l = new node(s,m);
			r = new node(m+1,e);
		}
	}
	
	void apply(int L){
		if(L == dummy) return;
		val = ii(roll[L][e-s+1], e-s+1);
		lazy = L;
	}
	
	void push(){
		if(s == e) return;
		l->apply(lazy);
		r->apply(lazy);
		lazy = dummy;
	}
	
	void update(int S, int E, int L){
		push();
		if(s == S and E == e) apply(L);
		else{
			if(E <= m) l->update(S,E,L);
			else if(S >= m+1) r->update(S,E,L);
			else l->update(S,m,L), r->update(m+1,E,L);
			val = merge(l->val, r->val);
		}
	}
	
	lint query(){ push(); return val.hash; }
} *root;

int mapto[2000];
lint gethash(string s){
	lint h = 0;
	for(int i = 0;i < sz(s);i++){
		h *= prime;
		h += mapto[(int)s[i]];
		h %= mod;
	}
	return h;
}

string cross(string a, string b){
	string res = "";
	for(int i = 0;i < sz(a);i++){
		if(a[i] == b[i]) res += a[i];
		else{
			res += (char) ((int)('J')+(int)('O')+(int)('I')-a[i]-b[i]);
		}
	}
	return res;
}

set<lint> orihashes;
vector<string> S;

int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	mapto['J'] = 1;
	mapto['O'] = 3;
	mapto['I'] = 5;
	P[0] = 1;
	for(int i = 1;i <= n;i++) P[i] = (P[i-1] * prime) % mod;
	
	string s1, s2, s3;
	cin >> s1; cin >> s2; cin >> s3;
	S = {s1,s2,s3};
	orihashes.insert(gethash(s1));
	orihashes.insert(gethash(s2));
	orihashes.insert(gethash(s3));
	
	while(true){
		bool found = false;
		int m = sz(S);
		for(int i = 0;i < m;i++){
			for(int j = 0;j < m;j++){
				string s = cross(S[i],S[j]);
				lint h = gethash(s);
				if(orihashes.find(h) == orihashes.end()){
					orihashes.insert(h);
					S.push_back(s);
					found = true;
				}
			}
		}
		if(not found) break;
	}
	
	for(int x = 1;x <= 5;x++){
		lint h = 0;
		for(int i = 1;i <= n;i++){
			h *= prime;
			h += x;
			h %= mod;
			roll[x][i] = h;
		}
	}
	
	int Q; cin >> Q;
	root = new node(1,n);
	string O; cin >> O;
	for(int i = 1;i <= n;i++){
		root->update(i,i,mapto[(int)O[i-1]]);
	}
		
	for(int q = -1;q < Q;q++){
		if(orihashes.find(root->query()) != orihashes.end()) cout << "Yes\n";
		else cout << "No\n";
		
		int l, r; char c; cin >> l >> r >> c;
		root->update(l,r, mapto[(int)c]);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 856 KB Output is correct
2 Correct 84 ms 952 KB Output is correct
3 Correct 85 ms 860 KB Output is correct
4 Correct 71 ms 896 KB Output is correct
5 Correct 74 ms 916 KB Output is correct
6 Correct 76 ms 936 KB Output is correct
7 Correct 73 ms 948 KB Output is correct
8 Correct 76 ms 1052 KB Output is correct
9 Correct 82 ms 872 KB Output is correct
10 Correct 111 ms 888 KB Output is correct
11 Correct 96 ms 936 KB Output is correct
12 Correct 77 ms 956 KB Output is correct
13 Correct 78 ms 908 KB Output is correct
14 Correct 79 ms 852 KB Output is correct
15 Correct 75 ms 884 KB Output is correct
16 Correct 80 ms 908 KB Output is correct
17 Correct 75 ms 932 KB Output is correct
18 Correct 79 ms 964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 856 KB Output is correct
2 Correct 84 ms 952 KB Output is correct
3 Correct 85 ms 860 KB Output is correct
4 Correct 71 ms 896 KB Output is correct
5 Correct 74 ms 916 KB Output is correct
6 Correct 76 ms 936 KB Output is correct
7 Correct 73 ms 948 KB Output is correct
8 Correct 76 ms 1052 KB Output is correct
9 Correct 82 ms 872 KB Output is correct
10 Correct 111 ms 888 KB Output is correct
11 Correct 96 ms 936 KB Output is correct
12 Correct 77 ms 956 KB Output is correct
13 Correct 78 ms 908 KB Output is correct
14 Correct 79 ms 852 KB Output is correct
15 Correct 75 ms 884 KB Output is correct
16 Correct 80 ms 908 KB Output is correct
17 Correct 75 ms 932 KB Output is correct
18 Correct 79 ms 964 KB Output is correct
19 Correct 473 ms 36892 KB Output is correct
20 Correct 385 ms 36960 KB Output is correct
21 Correct 335 ms 34864 KB Output is correct
22 Correct 347 ms 31444 KB Output is correct
23 Correct 128 ms 2760 KB Output is correct
24 Correct 129 ms 2792 KB Output is correct
25 Correct 369 ms 36972 KB Output is correct
26 Correct 358 ms 36876 KB Output is correct
27 Correct 417 ms 36860 KB Output is correct
28 Correct 402 ms 37016 KB Output is correct
29 Correct 407 ms 35904 KB Output is correct
30 Correct 138 ms 2776 KB Output is correct
31 Correct 390 ms 36916 KB Output is correct
32 Correct 400 ms 33996 KB Output is correct
33 Correct 126 ms 2804 KB Output is correct
34 Correct 422 ms 36976 KB Output is correct
35 Correct 322 ms 27772 KB Output is correct
36 Correct 131 ms 2784 KB Output is correct
37 Correct 147 ms 2776 KB Output is correct
38 Correct 423 ms 36932 KB Output is correct
39 Correct 222 ms 36876 KB Output is correct
40 Correct 319 ms 24624 KB Output is correct
41 Correct 545 ms 37148 KB Output is correct
42 Correct 156 ms 37140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 856 KB Output is correct
2 Correct 84 ms 952 KB Output is correct
3 Correct 85 ms 860 KB Output is correct
4 Correct 71 ms 896 KB Output is correct
5 Correct 74 ms 916 KB Output is correct
6 Correct 76 ms 936 KB Output is correct
7 Correct 73 ms 948 KB Output is correct
8 Correct 76 ms 1052 KB Output is correct
9 Correct 82 ms 872 KB Output is correct
10 Correct 111 ms 888 KB Output is correct
11 Correct 96 ms 936 KB Output is correct
12 Correct 77 ms 956 KB Output is correct
13 Correct 78 ms 908 KB Output is correct
14 Correct 79 ms 852 KB Output is correct
15 Correct 75 ms 884 KB Output is correct
16 Correct 80 ms 908 KB Output is correct
17 Correct 75 ms 932 KB Output is correct
18 Correct 79 ms 964 KB Output is correct
19 Correct 86 ms 940 KB Output is correct
20 Correct 90 ms 892 KB Output is correct
21 Correct 77 ms 936 KB Output is correct
22 Correct 97 ms 900 KB Output is correct
23 Correct 76 ms 864 KB Output is correct
24 Correct 73 ms 836 KB Output is correct
25 Correct 87 ms 888 KB Output is correct
26 Correct 81 ms 832 KB Output is correct
27 Correct 92 ms 952 KB Output is correct
28 Correct 75 ms 908 KB Output is correct
29 Correct 80 ms 928 KB Output is correct
30 Correct 78 ms 856 KB Output is correct
31 Correct 78 ms 940 KB Output is correct
32 Correct 78 ms 868 KB Output is correct
33 Correct 79 ms 856 KB Output is correct
34 Correct 85 ms 828 KB Output is correct
35 Correct 90 ms 964 KB Output is correct
36 Correct 80 ms 908 KB Output is correct
37 Correct 77 ms 872 KB Output is correct
38 Correct 80 ms 964 KB Output is correct
39 Correct 77 ms 900 KB Output is correct
40 Correct 78 ms 936 KB Output is correct
41 Correct 93 ms 932 KB Output is correct
42 Correct 86 ms 960 KB Output is correct
43 Correct 73 ms 908 KB Output is correct
44 Correct 90 ms 880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 856 KB Output is correct
2 Correct 84 ms 952 KB Output is correct
3 Correct 85 ms 860 KB Output is correct
4 Correct 71 ms 896 KB Output is correct
5 Correct 74 ms 916 KB Output is correct
6 Correct 76 ms 936 KB Output is correct
7 Correct 73 ms 948 KB Output is correct
8 Correct 76 ms 1052 KB Output is correct
9 Correct 82 ms 872 KB Output is correct
10 Correct 111 ms 888 KB Output is correct
11 Correct 96 ms 936 KB Output is correct
12 Correct 77 ms 956 KB Output is correct
13 Correct 78 ms 908 KB Output is correct
14 Correct 79 ms 852 KB Output is correct
15 Correct 75 ms 884 KB Output is correct
16 Correct 80 ms 908 KB Output is correct
17 Correct 75 ms 932 KB Output is correct
18 Correct 79 ms 964 KB Output is correct
19 Correct 473 ms 36892 KB Output is correct
20 Correct 385 ms 36960 KB Output is correct
21 Correct 335 ms 34864 KB Output is correct
22 Correct 347 ms 31444 KB Output is correct
23 Correct 128 ms 2760 KB Output is correct
24 Correct 129 ms 2792 KB Output is correct
25 Correct 369 ms 36972 KB Output is correct
26 Correct 358 ms 36876 KB Output is correct
27 Correct 417 ms 36860 KB Output is correct
28 Correct 402 ms 37016 KB Output is correct
29 Correct 407 ms 35904 KB Output is correct
30 Correct 138 ms 2776 KB Output is correct
31 Correct 390 ms 36916 KB Output is correct
32 Correct 400 ms 33996 KB Output is correct
33 Correct 126 ms 2804 KB Output is correct
34 Correct 422 ms 36976 KB Output is correct
35 Correct 322 ms 27772 KB Output is correct
36 Correct 131 ms 2784 KB Output is correct
37 Correct 147 ms 2776 KB Output is correct
38 Correct 423 ms 36932 KB Output is correct
39 Correct 222 ms 36876 KB Output is correct
40 Correct 319 ms 24624 KB Output is correct
41 Correct 545 ms 37148 KB Output is correct
42 Correct 156 ms 37140 KB Output is correct
43 Correct 86 ms 940 KB Output is correct
44 Correct 90 ms 892 KB Output is correct
45 Correct 77 ms 936 KB Output is correct
46 Correct 97 ms 900 KB Output is correct
47 Correct 76 ms 864 KB Output is correct
48 Correct 73 ms 836 KB Output is correct
49 Correct 87 ms 888 KB Output is correct
50 Correct 81 ms 832 KB Output is correct
51 Correct 92 ms 952 KB Output is correct
52 Correct 75 ms 908 KB Output is correct
53 Correct 80 ms 928 KB Output is correct
54 Correct 78 ms 856 KB Output is correct
55 Correct 78 ms 940 KB Output is correct
56 Correct 78 ms 868 KB Output is correct
57 Correct 79 ms 856 KB Output is correct
58 Correct 85 ms 828 KB Output is correct
59 Correct 90 ms 964 KB Output is correct
60 Correct 80 ms 908 KB Output is correct
61 Correct 77 ms 872 KB Output is correct
62 Correct 80 ms 964 KB Output is correct
63 Correct 77 ms 900 KB Output is correct
64 Correct 78 ms 936 KB Output is correct
65 Correct 93 ms 932 KB Output is correct
66 Correct 86 ms 960 KB Output is correct
67 Correct 73 ms 908 KB Output is correct
68 Correct 90 ms 880 KB Output is correct
69 Correct 760 ms 32008 KB Output is correct
70 Correct 808 ms 38076 KB Output is correct
71 Correct 128 ms 2772 KB Output is correct
72 Correct 126 ms 2824 KB Output is correct
73 Correct 134 ms 2840 KB Output is correct
74 Correct 346 ms 30972 KB Output is correct
75 Correct 128 ms 2720 KB Output is correct
76 Correct 357 ms 36956 KB Output is correct
77 Correct 323 ms 31140 KB Output is correct
78 Correct 125 ms 2752 KB Output is correct
79 Correct 127 ms 2784 KB Output is correct
80 Correct 552 ms 27544 KB Output is correct
81 Correct 147 ms 2728 KB Output is correct
82 Correct 768 ms 38040 KB Output is correct
83 Correct 716 ms 35892 KB Output is correct
84 Correct 142 ms 2756 KB Output is correct
85 Correct 174 ms 2916 KB Output is correct
86 Correct 608 ms 29188 KB Output is correct
87 Correct 743 ms 38140 KB Output is correct
88 Correct 196 ms 2800 KB Output is correct
89 Correct 596 ms 33692 KB Output is correct
90 Correct 685 ms 38072 KB Output is correct
91 Correct 185 ms 2820 KB Output is correct
92 Correct 587 ms 28632 KB Output is correct
93 Correct 143 ms 2780 KB Output is correct
94 Correct 145 ms 2756 KB Output is correct
95 Correct 160 ms 2740 KB Output is correct
96 Correct 341 ms 36976 KB Output is correct
97 Correct 514 ms 38024 KB Output is correct
98 Correct 584 ms 25396 KB Output is correct
99 Correct 897 ms 38236 KB Output is correct
100 Correct 521 ms 38320 KB Output is correct