Submission #501575

# Submission time Handle Problem Language Result Execution time Memory
501575 2022-01-04T05:39:54 Z amunduzbaev Crossing (JOI21_crossing) C++14
100 / 100
248 ms 19712 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

const int N = 2e5 + 5;
const int P = 167;
const int mod = (119 << 23) + 1;
int pref[N], pw[N];

struct ST{
	int tree[N * 4], p[N * 4];
	void push(int x, int lx, int rx){
		if(lx == rx || !(~p[x])) return;
		int m = (lx + rx) >> 1;
		tree[x<<1] = p[x] * 1ll * pref[m - lx] % mod, p[x<<1] = p[x];
		tree[x<<1|1] = p[x] * 1ll * pref[rx - m - 1] % mod, p[x<<1|1] = p[x];
		p[x] = -1;
	}
	
	void sett(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return;
		if(lx >= l && rx <= r){
			tree[x] = v * 1ll * pref[rx - lx] % mod;
			p[x] = v; return;
		} push(x, lx, rx);
		int m = (lx + rx) >> 1;
		sett(l, r, v, lx, m, x<<1), sett(l, r, v, m+1, rx, x<<1|1);
		tree[x] = (tree[x<<1] + tree[x<<1|1] * 1ll * pw[m - lx + 1]) % mod;
	}
}tree;

string operator + (string s, string t){
	for(int i=0;i<(int)s.size();i++){
		if(s[i] == t[i]) continue;
		s[i] = 3 - s[i] - t[i];
	} return s;
}

int HH(string t){
	int res = 0;
	for(int i=0;i<(int)t.size();i++){
		res = (res + pw[i] * 1ll * t[i]) % mod;
	} return res;
}

string take(string s){
	for(int i=0;i<(int)s.size();i++){
		if(s[i] == 'J') s[i] = 0;
		if(s[i] == 'O') s[i] = 1;
		if(s[i] == 'I') s[i] = 2;
	} return s;
}

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);

	memset(tree.p, -1, sizeof tree.p);
	pw[0] = pref[0] = 1;
	for(int i=1;i<N;i++){
		pw[i] = pw[i-1] * 1ll * P % mod;
		pref[i] = (pref[i-1] + pw[i]) % mod;
	}
	
	int n; cin>>n;
	string a, b, c; cin>>a>>b>>c;
	//~ cout<<b + c<<"\n";
	a = take(a), b = take(b), c = take(c);
	vector<int> tot;
	tot.push_back(HH(a));
	tot.push_back(HH(b));
	tot.push_back(HH(c));
	tot.push_back(HH(a + b));
	tot.push_back(HH(b + c));
	tot.push_back(HH(a + c));
	tot.push_back(HH((a + c) + b));
	tot.push_back(HH((a + b) + c));
	tot.push_back(HH((b + c) + a));
	
	auto check = [&](){
		int tmp = tree.tree[1];
		//~ cout<<tmp<<" "<<tot[0]<<"\n";
		for(auto x : tot){
			if(x == tmp){
				cout<<"Yes\n";
				return;
			}
		} cout<<"No\n";
	};
	
	int q; cin>>q;
	string s; cin>>s; 
	//~ cout<<s<<"\n";
	s = take(s);
	for(int i=0;i<n;i++) tree.sett(i, i, s[i]);
	check();
	while(q--){
		int l, r; char c; cin>>l>>r>>c, l--, r--;
		if(c == 'J') c = 0;
		if(c == 'O') c = 1;
		if(c == 'I') c = 2;
		tree.sett(l, r, c);
		check();
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:36: warning: array subscript 200005 is above array bounds of 'long long int [200005]' [-Warray-bounds]
   25 |    tree[x] = v * 1ll * pref[rx - lx] % mod;
      |                        ~~~~~~~~~~~~^
Main.cpp:10:5: note: while referencing 'pref'
   10 | int pref[N], pw[N];
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 82 ms 11768 KB Output is correct
2 Correct 86 ms 11768 KB Output is correct
3 Correct 91 ms 11740 KB Output is correct
4 Correct 77 ms 11724 KB Output is correct
5 Correct 79 ms 11720 KB Output is correct
6 Correct 77 ms 11692 KB Output is correct
7 Correct 79 ms 11816 KB Output is correct
8 Correct 85 ms 11868 KB Output is correct
9 Correct 80 ms 11896 KB Output is correct
10 Correct 81 ms 11844 KB Output is correct
11 Correct 85 ms 11884 KB Output is correct
12 Correct 81 ms 11844 KB Output is correct
13 Correct 83 ms 11780 KB Output is correct
14 Correct 81 ms 11776 KB Output is correct
15 Correct 82 ms 11780 KB Output is correct
16 Correct 91 ms 11852 KB Output is correct
17 Correct 84 ms 11828 KB Output is correct
18 Correct 88 ms 11720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 11768 KB Output is correct
2 Correct 86 ms 11768 KB Output is correct
3 Correct 91 ms 11740 KB Output is correct
4 Correct 77 ms 11724 KB Output is correct
5 Correct 79 ms 11720 KB Output is correct
6 Correct 77 ms 11692 KB Output is correct
7 Correct 79 ms 11816 KB Output is correct
8 Correct 85 ms 11868 KB Output is correct
9 Correct 80 ms 11896 KB Output is correct
10 Correct 81 ms 11844 KB Output is correct
11 Correct 85 ms 11884 KB Output is correct
12 Correct 81 ms 11844 KB Output is correct
13 Correct 83 ms 11780 KB Output is correct
14 Correct 81 ms 11776 KB Output is correct
15 Correct 82 ms 11780 KB Output is correct
16 Correct 91 ms 11852 KB Output is correct
17 Correct 84 ms 11828 KB Output is correct
18 Correct 88 ms 11720 KB Output is correct
19 Correct 240 ms 19492 KB Output is correct
20 Correct 225 ms 19388 KB Output is correct
21 Correct 177 ms 18664 KB Output is correct
22 Correct 178 ms 18036 KB Output is correct
23 Correct 105 ms 12868 KB Output is correct
24 Correct 108 ms 12860 KB Output is correct
25 Correct 188 ms 19448 KB Output is correct
26 Correct 198 ms 19396 KB Output is correct
27 Correct 193 ms 19408 KB Output is correct
28 Correct 193 ms 19360 KB Output is correct
29 Correct 199 ms 19196 KB Output is correct
30 Correct 116 ms 12964 KB Output is correct
31 Correct 192 ms 19400 KB Output is correct
32 Correct 185 ms 18540 KB Output is correct
33 Correct 107 ms 12912 KB Output is correct
34 Correct 199 ms 19444 KB Output is correct
35 Correct 165 ms 17512 KB Output is correct
36 Correct 103 ms 12996 KB Output is correct
37 Correct 107 ms 12944 KB Output is correct
38 Correct 207 ms 19264 KB Output is correct
39 Correct 168 ms 19712 KB Output is correct
40 Correct 160 ms 17176 KB Output is correct
41 Correct 236 ms 19568 KB Output is correct
42 Correct 143 ms 18908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 11768 KB Output is correct
2 Correct 86 ms 11768 KB Output is correct
3 Correct 91 ms 11740 KB Output is correct
4 Correct 77 ms 11724 KB Output is correct
5 Correct 79 ms 11720 KB Output is correct
6 Correct 77 ms 11692 KB Output is correct
7 Correct 79 ms 11816 KB Output is correct
8 Correct 85 ms 11868 KB Output is correct
9 Correct 80 ms 11896 KB Output is correct
10 Correct 81 ms 11844 KB Output is correct
11 Correct 85 ms 11884 KB Output is correct
12 Correct 81 ms 11844 KB Output is correct
13 Correct 83 ms 11780 KB Output is correct
14 Correct 81 ms 11776 KB Output is correct
15 Correct 82 ms 11780 KB Output is correct
16 Correct 91 ms 11852 KB Output is correct
17 Correct 84 ms 11828 KB Output is correct
18 Correct 88 ms 11720 KB Output is correct
19 Correct 82 ms 11716 KB Output is correct
20 Correct 87 ms 11632 KB Output is correct
21 Correct 82 ms 11780 KB Output is correct
22 Correct 75 ms 11580 KB Output is correct
23 Correct 81 ms 11764 KB Output is correct
24 Correct 79 ms 11772 KB Output is correct
25 Correct 81 ms 11760 KB Output is correct
26 Correct 77 ms 11772 KB Output is correct
27 Correct 81 ms 11876 KB Output is correct
28 Correct 78 ms 11588 KB Output is correct
29 Correct 84 ms 11848 KB Output is correct
30 Correct 75 ms 11616 KB Output is correct
31 Correct 87 ms 11844 KB Output is correct
32 Correct 82 ms 11812 KB Output is correct
33 Correct 81 ms 11828 KB Output is correct
34 Correct 77 ms 11716 KB Output is correct
35 Correct 81 ms 11796 KB Output is correct
36 Correct 86 ms 11844 KB Output is correct
37 Correct 80 ms 11780 KB Output is correct
38 Correct 80 ms 11844 KB Output is correct
39 Correct 85 ms 11768 KB Output is correct
40 Correct 83 ms 11768 KB Output is correct
41 Correct 86 ms 11844 KB Output is correct
42 Correct 82 ms 11808 KB Output is correct
43 Correct 81 ms 11844 KB Output is correct
44 Correct 82 ms 11772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 11768 KB Output is correct
2 Correct 86 ms 11768 KB Output is correct
3 Correct 91 ms 11740 KB Output is correct
4 Correct 77 ms 11724 KB Output is correct
5 Correct 79 ms 11720 KB Output is correct
6 Correct 77 ms 11692 KB Output is correct
7 Correct 79 ms 11816 KB Output is correct
8 Correct 85 ms 11868 KB Output is correct
9 Correct 80 ms 11896 KB Output is correct
10 Correct 81 ms 11844 KB Output is correct
11 Correct 85 ms 11884 KB Output is correct
12 Correct 81 ms 11844 KB Output is correct
13 Correct 83 ms 11780 KB Output is correct
14 Correct 81 ms 11776 KB Output is correct
15 Correct 82 ms 11780 KB Output is correct
16 Correct 91 ms 11852 KB Output is correct
17 Correct 84 ms 11828 KB Output is correct
18 Correct 88 ms 11720 KB Output is correct
19 Correct 240 ms 19492 KB Output is correct
20 Correct 225 ms 19388 KB Output is correct
21 Correct 177 ms 18664 KB Output is correct
22 Correct 178 ms 18036 KB Output is correct
23 Correct 105 ms 12868 KB Output is correct
24 Correct 108 ms 12860 KB Output is correct
25 Correct 188 ms 19448 KB Output is correct
26 Correct 198 ms 19396 KB Output is correct
27 Correct 193 ms 19408 KB Output is correct
28 Correct 193 ms 19360 KB Output is correct
29 Correct 199 ms 19196 KB Output is correct
30 Correct 116 ms 12964 KB Output is correct
31 Correct 192 ms 19400 KB Output is correct
32 Correct 185 ms 18540 KB Output is correct
33 Correct 107 ms 12912 KB Output is correct
34 Correct 199 ms 19444 KB Output is correct
35 Correct 165 ms 17512 KB Output is correct
36 Correct 103 ms 12996 KB Output is correct
37 Correct 107 ms 12944 KB Output is correct
38 Correct 207 ms 19264 KB Output is correct
39 Correct 168 ms 19712 KB Output is correct
40 Correct 160 ms 17176 KB Output is correct
41 Correct 236 ms 19568 KB Output is correct
42 Correct 143 ms 18908 KB Output is correct
43 Correct 82 ms 11716 KB Output is correct
44 Correct 87 ms 11632 KB Output is correct
45 Correct 82 ms 11780 KB Output is correct
46 Correct 75 ms 11580 KB Output is correct
47 Correct 81 ms 11764 KB Output is correct
48 Correct 79 ms 11772 KB Output is correct
49 Correct 81 ms 11760 KB Output is correct
50 Correct 77 ms 11772 KB Output is correct
51 Correct 81 ms 11876 KB Output is correct
52 Correct 78 ms 11588 KB Output is correct
53 Correct 84 ms 11848 KB Output is correct
54 Correct 75 ms 11616 KB Output is correct
55 Correct 87 ms 11844 KB Output is correct
56 Correct 82 ms 11812 KB Output is correct
57 Correct 81 ms 11828 KB Output is correct
58 Correct 77 ms 11716 KB Output is correct
59 Correct 81 ms 11796 KB Output is correct
60 Correct 86 ms 11844 KB Output is correct
61 Correct 80 ms 11780 KB Output is correct
62 Correct 80 ms 11844 KB Output is correct
63 Correct 85 ms 11768 KB Output is correct
64 Correct 83 ms 11768 KB Output is correct
65 Correct 86 ms 11844 KB Output is correct
66 Correct 82 ms 11808 KB Output is correct
67 Correct 81 ms 11844 KB Output is correct
68 Correct 82 ms 11772 KB Output is correct
69 Correct 202 ms 18124 KB Output is correct
70 Correct 230 ms 19328 KB Output is correct
71 Correct 104 ms 12876 KB Output is correct
72 Correct 104 ms 12968 KB Output is correct
73 Correct 109 ms 13024 KB Output is correct
74 Correct 170 ms 18068 KB Output is correct
75 Correct 102 ms 12868 KB Output is correct
76 Correct 202 ms 19712 KB Output is correct
77 Correct 175 ms 18284 KB Output is correct
78 Correct 102 ms 12924 KB Output is correct
79 Correct 102 ms 12920 KB Output is correct
80 Correct 159 ms 17352 KB Output is correct
81 Correct 108 ms 13036 KB Output is correct
82 Correct 195 ms 19468 KB Output is correct
83 Correct 186 ms 18748 KB Output is correct
84 Correct 112 ms 13020 KB Output is correct
85 Correct 107 ms 12920 KB Output is correct
86 Correct 175 ms 17628 KB Output is correct
87 Correct 202 ms 19360 KB Output is correct
88 Correct 111 ms 12920 KB Output is correct
89 Correct 179 ms 18452 KB Output is correct
90 Correct 200 ms 19384 KB Output is correct
91 Correct 111 ms 12952 KB Output is correct
92 Correct 174 ms 17556 KB Output is correct
93 Correct 110 ms 13048 KB Output is correct
94 Correct 105 ms 12832 KB Output is correct
95 Correct 102 ms 12868 KB Output is correct
96 Correct 202 ms 19276 KB Output is correct
97 Correct 164 ms 19488 KB Output is correct
98 Correct 164 ms 17160 KB Output is correct
99 Correct 248 ms 19700 KB Output is correct
100 Correct 149 ms 18812 KB Output is correct