# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
902569 |
2024-01-10T18:19:28 Z |
qin |
Crossing (JOI21_crossing) |
C++17 |
|
944 ms |
64224 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18;
vector<string> get_strings(string &xx, string &y, string &z){
string s[3] = {xx, y, z};
int n = int(s[0].length());
map<string, int> mp;
queue<string> q;
vector<string> ret;
for(int l = 0; l < 3; ++l) mp[s[l]] = 1, q.emplace(s[l]), ret.emplace_back(s[l]);
char t[3] = {'J', 'O', 'I'};
int cnt = 0;
while(!q.empty()){
string x = q.front(); q.pop();
string tt = ""; tt.resize(n);
for(string &u : ret){
for(int i = 0; i < n; ++i){
if(x[i] == u[i]) tt[i] = x[i];
else{
int a, b;
for(int j = 0; j < 3; ++j) if(t[j] == x[i]) a = j;
for(int j = 0; j < 3; ++j) if(t[j] == u[i]) b = j;
if(a && b) tt[i] = t[0];
else if(max(a, b) > 1) tt[i] = t[1];
else tt[i] = t[2];
}
}
if(mp[tt] != 1) mp[tt] = 1, q.emplace(tt), ++cnt, ret.emplace_back(tt);//, cout << ":\n" << x << "\n" << u << "\n" << tt << "\n\n";
}
//~ cout << x << "\n";
}
return ret;
}
int base = 1;
ll mod = 998244353;
struct seg{
vector<ll> t, p, tmp, powp;
ll mul;
ll r[256];
void build(int i, int s, int e){
for(int j = s; j <= e; ++j) tmp[i] = (tmp[i]+powp[j])%mod;
int mid = (s+e)>>1;
if(s != e) build(i<<1, s, mid), build(i<<1|1, mid+1, e);
}
void init(int n, ll m, string &s){
r['J'] = 328336787, r['O'] = 760308421, r['I'] = 988411051;
while(base < n) base <<= 1;
t.resize(base<<1, 0), tmp.resize(base<<1, 0), powp.resize(base+1), p.resize(base<<1, 0);
mul = m, powp[0] = 1;
for(int i = 1; i <= base; ++i) powp[i] = powp[i-1]*mul%mod;
build(1, 1, base);
for(int i = 0; i < int(s.length()); ++i) t[i+base] = r[s[i]]*powp[i+1]%mod;
for(int i = base-1; i; --i) t[i] = (t[i<<1]+t[i<<1|1])%mod;
}
void add(int i, ll pr){ t[i] = tmp[i]*pr%mod, p[i] = pr; }
void push(int i){ if(p[i]) add(i<<1, p[i]), add(i<<1|1, p[i]), p[i] = 0; }
void update(int i, int s, int e, int x, int y, ll pr){
if(x <= s && e <= y) return void(add(i, pr));
int mid = (s+e)>>1; push(i);
if(x <= mid) update(i<<1, s, mid, x, y, pr);
if(mid < y) update(i<<1|1, mid+1, e, x, y, pr);
t[i] = (t[i<<1]+t[i<<1|1])%mod;
}
};
void answer(){
int n, q; scanf("%d", &n);
string s[3] = {"", "", ""}, t="";
char c;
for(int l = 0; l < 3; ++l){
c = getchar_unlocked();
for(int i = 0; i < n; ++i) c = getchar_unlocked(), s[l] += c;
}
scanf("%d\n", &q);
for(int i = 0; i < n; ++i) c = getchar_unlocked(), t += c;
vector<string> st = get_strings(s[0], s[1], s[2]);
vector<ll> powp(n+1); powp[0] = 1;
for(int i = 1; i <= n; ++i) powp[i] = powp[i-1]*97ll%mod;
vector<ll> powp1(n+1); powp1[0] = 1;
for(int i = 1; i <= n; ++i) powp1[i] = powp1[i-1]*1000000007ll%mod;
vector<ll> powp2(n+1); powp2[0] = 1;
for(int i = 1; i <= n; ++i) powp2[i] = powp2[i-1]*2137ll%mod;
ll r[256]; r['J'] = 328336787, r['O'] = 760308421, r['I'] = 988411051;
unordered_map<ll, bool> mp9, mp10, mp11;
for(string &u : st){
ll hash = 0;
for(int i = 0; i < n; ++i) hash = (hash+r[u[i]]*powp[i+1])%mod;
mp9[hash] = 1;
hash = 0;
for(int i = 0; i < n; ++i) hash = (hash+r[u[i]]*powp1[i+1])%mod;
mp10[hash] = 1;
hash = 0;
for(int i = 0; i < n; ++i) hash = (hash+r[u[i]]*powp2[i+1])%mod;
mp11[hash] = 1;
//~ printf("%lld\n", hash);
}
seg seg, seg2, seg3; seg.init(n+1, 97, t); seg2.init(n+1, 1000000007, t), seg3.init(n+1, 2137, t);
printf(mp9[seg.t[1]] && mp10[seg2.t[1]] && mp11[seg3.t[1]] ? "Yes\n" : "No\n");
//~ printf("%lld\n", seg.t[1]);
for(++q; --q; ){
int a, b;
scanf("%d%d %c", &a, &b, &c);
seg.update(1, 1, base, a, b, r[c]);
seg2.update(1, 1, base, a, b, r[c]);
seg3.update(1, 1, base, a, b, r[c]);
printf(mp9[seg.t[1]] && mp10[seg2.t[1]] && mp11[seg3.t[1]] ? "Yes\n" : "No\n");
//~ printf("%lld\n", seg3.t[1]);
}
}
int main(){
int T = 1;
//~ ios_base::sync_with_stdio(0); cin.tie(0);
for(++T; --T; ) answer();
return 0;
}
Compilation message
Main.cpp: In member function 'void seg::init(int, ll, std::string&)':
Main.cpp:60:64: warning: array subscript has type 'char' [-Wchar-subscripts]
60 | for(int i = 0; i < int(s.length()); ++i) t[i+base] = r[s[i]]*powp[i+1]%mod;
| ^
Main.cpp: In function 'void answer()':
Main.cpp:97:51: warning: array subscript has type 'char' [-Wchar-subscripts]
97 | for(int i = 0; i < n; ++i) hash = (hash+r[u[i]]*powp[i+1])%mod;
| ^
Main.cpp:100:51: warning: array subscript has type 'char' [-Wchar-subscripts]
100 | for(int i = 0; i < n; ++i) hash = (hash+r[u[i]]*powp1[i+1])%mod;
| ^
Main.cpp:103:51: warning: array subscript has type 'char' [-Wchar-subscripts]
103 | for(int i = 0; i < n; ++i) hash = (hash+r[u[i]]*powp2[i+1])%mod;
| ^
Main.cpp:114:36: warning: array subscript has type 'char' [-Wchar-subscripts]
114 | seg.update(1, 1, base, a, b, r[c]);
| ^
Main.cpp:115:37: warning: array subscript has type 'char' [-Wchar-subscripts]
115 | seg2.update(1, 1, base, a, b, r[c]);
| ^
Main.cpp:116:37: warning: array subscript has type 'char' [-Wchar-subscripts]
116 | seg3.update(1, 1, base, a, b, r[c]);
| ^
Main.cpp:75:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | int n, q; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | scanf("%d\n", &q);
| ~~~~~^~~~~~~~~~~~
Main.cpp:113:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | scanf("%d%d %c", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
6856 KB |
Output is correct |
2 |
Correct |
163 ms |
7312 KB |
Output is correct |
3 |
Correct |
179 ms |
3420 KB |
Output is correct |
4 |
Correct |
149 ms |
7400 KB |
Output is correct |
5 |
Correct |
154 ms |
7300 KB |
Output is correct |
6 |
Correct |
143 ms |
7044 KB |
Output is correct |
7 |
Correct |
137 ms |
7380 KB |
Output is correct |
8 |
Correct |
138 ms |
7424 KB |
Output is correct |
9 |
Correct |
184 ms |
7364 KB |
Output is correct |
10 |
Correct |
157 ms |
10340 KB |
Output is correct |
11 |
Correct |
151 ms |
7732 KB |
Output is correct |
12 |
Correct |
199 ms |
10544 KB |
Output is correct |
13 |
Correct |
174 ms |
7736 KB |
Output is correct |
14 |
Correct |
139 ms |
10432 KB |
Output is correct |
15 |
Correct |
142 ms |
7620 KB |
Output is correct |
16 |
Correct |
156 ms |
10788 KB |
Output is correct |
17 |
Correct |
151 ms |
7576 KB |
Output is correct |
18 |
Correct |
158 ms |
2308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
6856 KB |
Output is correct |
2 |
Correct |
163 ms |
7312 KB |
Output is correct |
3 |
Correct |
179 ms |
3420 KB |
Output is correct |
4 |
Correct |
149 ms |
7400 KB |
Output is correct |
5 |
Correct |
154 ms |
7300 KB |
Output is correct |
6 |
Correct |
143 ms |
7044 KB |
Output is correct |
7 |
Correct |
137 ms |
7380 KB |
Output is correct |
8 |
Correct |
138 ms |
7424 KB |
Output is correct |
9 |
Correct |
184 ms |
7364 KB |
Output is correct |
10 |
Correct |
157 ms |
10340 KB |
Output is correct |
11 |
Correct |
151 ms |
7732 KB |
Output is correct |
12 |
Correct |
199 ms |
10544 KB |
Output is correct |
13 |
Correct |
174 ms |
7736 KB |
Output is correct |
14 |
Correct |
139 ms |
10432 KB |
Output is correct |
15 |
Correct |
142 ms |
7620 KB |
Output is correct |
16 |
Correct |
156 ms |
10788 KB |
Output is correct |
17 |
Correct |
151 ms |
7576 KB |
Output is correct |
18 |
Correct |
158 ms |
2308 KB |
Output is correct |
19 |
Correct |
854 ms |
56472 KB |
Output is correct |
20 |
Correct |
797 ms |
56644 KB |
Output is correct |
21 |
Correct |
551 ms |
59168 KB |
Output is correct |
22 |
Correct |
639 ms |
55200 KB |
Output is correct |
23 |
Correct |
282 ms |
13512 KB |
Output is correct |
24 |
Correct |
276 ms |
13548 KB |
Output is correct |
25 |
Correct |
574 ms |
59540 KB |
Output is correct |
26 |
Correct |
563 ms |
56596 KB |
Output is correct |
27 |
Correct |
652 ms |
59740 KB |
Output is correct |
28 |
Correct |
750 ms |
56612 KB |
Output is correct |
29 |
Correct |
676 ms |
59796 KB |
Output is correct |
30 |
Correct |
294 ms |
13436 KB |
Output is correct |
31 |
Correct |
684 ms |
59564 KB |
Output is correct |
32 |
Correct |
594 ms |
56032 KB |
Output is correct |
33 |
Correct |
268 ms |
13524 KB |
Output is correct |
34 |
Correct |
670 ms |
56544 KB |
Output is correct |
35 |
Correct |
551 ms |
55032 KB |
Output is correct |
36 |
Correct |
258 ms |
13416 KB |
Output is correct |
37 |
Correct |
257 ms |
13508 KB |
Output is correct |
38 |
Correct |
703 ms |
55576 KB |
Output is correct |
39 |
Correct |
311 ms |
54820 KB |
Output is correct |
40 |
Correct |
597 ms |
54688 KB |
Output is correct |
41 |
Correct |
923 ms |
54080 KB |
Output is correct |
42 |
Correct |
280 ms |
53476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
6856 KB |
Output is correct |
2 |
Correct |
163 ms |
7312 KB |
Output is correct |
3 |
Correct |
179 ms |
3420 KB |
Output is correct |
4 |
Correct |
149 ms |
7400 KB |
Output is correct |
5 |
Correct |
154 ms |
7300 KB |
Output is correct |
6 |
Correct |
143 ms |
7044 KB |
Output is correct |
7 |
Correct |
137 ms |
7380 KB |
Output is correct |
8 |
Correct |
138 ms |
7424 KB |
Output is correct |
9 |
Correct |
184 ms |
7364 KB |
Output is correct |
10 |
Correct |
157 ms |
10340 KB |
Output is correct |
11 |
Correct |
151 ms |
7732 KB |
Output is correct |
12 |
Correct |
199 ms |
10544 KB |
Output is correct |
13 |
Correct |
174 ms |
7736 KB |
Output is correct |
14 |
Correct |
139 ms |
10432 KB |
Output is correct |
15 |
Correct |
142 ms |
7620 KB |
Output is correct |
16 |
Correct |
156 ms |
10788 KB |
Output is correct |
17 |
Correct |
151 ms |
7576 KB |
Output is correct |
18 |
Correct |
158 ms |
2308 KB |
Output is correct |
19 |
Correct |
189 ms |
7144 KB |
Output is correct |
20 |
Correct |
171 ms |
3352 KB |
Output is correct |
21 |
Correct |
174 ms |
10448 KB |
Output is correct |
22 |
Correct |
132 ms |
6948 KB |
Output is correct |
23 |
Correct |
163 ms |
10424 KB |
Output is correct |
24 |
Correct |
138 ms |
7224 KB |
Output is correct |
25 |
Correct |
147 ms |
10380 KB |
Output is correct |
26 |
Correct |
145 ms |
7144 KB |
Output is correct |
27 |
Correct |
158 ms |
10560 KB |
Output is correct |
28 |
Correct |
161 ms |
7340 KB |
Output is correct |
29 |
Correct |
142 ms |
7348 KB |
Output is correct |
30 |
Correct |
122 ms |
6884 KB |
Output is correct |
31 |
Correct |
147 ms |
10312 KB |
Output is correct |
32 |
Correct |
152 ms |
10572 KB |
Output is correct |
33 |
Correct |
149 ms |
7620 KB |
Output is correct |
34 |
Correct |
176 ms |
7108 KB |
Output is correct |
35 |
Correct |
137 ms |
10436 KB |
Output is correct |
36 |
Correct |
149 ms |
7700 KB |
Output is correct |
37 |
Correct |
168 ms |
10428 KB |
Output is correct |
38 |
Correct |
133 ms |
7796 KB |
Output is correct |
39 |
Correct |
158 ms |
10436 KB |
Output is correct |
40 |
Correct |
131 ms |
7808 KB |
Output is correct |
41 |
Correct |
133 ms |
10432 KB |
Output is correct |
42 |
Correct |
188 ms |
7616 KB |
Output is correct |
43 |
Correct |
140 ms |
7364 KB |
Output is correct |
44 |
Correct |
140 ms |
7580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
144 ms |
6856 KB |
Output is correct |
2 |
Correct |
163 ms |
7312 KB |
Output is correct |
3 |
Correct |
179 ms |
3420 KB |
Output is correct |
4 |
Correct |
149 ms |
7400 KB |
Output is correct |
5 |
Correct |
154 ms |
7300 KB |
Output is correct |
6 |
Correct |
143 ms |
7044 KB |
Output is correct |
7 |
Correct |
137 ms |
7380 KB |
Output is correct |
8 |
Correct |
138 ms |
7424 KB |
Output is correct |
9 |
Correct |
184 ms |
7364 KB |
Output is correct |
10 |
Correct |
157 ms |
10340 KB |
Output is correct |
11 |
Correct |
151 ms |
7732 KB |
Output is correct |
12 |
Correct |
199 ms |
10544 KB |
Output is correct |
13 |
Correct |
174 ms |
7736 KB |
Output is correct |
14 |
Correct |
139 ms |
10432 KB |
Output is correct |
15 |
Correct |
142 ms |
7620 KB |
Output is correct |
16 |
Correct |
156 ms |
10788 KB |
Output is correct |
17 |
Correct |
151 ms |
7576 KB |
Output is correct |
18 |
Correct |
158 ms |
2308 KB |
Output is correct |
19 |
Correct |
854 ms |
56472 KB |
Output is correct |
20 |
Correct |
797 ms |
56644 KB |
Output is correct |
21 |
Correct |
551 ms |
59168 KB |
Output is correct |
22 |
Correct |
639 ms |
55200 KB |
Output is correct |
23 |
Correct |
282 ms |
13512 KB |
Output is correct |
24 |
Correct |
276 ms |
13548 KB |
Output is correct |
25 |
Correct |
574 ms |
59540 KB |
Output is correct |
26 |
Correct |
563 ms |
56596 KB |
Output is correct |
27 |
Correct |
652 ms |
59740 KB |
Output is correct |
28 |
Correct |
750 ms |
56612 KB |
Output is correct |
29 |
Correct |
676 ms |
59796 KB |
Output is correct |
30 |
Correct |
294 ms |
13436 KB |
Output is correct |
31 |
Correct |
684 ms |
59564 KB |
Output is correct |
32 |
Correct |
594 ms |
56032 KB |
Output is correct |
33 |
Correct |
268 ms |
13524 KB |
Output is correct |
34 |
Correct |
670 ms |
56544 KB |
Output is correct |
35 |
Correct |
551 ms |
55032 KB |
Output is correct |
36 |
Correct |
258 ms |
13416 KB |
Output is correct |
37 |
Correct |
257 ms |
13508 KB |
Output is correct |
38 |
Correct |
703 ms |
55576 KB |
Output is correct |
39 |
Correct |
311 ms |
54820 KB |
Output is correct |
40 |
Correct |
597 ms |
54688 KB |
Output is correct |
41 |
Correct |
923 ms |
54080 KB |
Output is correct |
42 |
Correct |
280 ms |
53476 KB |
Output is correct |
43 |
Correct |
189 ms |
7144 KB |
Output is correct |
44 |
Correct |
171 ms |
3352 KB |
Output is correct |
45 |
Correct |
174 ms |
10448 KB |
Output is correct |
46 |
Correct |
132 ms |
6948 KB |
Output is correct |
47 |
Correct |
163 ms |
10424 KB |
Output is correct |
48 |
Correct |
138 ms |
7224 KB |
Output is correct |
49 |
Correct |
147 ms |
10380 KB |
Output is correct |
50 |
Correct |
145 ms |
7144 KB |
Output is correct |
51 |
Correct |
158 ms |
10560 KB |
Output is correct |
52 |
Correct |
161 ms |
7340 KB |
Output is correct |
53 |
Correct |
142 ms |
7348 KB |
Output is correct |
54 |
Correct |
122 ms |
6884 KB |
Output is correct |
55 |
Correct |
147 ms |
10312 KB |
Output is correct |
56 |
Correct |
152 ms |
10572 KB |
Output is correct |
57 |
Correct |
149 ms |
7620 KB |
Output is correct |
58 |
Correct |
176 ms |
7108 KB |
Output is correct |
59 |
Correct |
137 ms |
10436 KB |
Output is correct |
60 |
Correct |
149 ms |
7700 KB |
Output is correct |
61 |
Correct |
168 ms |
10428 KB |
Output is correct |
62 |
Correct |
133 ms |
7796 KB |
Output is correct |
63 |
Correct |
158 ms |
10436 KB |
Output is correct |
64 |
Correct |
131 ms |
7808 KB |
Output is correct |
65 |
Correct |
133 ms |
10432 KB |
Output is correct |
66 |
Correct |
188 ms |
7616 KB |
Output is correct |
67 |
Correct |
140 ms |
7364 KB |
Output is correct |
68 |
Correct |
140 ms |
7580 KB |
Output is correct |
69 |
Correct |
809 ms |
59104 KB |
Output is correct |
70 |
Correct |
836 ms |
61732 KB |
Output is correct |
71 |
Correct |
254 ms |
15836 KB |
Output is correct |
72 |
Correct |
281 ms |
15908 KB |
Output is correct |
73 |
Correct |
263 ms |
15932 KB |
Output is correct |
74 |
Correct |
457 ms |
61876 KB |
Output is correct |
75 |
Correct |
262 ms |
15700 KB |
Output is correct |
76 |
Correct |
573 ms |
62948 KB |
Output is correct |
77 |
Correct |
511 ms |
58556 KB |
Output is correct |
78 |
Correct |
249 ms |
15812 KB |
Output is correct |
79 |
Correct |
249 ms |
15860 KB |
Output is correct |
80 |
Correct |
579 ms |
58952 KB |
Output is correct |
81 |
Correct |
245 ms |
15632 KB |
Output is correct |
82 |
Correct |
690 ms |
64224 KB |
Output is correct |
83 |
Correct |
667 ms |
60764 KB |
Output is correct |
84 |
Correct |
346 ms |
15816 KB |
Output is correct |
85 |
Correct |
246 ms |
15904 KB |
Output is correct |
86 |
Correct |
652 ms |
58976 KB |
Output is correct |
87 |
Correct |
703 ms |
61468 KB |
Output is correct |
88 |
Correct |
254 ms |
13120 KB |
Output is correct |
89 |
Correct |
639 ms |
60028 KB |
Output is correct |
90 |
Correct |
623 ms |
61492 KB |
Output is correct |
91 |
Correct |
266 ms |
12996 KB |
Output is correct |
92 |
Correct |
607 ms |
59216 KB |
Output is correct |
93 |
Correct |
260 ms |
15972 KB |
Output is correct |
94 |
Correct |
259 ms |
16064 KB |
Output is correct |
95 |
Correct |
257 ms |
16008 KB |
Output is correct |
96 |
Correct |
667 ms |
58892 KB |
Output is correct |
97 |
Correct |
369 ms |
60364 KB |
Output is correct |
98 |
Correct |
614 ms |
58696 KB |
Output is correct |
99 |
Correct |
944 ms |
57872 KB |
Output is correct |
100 |
Correct |
407 ms |
57232 KB |
Output is correct |