Submission #824525

# Submission time Handle Problem Language Result Execution time Memory
824525 2023-08-14T07:22:38 Z ZHIRDILBILDIZ Crossing (JOI21_crossing) C++14
0 / 100
436 ms 17612 KB
#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 = 1e15 + 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 ;
    deque<string> d ;
    d.push_back(sa) ;
    d.push_back(sb) ;
    d.push_back(sc) ;
    us[get_hash(sa)] = 1 ;
    us[get_hash(sb)] = 1 ;
    us[get_hash(sc)] = 1 ;
    while(d.size())
    {
        string now = d[0], s1 = mrg(now, sa), s2 = mrg(now, sb), s3 = mrg(now, sc) ;
        ll mr1 = get_hash(s1), mr2 = get_hash(s2), mr3 = get_hash(s3) ;
        d.pop_front() ;
        if(!us[mr1])
        {
            us[mr1] = 1 ;
            d.push_back(s1) ;
        }
        if(!us[mr2])
        {
            us[mr2] = 1 ;
            d.push_back(s2) ;
        }
        if(!us[mr3])
        {
            us[mr3] = 1 ;
            d.push_back(s3) ;
        }
    }
}
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

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
1 Correct 417 ms 16508 KB Output is correct
2 Correct 408 ms 17612 KB Output is correct
3 Correct 375 ms 10240 KB Output is correct
4 Incorrect 436 ms 16232 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 417 ms 16508 KB Output is correct
2 Correct 408 ms 17612 KB Output is correct
3 Correct 375 ms 10240 KB Output is correct
4 Incorrect 436 ms 16232 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 417 ms 16508 KB Output is correct
2 Correct 408 ms 17612 KB Output is correct
3 Correct 375 ms 10240 KB Output is correct
4 Incorrect 436 ms 16232 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 417 ms 16508 KB Output is correct
2 Correct 408 ms 17612 KB Output is correct
3 Correct 375 ms 10240 KB Output is correct
4 Incorrect 436 ms 16232 KB Output isn't correct
5 Halted 0 ms 0 KB -