# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
542265 |
2022-03-26T03:48:53 Z |
radal |
Crossing (JOI21_crossing) |
C++17 |
|
625 ms |
17708 KB |
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr ll N = 2e5+20,mod = 1e9+9,inf = 1e9+10,mod2 = 1e9+7,mod3 = 1e9+21;
inline int mkay(int a,int b,int mod){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k,int m){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%m;
a = 1ll*a*a%m;
k >>= 1;
}
return z;
}
int pw[N][3],n;
set <pair<int,pll> >st;
int lz[N*4],inv[3];
pair<int,pll> seg[N*4];
inline string Xor(string& s,string& t){
string ans = "";
rep(i,0,n){
if (s[i] == t[i]) ans += s[i];
else{
if (s[i] != 'J' && t[i] !='J') ans += 'J';
else if (s[i] != 'O' && t[i] != 'O') ans += 'O';
else ans += 'I';
}
}
return ans;
}
inline int hash_func(string& s,int f,int m){
int ans = 0;
rep(i,0,n){
if (s[i] == 'J') continue;
if (s[i] == 'O')
ans = mkay(ans,pw[i][f],m);
else
ans = mkay(ans,pw[i][f]*2%m,m);
}
return ans;
}
string t;
void build(int l = 0,int r = n,int v = 1){
lz[v] = -1;
if (r-l == 1){
if(t[l] == 'J'){
seg[v] = {0,{0,0}};
return;
}
if (t[l] == 'O'){
seg[v] = {pw[l][0],{pw[l][1],pw[l][2]}};
return;
}
seg[v] = {mkay(pw[l][0],pw[l][0],mod),{mkay(pw[l][1],pw[l][1],mod2),mkay(pw[l][2],pw[l][2],mod3)}};
return;
}
int m = (l+r) >> 1,u = (v << 1);
build(l,m,u);
build(m,r,u|1);
seg[v].X = mkay(seg[u].X,seg[u|1].X,mod);
seg[v].Y.X = mkay(seg[u].Y.X,seg[u|1].Y.X,mod2);
seg[v].Y.Y = mkay(seg[u].Y.Y,seg[u|1].Y.Y,mod3);
}
inline void pass(int l,int r,int v){
if (lz[v] == -1) return;
int u = (v << 1);
lz[u] = lz[v];
lz[u|1] = lz[v];
if (lz[v] == 0){
seg[u] = {0,{0,0}};
seg[u|1] = {0,{0,0}};
lz[v] = -1;
return;
}
int m = (l+r) >> 1;
int L[3], R[3];
R[0] = mkay(pw[r][0],-pw[m][0],mod);
R[1] = mkay(pw[r][1],-pw[m][1],mod2);
R[2] = mkay(pw[r][2],-pw[m][2],mod3);
L[0] = mkay(pw[m][0],-pw[l][0],mod);
L[1] = mkay(pw[m][1],-pw[l][1],mod2);
L[2] = mkay(pw[m][2],-pw[l][2],mod3);
if (lz[v] == 2){
seg[u] = {L[0],{L[1],L[2]}};
seg[u|1] = {R[0],{R[1],R[2]}};
lz[v] = -1;
return;
}
lz[v] = -1;
L[0] = 1ll*L[0]*inv[0]%mod;
R[0] = 1ll*R[0]*inv[0]%mod;
L[1] = 1ll*L[1]*inv[1]%mod2;
R[1] = 1ll*R[1]*inv[1]%mod2;
L[2] = 1ll*L[2]*inv[2]%mod3;
R[2] = 1ll*R[2]*inv[2]%mod3;
seg[u] = {L[0],{L[1],L[2]}};
seg[u|1] = {R[0],{R[1],R[2]}};
}
void upd(int l,int r,int s,int e,int x,int v = 1){
if (s >= r || l >= e) return;
if (s <= l && r <= e){
lz[v] = x;
if (!x){
seg[v] = {0,{0,0}};
return;
}
if (x == 2){
seg[v].X = mkay(pw[r][0],-pw[l][0],mod);
seg[v].Y.X = mkay(pw[r][1],-pw[l][1],mod2);
seg[v].Y.Y = mkay(pw[r][2],-pw[l][2],mod3);
return;
}
seg[v].X = 1ll*mkay(pw[r][0],-pw[l][0],mod)*inv[0]%mod;
seg[v].Y.X = 1ll*mkay(pw[r][1],-pw[l][1],mod2)*inv[1]%mod2;
seg[v].Y.Y = 1ll*mkay(pw[r][2],-pw[l][2],mod3)*inv[2]%mod3;
return;
}
pass(l,r,v);
int u = (v << 1),m = (l+r) >> 1;
upd(l,m,s,e,x,u);
upd(m,r,s,e,x,u|1);
seg[v].X = mkay(seg[u].X,seg[u|1].X,mod);
seg[v].Y.X = mkay(seg[u].Y.X,seg[u|1].Y.X,mod2);
seg[v].Y.Y = mkay(seg[u].Y.Y,seg[u|1].Y.Y,mod3);
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
int q;
cin >> n;
set<string> st2;
inv[0] = poww(2,mod-2,mod);
inv[1] = poww(2,mod2-2,mod2);
inv[2] = poww(2,mod3-2,mod3);
rep(i,0,3){
string s;
cin >> s;
st2.insert(s);
}
rep(i,0,1000){
bool f = 0;
for (string s : st2){
for (string v : st2){
string w = Xor(s,v);
if (st2.find(w) != st2.end()) continue;
f = 1;
st2.insert(w);
}
}
if (!f) break;
}
pw[0][0] = pw[0][1] = pw[0][2] = 1;
rep(i,1,n+3){
pw[i][0] = 1ll*pw[i-1][0]*3%mod;
pw[i][1] = 1ll*pw[i-1][1]*3%mod2;
pw[i][2] = 1ll*pw[i-1][2]*3%mod3;
}
for (string s : st2){
st.insert({hash_func(s,0,mod),{hash_func(s,1,mod2),hash_func(s,2,mod3)}});
}
cin >> q;
cin >> t;
build();
if (st.find(seg[1]) != st.end()){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
while (q--){
int l,r;
char c;
cin >> l >> r >> c;
l--;
if (c == 'J') upd(0,n,l,r,0);
if (c == 'O') upd(0,n,l,r,1);
if (c == 'I') upd(0,n,l,r,2);
cout << ((st.find(seg[1]) != st.end()) ? "Yes" : "No") << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2396 KB |
Output is correct |
2 |
Correct |
118 ms |
2400 KB |
Output is correct |
3 |
Correct |
86 ms |
2264 KB |
Output is correct |
4 |
Correct |
82 ms |
2300 KB |
Output is correct |
5 |
Correct |
86 ms |
2356 KB |
Output is correct |
6 |
Correct |
100 ms |
2244 KB |
Output is correct |
7 |
Correct |
91 ms |
2364 KB |
Output is correct |
8 |
Correct |
89 ms |
2380 KB |
Output is correct |
9 |
Correct |
93 ms |
2380 KB |
Output is correct |
10 |
Correct |
109 ms |
2420 KB |
Output is correct |
11 |
Correct |
101 ms |
2460 KB |
Output is correct |
12 |
Correct |
88 ms |
2408 KB |
Output is correct |
13 |
Correct |
93 ms |
2452 KB |
Output is correct |
14 |
Correct |
99 ms |
2428 KB |
Output is correct |
15 |
Correct |
97 ms |
2380 KB |
Output is correct |
16 |
Correct |
99 ms |
2400 KB |
Output is correct |
17 |
Correct |
99 ms |
2464 KB |
Output is correct |
18 |
Correct |
94 ms |
2344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2396 KB |
Output is correct |
2 |
Correct |
118 ms |
2400 KB |
Output is correct |
3 |
Correct |
86 ms |
2264 KB |
Output is correct |
4 |
Correct |
82 ms |
2300 KB |
Output is correct |
5 |
Correct |
86 ms |
2356 KB |
Output is correct |
6 |
Correct |
100 ms |
2244 KB |
Output is correct |
7 |
Correct |
91 ms |
2364 KB |
Output is correct |
8 |
Correct |
89 ms |
2380 KB |
Output is correct |
9 |
Correct |
93 ms |
2380 KB |
Output is correct |
10 |
Correct |
109 ms |
2420 KB |
Output is correct |
11 |
Correct |
101 ms |
2460 KB |
Output is correct |
12 |
Correct |
88 ms |
2408 KB |
Output is correct |
13 |
Correct |
93 ms |
2452 KB |
Output is correct |
14 |
Correct |
99 ms |
2428 KB |
Output is correct |
15 |
Correct |
97 ms |
2380 KB |
Output is correct |
16 |
Correct |
99 ms |
2400 KB |
Output is correct |
17 |
Correct |
99 ms |
2464 KB |
Output is correct |
18 |
Correct |
94 ms |
2344 KB |
Output is correct |
19 |
Correct |
361 ms |
15948 KB |
Output is correct |
20 |
Correct |
373 ms |
15920 KB |
Output is correct |
21 |
Correct |
224 ms |
15620 KB |
Output is correct |
22 |
Correct |
249 ms |
15220 KB |
Output is correct |
23 |
Correct |
157 ms |
4040 KB |
Output is correct |
24 |
Correct |
165 ms |
4080 KB |
Output is correct |
25 |
Correct |
232 ms |
15944 KB |
Output is correct |
26 |
Correct |
238 ms |
15956 KB |
Output is correct |
27 |
Correct |
307 ms |
15952 KB |
Output is correct |
28 |
Correct |
292 ms |
15956 KB |
Output is correct |
29 |
Correct |
261 ms |
15940 KB |
Output is correct |
30 |
Correct |
168 ms |
3972 KB |
Output is correct |
31 |
Correct |
294 ms |
15956 KB |
Output is correct |
32 |
Correct |
266 ms |
15732 KB |
Output is correct |
33 |
Correct |
164 ms |
3928 KB |
Output is correct |
34 |
Correct |
283 ms |
15892 KB |
Output is correct |
35 |
Correct |
231 ms |
14688 KB |
Output is correct |
36 |
Correct |
148 ms |
3904 KB |
Output is correct |
37 |
Correct |
171 ms |
3956 KB |
Output is correct |
38 |
Correct |
284 ms |
15716 KB |
Output is correct |
39 |
Correct |
169 ms |
15968 KB |
Output is correct |
40 |
Correct |
241 ms |
10324 KB |
Output is correct |
41 |
Correct |
304 ms |
16088 KB |
Output is correct |
42 |
Correct |
58 ms |
15348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2396 KB |
Output is correct |
2 |
Correct |
118 ms |
2400 KB |
Output is correct |
3 |
Correct |
86 ms |
2264 KB |
Output is correct |
4 |
Correct |
82 ms |
2300 KB |
Output is correct |
5 |
Correct |
86 ms |
2356 KB |
Output is correct |
6 |
Correct |
100 ms |
2244 KB |
Output is correct |
7 |
Correct |
91 ms |
2364 KB |
Output is correct |
8 |
Correct |
89 ms |
2380 KB |
Output is correct |
9 |
Correct |
93 ms |
2380 KB |
Output is correct |
10 |
Correct |
109 ms |
2420 KB |
Output is correct |
11 |
Correct |
101 ms |
2460 KB |
Output is correct |
12 |
Correct |
88 ms |
2408 KB |
Output is correct |
13 |
Correct |
93 ms |
2452 KB |
Output is correct |
14 |
Correct |
99 ms |
2428 KB |
Output is correct |
15 |
Correct |
97 ms |
2380 KB |
Output is correct |
16 |
Correct |
99 ms |
2400 KB |
Output is correct |
17 |
Correct |
99 ms |
2464 KB |
Output is correct |
18 |
Correct |
94 ms |
2344 KB |
Output is correct |
19 |
Correct |
102 ms |
2364 KB |
Output is correct |
20 |
Correct |
117 ms |
2248 KB |
Output is correct |
21 |
Correct |
89 ms |
2380 KB |
Output is correct |
22 |
Correct |
78 ms |
2252 KB |
Output is correct |
23 |
Correct |
103 ms |
2432 KB |
Output is correct |
24 |
Correct |
92 ms |
2332 KB |
Output is correct |
25 |
Correct |
91 ms |
2400 KB |
Output is correct |
26 |
Correct |
85 ms |
2252 KB |
Output is correct |
27 |
Correct |
112 ms |
2368 KB |
Output is correct |
28 |
Correct |
81 ms |
2252 KB |
Output is correct |
29 |
Correct |
92 ms |
2356 KB |
Output is correct |
30 |
Correct |
76 ms |
2372 KB |
Output is correct |
31 |
Correct |
95 ms |
2432 KB |
Output is correct |
32 |
Correct |
94 ms |
2336 KB |
Output is correct |
33 |
Correct |
107 ms |
2400 KB |
Output is correct |
34 |
Correct |
85 ms |
2252 KB |
Output is correct |
35 |
Correct |
93 ms |
2460 KB |
Output is correct |
36 |
Correct |
94 ms |
2380 KB |
Output is correct |
37 |
Correct |
96 ms |
2380 KB |
Output is correct |
38 |
Correct |
97 ms |
2452 KB |
Output is correct |
39 |
Correct |
93 ms |
2376 KB |
Output is correct |
40 |
Correct |
96 ms |
2392 KB |
Output is correct |
41 |
Correct |
96 ms |
2460 KB |
Output is correct |
42 |
Correct |
101 ms |
2452 KB |
Output is correct |
43 |
Correct |
90 ms |
2380 KB |
Output is correct |
44 |
Correct |
96 ms |
2476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
2396 KB |
Output is correct |
2 |
Correct |
118 ms |
2400 KB |
Output is correct |
3 |
Correct |
86 ms |
2264 KB |
Output is correct |
4 |
Correct |
82 ms |
2300 KB |
Output is correct |
5 |
Correct |
86 ms |
2356 KB |
Output is correct |
6 |
Correct |
100 ms |
2244 KB |
Output is correct |
7 |
Correct |
91 ms |
2364 KB |
Output is correct |
8 |
Correct |
89 ms |
2380 KB |
Output is correct |
9 |
Correct |
93 ms |
2380 KB |
Output is correct |
10 |
Correct |
109 ms |
2420 KB |
Output is correct |
11 |
Correct |
101 ms |
2460 KB |
Output is correct |
12 |
Correct |
88 ms |
2408 KB |
Output is correct |
13 |
Correct |
93 ms |
2452 KB |
Output is correct |
14 |
Correct |
99 ms |
2428 KB |
Output is correct |
15 |
Correct |
97 ms |
2380 KB |
Output is correct |
16 |
Correct |
99 ms |
2400 KB |
Output is correct |
17 |
Correct |
99 ms |
2464 KB |
Output is correct |
18 |
Correct |
94 ms |
2344 KB |
Output is correct |
19 |
Correct |
361 ms |
15948 KB |
Output is correct |
20 |
Correct |
373 ms |
15920 KB |
Output is correct |
21 |
Correct |
224 ms |
15620 KB |
Output is correct |
22 |
Correct |
249 ms |
15220 KB |
Output is correct |
23 |
Correct |
157 ms |
4040 KB |
Output is correct |
24 |
Correct |
165 ms |
4080 KB |
Output is correct |
25 |
Correct |
232 ms |
15944 KB |
Output is correct |
26 |
Correct |
238 ms |
15956 KB |
Output is correct |
27 |
Correct |
307 ms |
15952 KB |
Output is correct |
28 |
Correct |
292 ms |
15956 KB |
Output is correct |
29 |
Correct |
261 ms |
15940 KB |
Output is correct |
30 |
Correct |
168 ms |
3972 KB |
Output is correct |
31 |
Correct |
294 ms |
15956 KB |
Output is correct |
32 |
Correct |
266 ms |
15732 KB |
Output is correct |
33 |
Correct |
164 ms |
3928 KB |
Output is correct |
34 |
Correct |
283 ms |
15892 KB |
Output is correct |
35 |
Correct |
231 ms |
14688 KB |
Output is correct |
36 |
Correct |
148 ms |
3904 KB |
Output is correct |
37 |
Correct |
171 ms |
3956 KB |
Output is correct |
38 |
Correct |
284 ms |
15716 KB |
Output is correct |
39 |
Correct |
169 ms |
15968 KB |
Output is correct |
40 |
Correct |
241 ms |
10324 KB |
Output is correct |
41 |
Correct |
304 ms |
16088 KB |
Output is correct |
42 |
Correct |
58 ms |
15348 KB |
Output is correct |
43 |
Correct |
102 ms |
2364 KB |
Output is correct |
44 |
Correct |
117 ms |
2248 KB |
Output is correct |
45 |
Correct |
89 ms |
2380 KB |
Output is correct |
46 |
Correct |
78 ms |
2252 KB |
Output is correct |
47 |
Correct |
103 ms |
2432 KB |
Output is correct |
48 |
Correct |
92 ms |
2332 KB |
Output is correct |
49 |
Correct |
91 ms |
2400 KB |
Output is correct |
50 |
Correct |
85 ms |
2252 KB |
Output is correct |
51 |
Correct |
112 ms |
2368 KB |
Output is correct |
52 |
Correct |
81 ms |
2252 KB |
Output is correct |
53 |
Correct |
92 ms |
2356 KB |
Output is correct |
54 |
Correct |
76 ms |
2372 KB |
Output is correct |
55 |
Correct |
95 ms |
2432 KB |
Output is correct |
56 |
Correct |
94 ms |
2336 KB |
Output is correct |
57 |
Correct |
107 ms |
2400 KB |
Output is correct |
58 |
Correct |
85 ms |
2252 KB |
Output is correct |
59 |
Correct |
93 ms |
2460 KB |
Output is correct |
60 |
Correct |
94 ms |
2380 KB |
Output is correct |
61 |
Correct |
96 ms |
2380 KB |
Output is correct |
62 |
Correct |
97 ms |
2452 KB |
Output is correct |
63 |
Correct |
93 ms |
2376 KB |
Output is correct |
64 |
Correct |
96 ms |
2392 KB |
Output is correct |
65 |
Correct |
96 ms |
2460 KB |
Output is correct |
66 |
Correct |
101 ms |
2452 KB |
Output is correct |
67 |
Correct |
90 ms |
2380 KB |
Output is correct |
68 |
Correct |
96 ms |
2476 KB |
Output is correct |
69 |
Correct |
625 ms |
16272 KB |
Output is correct |
70 |
Correct |
614 ms |
17548 KB |
Output is correct |
71 |
Correct |
155 ms |
3940 KB |
Output is correct |
72 |
Correct |
160 ms |
4120 KB |
Output is correct |
73 |
Correct |
159 ms |
3988 KB |
Output is correct |
74 |
Correct |
249 ms |
15568 KB |
Output is correct |
75 |
Correct |
174 ms |
3884 KB |
Output is correct |
76 |
Correct |
268 ms |
16452 KB |
Output is correct |
77 |
Correct |
311 ms |
15636 KB |
Output is correct |
78 |
Correct |
157 ms |
3984 KB |
Output is correct |
79 |
Correct |
166 ms |
3976 KB |
Output is correct |
80 |
Correct |
501 ms |
15544 KB |
Output is correct |
81 |
Correct |
174 ms |
4028 KB |
Output is correct |
82 |
Correct |
621 ms |
17432 KB |
Output is correct |
83 |
Correct |
609 ms |
17300 KB |
Output is correct |
84 |
Correct |
200 ms |
4000 KB |
Output is correct |
85 |
Correct |
166 ms |
4044 KB |
Output is correct |
86 |
Correct |
422 ms |
15824 KB |
Output is correct |
87 |
Correct |
490 ms |
17428 KB |
Output is correct |
88 |
Correct |
198 ms |
3952 KB |
Output is correct |
89 |
Correct |
409 ms |
16636 KB |
Output is correct |
90 |
Correct |
466 ms |
17484 KB |
Output is correct |
91 |
Correct |
183 ms |
4000 KB |
Output is correct |
92 |
Correct |
507 ms |
15764 KB |
Output is correct |
93 |
Correct |
186 ms |
4024 KB |
Output is correct |
94 |
Correct |
175 ms |
3932 KB |
Output is correct |
95 |
Correct |
181 ms |
4044 KB |
Output is correct |
96 |
Correct |
300 ms |
15676 KB |
Output is correct |
97 |
Correct |
339 ms |
17548 KB |
Output is correct |
98 |
Correct |
441 ms |
11304 KB |
Output is correct |
99 |
Correct |
559 ms |
17708 KB |
Output is correct |
100 |
Correct |
360 ms |
16968 KB |
Output is correct |