///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
//#define int long long
string cross(string a,string b)
{
string ans;
ans.resize(a.sz);
for(int i=0; i<a.sz; i++)
{
if(a[i]==b[i])
ans[i]=a[i];
else
{
string o="JOI";
for(int j=0;j<o.sz;j++)
{
if(o[j]==a[i]||o[j]==b[i])continue;
ans[i]=o[j];
}
}
}
return ans;
}
int n;
string a,b;
set<string>st;
vector<int>prfo;
vector<int>prfi;
vector<int>prfj;
string t;
struct segtree
{
vi vals;
int siz=1;
vector<char>lazy;
void init(int n)
{
while(siz<n)
siz*=2;
vals.resize(2*siz);
lazy.resize(2*siz);
}
void check(int l,int r,int x)
{
//cout<<l<<" "<<r<<" "<<lazy[x]<<" "<<vals[x]<<endl;
if(lazy[x]!='-')
{
int p=0;
if(lazy[x]=='O')p=prfo[r]-(l==0?0:prfo[l-1]);
if(lazy[x]=='I')p=prfi[r]-(l==0?0:prfi[l-1]);
if(lazy[x]=='J')p=prfj[r]-(l==0?0:prfj[l-1]);
if(l!=r){
lazy[2*x+1]=lazy[x];
lazy[2*x+2]=lazy[x];
}
vals[x]=p;
lazy[x]='-';
}
}
void build(int x,int lx,int rx)
{
lazy[x]='-';
if(lx==rx)
{
if(lx>=a.sz)vals[x]=0;
else
vals[x]=(a[lx]==t[lx]);
return;
}
int mid=(lx+rx+1)/2;
build(2*x+1,lx,mid-1);
build(2*x+2,mid,rx);
vals[x]=vals[2*x+1]+vals[2*x+2];
}
void build()
{
build(0,0,siz-1);
}
void updrange(int l,int r,char v,int x,int lx,int rx)
{
check(lx,rx,x);
if(lx>r||rx<l)return;
//cout<<lx<<" "<<rx<<" "<<x<<endl;
if(rx<=r&&lx>=l)
{
int p=0;
if(v=='O')p=prfo[rx]-(lx==0?0:prfo[lx-1]);
if(v=='I')p=prfi[rx]-(lx==0?0:prfi[lx-1]);
if(v=='J')p=prfj[rx]-(lx==0?0:prfj[lx-1]);
vals[x]=p;
if(lx!=rx)lazy[2*x+1]=v,lazy[2*x+2]=v,lazy[x]='-';
return;
}
int mid=(lx+rx+1)/2;
updrange(l,r,v,2*x+1,lx,mid-1);
updrange(l,r,v,2*x+2,mid,rx);
vals[x]=vals[2*x+1]+vals[2*x+2];
}
void updrange(int l,int r,char x)
{
updrange(l,r,x,0,0,siz-1);
}
};
void preprocess() {}
void solve()
{
cin>>n;
string s1,s2,s3;
cin>>s1>>s2>>s3;
st.insert(s1);
st.insert(s2);
st.insert(s3);
while(true)
{
int x=st.sz;
for(auto i:st)
for(auto j:st){
if(i!=j)
st.insert(cross(i,j));
}
if(x==st.sz)
break;
}
int q;
cin>>q;
cin>>t;
if(st.find(t)!=st.end())cout<<"Yes"<<endl;
else cout<<"No"<<endl;
vector<pair<pair<int,int>,char>>arr(q);
for(int i=0;i<q;i++)cin>>arr[i].first.first>>arr[i].first.second>>arr[i].second;
vi ans(q);
segtree sg;
sg.init(n);
prfi.resize(3*n);
prfj.resize(3*n);
prfo.resize(3*n);
for(auto i:st)
{
a=i;
int sumo=0,sumi=0,sumj=0;
for(int j=0;j<a.sz;j++)
{
sumo+=(a[j]=='O');
sumi+=(a[j]=='I');
sumj+=(a[j]=='J');
prfo[j]=sumo;
prfi[j]=sumi;
prfj[j]=sumj;
}
// cout<<sumo<<" "<<sumi<<" "<<sumj<<endl;
sg.build();
for(int j=0;j<arr.sz;j++)
{
sg.updrange(arr[j].first.first-1,arr[j].first.second-1,arr[j].second);
// cout<<sg.vals[0]<<" "<<j<<" amsdiomas"<<endl;
if(sg.vals[0]==n)ans[j]=1;
}
}
for(auto i:ans)
{
if(i==1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
signed main()
{
// freopen("div7.in","r",stdin);
//freopen("div7.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
preprocess();
//bla();
int t=1;
//cin>>t;
while(t--)
solve();
}
Compilation message
Main.cpp: In function 'std::string cross(std::string, std::string)':
Main.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i=0; i<a.sz; i++)
| ^
Main.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int j=0;j<o.sz;j++)
| ^
Main.cpp: In member function 'void segtree::build(int, int, int)':
Main.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | if(lx>=a.sz)vals[x]=0;
| ^
Main.cpp: In function 'void solve()':
Main.cpp:141:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
141 | if(x==st.sz)
| ^
Main.cpp:161:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
161 | for(int j=0;j<a.sz;j++)
| ^
Main.cpp:172:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
172 | for(int j=0;j<arr.sz;j++)
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
3868 KB |
Output is correct |
2 |
Correct |
62 ms |
4180 KB |
Output is correct |
3 |
Correct |
60 ms |
4104 KB |
Output is correct |
4 |
Correct |
53 ms |
3924 KB |
Output is correct |
5 |
Correct |
55 ms |
3984 KB |
Output is correct |
6 |
Correct |
52 ms |
3920 KB |
Output is correct |
7 |
Correct |
54 ms |
3932 KB |
Output is correct |
8 |
Correct |
53 ms |
4104 KB |
Output is correct |
9 |
Correct |
56 ms |
4096 KB |
Output is correct |
10 |
Correct |
55 ms |
4092 KB |
Output is correct |
11 |
Correct |
56 ms |
4180 KB |
Output is correct |
12 |
Correct |
54 ms |
4176 KB |
Output is correct |
13 |
Correct |
60 ms |
4100 KB |
Output is correct |
14 |
Correct |
55 ms |
4180 KB |
Output is correct |
15 |
Correct |
56 ms |
4092 KB |
Output is correct |
16 |
Correct |
55 ms |
4100 KB |
Output is correct |
17 |
Correct |
56 ms |
4180 KB |
Output is correct |
18 |
Correct |
58 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
3868 KB |
Output is correct |
2 |
Correct |
62 ms |
4180 KB |
Output is correct |
3 |
Correct |
60 ms |
4104 KB |
Output is correct |
4 |
Correct |
53 ms |
3924 KB |
Output is correct |
5 |
Correct |
55 ms |
3984 KB |
Output is correct |
6 |
Correct |
52 ms |
3920 KB |
Output is correct |
7 |
Correct |
54 ms |
3932 KB |
Output is correct |
8 |
Correct |
53 ms |
4104 KB |
Output is correct |
9 |
Correct |
56 ms |
4096 KB |
Output is correct |
10 |
Correct |
55 ms |
4092 KB |
Output is correct |
11 |
Correct |
56 ms |
4180 KB |
Output is correct |
12 |
Correct |
54 ms |
4176 KB |
Output is correct |
13 |
Correct |
60 ms |
4100 KB |
Output is correct |
14 |
Correct |
55 ms |
4180 KB |
Output is correct |
15 |
Correct |
56 ms |
4092 KB |
Output is correct |
16 |
Correct |
55 ms |
4100 KB |
Output is correct |
17 |
Correct |
56 ms |
4180 KB |
Output is correct |
18 |
Correct |
58 ms |
4176 KB |
Output is correct |
19 |
Correct |
165 ms |
15092 KB |
Output is correct |
20 |
Correct |
166 ms |
14960 KB |
Output is correct |
21 |
Correct |
102 ms |
14416 KB |
Output is correct |
22 |
Correct |
99 ms |
13408 KB |
Output is correct |
23 |
Correct |
86 ms |
4692 KB |
Output is correct |
24 |
Correct |
82 ms |
4944 KB |
Output is correct |
25 |
Correct |
116 ms |
15008 KB |
Output is correct |
26 |
Correct |
108 ms |
14960 KB |
Output is correct |
27 |
Correct |
132 ms |
15084 KB |
Output is correct |
28 |
Correct |
128 ms |
15084 KB |
Output is correct |
29 |
Correct |
124 ms |
14812 KB |
Output is correct |
30 |
Correct |
88 ms |
4732 KB |
Output is correct |
31 |
Correct |
125 ms |
15016 KB |
Output is correct |
32 |
Correct |
118 ms |
14260 KB |
Output is correct |
33 |
Correct |
83 ms |
4684 KB |
Output is correct |
34 |
Correct |
122 ms |
15468 KB |
Output is correct |
35 |
Correct |
100 ms |
12744 KB |
Output is correct |
36 |
Correct |
81 ms |
4692 KB |
Output is correct |
37 |
Correct |
84 ms |
4952 KB |
Output is correct |
38 |
Correct |
141 ms |
14960 KB |
Output is correct |
39 |
Correct |
82 ms |
15084 KB |
Output is correct |
40 |
Correct |
99 ms |
10920 KB |
Output is correct |
41 |
Correct |
162 ms |
15344 KB |
Output is correct |
42 |
Correct |
59 ms |
15332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
3868 KB |
Output is correct |
2 |
Correct |
62 ms |
4180 KB |
Output is correct |
3 |
Correct |
60 ms |
4104 KB |
Output is correct |
4 |
Correct |
53 ms |
3924 KB |
Output is correct |
5 |
Correct |
55 ms |
3984 KB |
Output is correct |
6 |
Correct |
52 ms |
3920 KB |
Output is correct |
7 |
Correct |
54 ms |
3932 KB |
Output is correct |
8 |
Correct |
53 ms |
4104 KB |
Output is correct |
9 |
Correct |
56 ms |
4096 KB |
Output is correct |
10 |
Correct |
55 ms |
4092 KB |
Output is correct |
11 |
Correct |
56 ms |
4180 KB |
Output is correct |
12 |
Correct |
54 ms |
4176 KB |
Output is correct |
13 |
Correct |
60 ms |
4100 KB |
Output is correct |
14 |
Correct |
55 ms |
4180 KB |
Output is correct |
15 |
Correct |
56 ms |
4092 KB |
Output is correct |
16 |
Correct |
55 ms |
4100 KB |
Output is correct |
17 |
Correct |
56 ms |
4180 KB |
Output is correct |
18 |
Correct |
58 ms |
4176 KB |
Output is correct |
19 |
Correct |
329 ms |
4180 KB |
Output is correct |
20 |
Correct |
331 ms |
4176 KB |
Output is correct |
21 |
Correct |
110 ms |
4092 KB |
Output is correct |
22 |
Correct |
107 ms |
3832 KB |
Output is correct |
23 |
Correct |
112 ms |
4116 KB |
Output is correct |
24 |
Correct |
109 ms |
4000 KB |
Output is correct |
25 |
Correct |
112 ms |
4104 KB |
Output is correct |
26 |
Correct |
110 ms |
3988 KB |
Output is correct |
27 |
Correct |
112 ms |
4092 KB |
Output is correct |
28 |
Correct |
104 ms |
3824 KB |
Output is correct |
29 |
Correct |
116 ms |
4176 KB |
Output is correct |
30 |
Correct |
102 ms |
3900 KB |
Output is correct |
31 |
Correct |
283 ms |
4096 KB |
Output is correct |
32 |
Correct |
284 ms |
4092 KB |
Output is correct |
33 |
Correct |
290 ms |
4096 KB |
Output is correct |
34 |
Correct |
262 ms |
3936 KB |
Output is correct |
35 |
Correct |
279 ms |
4176 KB |
Output is correct |
36 |
Correct |
291 ms |
4116 KB |
Output is correct |
37 |
Correct |
287 ms |
4100 KB |
Output is correct |
38 |
Correct |
290 ms |
4096 KB |
Output is correct |
39 |
Correct |
291 ms |
4176 KB |
Output is correct |
40 |
Correct |
284 ms |
4096 KB |
Output is correct |
41 |
Correct |
276 ms |
4108 KB |
Output is correct |
42 |
Correct |
309 ms |
4096 KB |
Output is correct |
43 |
Correct |
278 ms |
4060 KB |
Output is correct |
44 |
Correct |
295 ms |
4176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
3868 KB |
Output is correct |
2 |
Correct |
62 ms |
4180 KB |
Output is correct |
3 |
Correct |
60 ms |
4104 KB |
Output is correct |
4 |
Correct |
53 ms |
3924 KB |
Output is correct |
5 |
Correct |
55 ms |
3984 KB |
Output is correct |
6 |
Correct |
52 ms |
3920 KB |
Output is correct |
7 |
Correct |
54 ms |
3932 KB |
Output is correct |
8 |
Correct |
53 ms |
4104 KB |
Output is correct |
9 |
Correct |
56 ms |
4096 KB |
Output is correct |
10 |
Correct |
55 ms |
4092 KB |
Output is correct |
11 |
Correct |
56 ms |
4180 KB |
Output is correct |
12 |
Correct |
54 ms |
4176 KB |
Output is correct |
13 |
Correct |
60 ms |
4100 KB |
Output is correct |
14 |
Correct |
55 ms |
4180 KB |
Output is correct |
15 |
Correct |
56 ms |
4092 KB |
Output is correct |
16 |
Correct |
55 ms |
4100 KB |
Output is correct |
17 |
Correct |
56 ms |
4180 KB |
Output is correct |
18 |
Correct |
58 ms |
4176 KB |
Output is correct |
19 |
Correct |
165 ms |
15092 KB |
Output is correct |
20 |
Correct |
166 ms |
14960 KB |
Output is correct |
21 |
Correct |
102 ms |
14416 KB |
Output is correct |
22 |
Correct |
99 ms |
13408 KB |
Output is correct |
23 |
Correct |
86 ms |
4692 KB |
Output is correct |
24 |
Correct |
82 ms |
4944 KB |
Output is correct |
25 |
Correct |
116 ms |
15008 KB |
Output is correct |
26 |
Correct |
108 ms |
14960 KB |
Output is correct |
27 |
Correct |
132 ms |
15084 KB |
Output is correct |
28 |
Correct |
128 ms |
15084 KB |
Output is correct |
29 |
Correct |
124 ms |
14812 KB |
Output is correct |
30 |
Correct |
88 ms |
4732 KB |
Output is correct |
31 |
Correct |
125 ms |
15016 KB |
Output is correct |
32 |
Correct |
118 ms |
14260 KB |
Output is correct |
33 |
Correct |
83 ms |
4684 KB |
Output is correct |
34 |
Correct |
122 ms |
15468 KB |
Output is correct |
35 |
Correct |
100 ms |
12744 KB |
Output is correct |
36 |
Correct |
81 ms |
4692 KB |
Output is correct |
37 |
Correct |
84 ms |
4952 KB |
Output is correct |
38 |
Correct |
141 ms |
14960 KB |
Output is correct |
39 |
Correct |
82 ms |
15084 KB |
Output is correct |
40 |
Correct |
99 ms |
10920 KB |
Output is correct |
41 |
Correct |
162 ms |
15344 KB |
Output is correct |
42 |
Correct |
59 ms |
15332 KB |
Output is correct |
43 |
Correct |
329 ms |
4180 KB |
Output is correct |
44 |
Correct |
331 ms |
4176 KB |
Output is correct |
45 |
Correct |
110 ms |
4092 KB |
Output is correct |
46 |
Correct |
107 ms |
3832 KB |
Output is correct |
47 |
Correct |
112 ms |
4116 KB |
Output is correct |
48 |
Correct |
109 ms |
4000 KB |
Output is correct |
49 |
Correct |
112 ms |
4104 KB |
Output is correct |
50 |
Correct |
110 ms |
3988 KB |
Output is correct |
51 |
Correct |
112 ms |
4092 KB |
Output is correct |
52 |
Correct |
104 ms |
3824 KB |
Output is correct |
53 |
Correct |
116 ms |
4176 KB |
Output is correct |
54 |
Correct |
102 ms |
3900 KB |
Output is correct |
55 |
Correct |
283 ms |
4096 KB |
Output is correct |
56 |
Correct |
284 ms |
4092 KB |
Output is correct |
57 |
Correct |
290 ms |
4096 KB |
Output is correct |
58 |
Correct |
262 ms |
3936 KB |
Output is correct |
59 |
Correct |
279 ms |
4176 KB |
Output is correct |
60 |
Correct |
291 ms |
4116 KB |
Output is correct |
61 |
Correct |
287 ms |
4100 KB |
Output is correct |
62 |
Correct |
290 ms |
4096 KB |
Output is correct |
63 |
Correct |
291 ms |
4176 KB |
Output is correct |
64 |
Correct |
284 ms |
4096 KB |
Output is correct |
65 |
Correct |
276 ms |
4108 KB |
Output is correct |
66 |
Correct |
309 ms |
4096 KB |
Output is correct |
67 |
Correct |
278 ms |
4060 KB |
Output is correct |
68 |
Correct |
295 ms |
4176 KB |
Output is correct |
69 |
Correct |
1184 ms |
15080 KB |
Output is correct |
70 |
Correct |
1388 ms |
17212 KB |
Output is correct |
71 |
Correct |
188 ms |
4728 KB |
Output is correct |
72 |
Correct |
187 ms |
4728 KB |
Output is correct |
73 |
Correct |
197 ms |
4712 KB |
Output is correct |
74 |
Correct |
243 ms |
13888 KB |
Output is correct |
75 |
Correct |
185 ms |
4972 KB |
Output is correct |
76 |
Correct |
263 ms |
15476 KB |
Output is correct |
77 |
Correct |
250 ms |
13872 KB |
Output is correct |
78 |
Correct |
188 ms |
4708 KB |
Output is correct |
79 |
Correct |
186 ms |
4692 KB |
Output is correct |
80 |
Correct |
836 ms |
13816 KB |
Output is correct |
81 |
Correct |
503 ms |
4692 KB |
Output is correct |
82 |
Correct |
987 ms |
17256 KB |
Output is correct |
83 |
Correct |
959 ms |
16496 KB |
Output is correct |
84 |
Correct |
518 ms |
4688 KB |
Output is correct |
85 |
Correct |
507 ms |
4692 KB |
Output is correct |
86 |
Correct |
903 ms |
14380 KB |
Output is correct |
87 |
Correct |
939 ms |
17084 KB |
Output is correct |
88 |
Correct |
578 ms |
4688 KB |
Output is correct |
89 |
Correct |
816 ms |
15624 KB |
Output is correct |
90 |
Correct |
860 ms |
17040 KB |
Output is correct |
91 |
Correct |
557 ms |
4964 KB |
Output is correct |
92 |
Correct |
859 ms |
14240 KB |
Output is correct |
93 |
Correct |
508 ms |
4780 KB |
Output is correct |
94 |
Correct |
517 ms |
4780 KB |
Output is correct |
95 |
Correct |
515 ms |
4784 KB |
Output is correct |
96 |
Correct |
145 ms |
14960 KB |
Output is correct |
97 |
Correct |
454 ms |
17012 KB |
Output is correct |
98 |
Correct |
785 ms |
12368 KB |
Output is correct |
99 |
Correct |
1375 ms |
17300 KB |
Output is correct |
100 |
Correct |
503 ms |
17296 KB |
Output is correct |