This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const ll N = (1 << 18), x = 7, mod = 1e9 + 7 ;
map<char, ll> mp ;
map<ll, bool> us ;
string t ;
ll ln, pw[N + 1], psh[2 * N + 1], sum[2 * N + 1], ans[2 * N + 1] ;
void build(ll l, ll r, ll v)
{
if(l == r)
{
if(l >= ln)
return ;
if(!l)
pw[l] = 1 ;
else
pw[l] = pw[l - 1] * x ;
pw[l] %= mod ;
sum[v] = pw[l] ;
ans[v] = (mp[t[l]] * pw[l]) % mod ;
return ;
}
ll mid = (l + r) >> 1 ;
build(l, mid, v * 2) ;
build(mid + 1, r, v * 2 + 1) ;
sum[v] = (sum[v * 2] + sum[v * 2 + 1]) % mod ;
ans[v] = (ans[v * 2] + ans[v * 2 + 1]) % mod ;
}
void push(ll l, ll r, ll v)
{
if(!psh[v])
return ;
ll num = psh[v] ;
ans[v] = (sum[v] * num) % mod ;
psh[v] = 0 ;
if(l == r)
return ;
psh[v * 2] = num ;
psh[v * 2 + 1] = num ;
}
void update(ll l, ll r, ll l1, ll r1, ll num, ll v)
{
push(l, r, v) ;
if(l > r1 || r < l1)
return ;
if(l1 <= l && r <= r1)
{
psh[v] = num ;
push(l, r, v) ;
return ;
}
ll mid = (l + r) >> 1 ;
update(l, mid, l1, r1, num, v * 2) ;
update(mid + 1, r, l1, r1, num, v * 2 + 1) ;
ans[v] = ans[v * 2] + ans[v * 2 + 1] ;
}
string mrg(string &a, string &b)
{
string c ;
for(ll i = 0 ; i < b.size() ; i++)
if(a[i] == b[i])
c.push_back(a[i]) ;
else
{
if(a[i] == 'J' && b[i] == 'O' || a[i] == 'O' && b[i] == 'J')
c.push_back('I') ;
if(a[i] == 'J' && b[i] == 'I' || a[i] == 'I' && b[i] == 'J')
c.push_back('O') ;
if(a[i] == 'I' && b[i] == 'O' || a[i] == 'O' && b[i] == 'I')
c.push_back('J') ;
}
return c ;
}
ll get_hash(string &s)
{
ll sum = 0, p = 1 ;
for(ll i = 0 ; i < s.size() ; i++)
{
sum += mp[s[i]] * p ;
p *= x ;
p %= mod ;
sum %= mod ;
}
return sum ;
}
void bfs(string sa, string sb, string sc)
{
mp['J'] = 1 ;
mp['O'] = 2 ;
mp['I'] = 3 ;
string abu ;
vector<string> v ;
v.push_back(sa) ;
v.push_back(sb) ;
v.push_back(sc) ;
v.push_back(mrg(sa, sb)) ;
v.push_back(mrg(sa, sc)) ;
v.push_back(mrg(sb, sc)) ;
abu = mrg(sb, sc) ;
v.push_back(mrg(sa, abu)) ;
abu = mrg(sc, sb) ;
v.push_back(mrg(sa, abu)) ;
abu = mrg(sa, sc) ;
v.push_back(mrg(sb, abu)) ;
abu = mrg(sc, sa) ;
v.push_back(mrg(sb, abu)) ;
abu = mrg(sa, sb) ;
v.push_back(mrg(sc, abu)) ;
abu = mrg(sb, sa) ;
v.push_back(mrg(sc, abu)) ;
for(string i : v)
us[get_hash(i)] = 1 ;
}
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
ll n, q ;
string sa, sb, sc ;
cin >> n >> sa >> sb >> sc >> q >> t ;
ln = t.size() ;
bfs(sa, sb, sc) ;
build(0, N - 1, 1) ;
if(us[ans[1]])
cout << "Yes\n" ;
else
cout << "No\n" ;
while(q--)
{
char c ;
ll l, r ;
cin >> l >> r >> c ;
l-- ;
r-- ;
update(0, N - 1, l, r, mp[c], 1) ;
if(us[ans[1]])
cout << "Yes\n" ;
else
cout << "No\n" ;
}
return 0 ;
}
Compilation message (stderr)
Main.cpp: In function 'std::string mrg(std::string&, std::string&)':
Main.cpp:63:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(ll i = 0 ; i < b.size() ; i++)
| ~~^~~~~~~~~~
Main.cpp:68:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
68 | if(a[i] == 'J' && b[i] == 'O' || a[i] == 'O' && b[i] == 'J')
Main.cpp:70:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
70 | if(a[i] == 'J' && b[i] == 'I' || a[i] == 'I' && b[i] == 'J')
Main.cpp:72:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
72 | if(a[i] == 'I' && b[i] == 'O' || a[i] == 'O' && b[i] == 'I')
Main.cpp: In function 'long long int get_hash(std::string&)':
Main.cpp:80:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | for(ll i = 0 ; i < s.size() ; i++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |