Submission #824499

# Submission time Handle Problem Language Result Execution time Memory
824499 2023-08-14T07:02:57 Z vjudge1 Crossing (JOI21_crossing) C++14
0 / 100
162 ms 18380 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const ll N = (1 << 18), x = 5, mod = 1e9 + 7 ;
map<char, int> 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(int l, int r, int 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 ;
    }
    int 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(int l, int r, int 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(int l, int r, int l1, int r1, int num, int v)
{
    push(l, r, v) ;
    if(l > r1 || r < l1)
        return ;
    if(l1 <= l && r <= r1)
    {
        psh[v] = num ;
        push(l, r, v) ;
        return ;
    }
    int 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(int 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(int 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() ;
//        cout << now << '\n' ;
        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 ) ;
    int n, q ;
    string sa, sb, sc ;
    cin >> n >> sa >> sb >> sc >> q >> t ;
    ln = t.size() ;
    bfs(sa, sb, sc) ;
//    cout << "_____________________\n" ;
    build(0, N - 1, 1) ;
//    cout << ans[1] << ' ' ;
    if(us[ans[1]])
        cout << "Yes\n" ;
    else
        cout << "No\n" ;
    while(q--)
    {
        char c ;
        int l, r ;
        cin >> l >> r >> c ;
        update(0, N - 1, l - 1, r - 1, mp[c], 1) ;
//        cout << ans[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:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = 0 ; i < b.size() ; i++)
      |                     ~~^~~~~~~~~~
Main.cpp:67:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   67 |             if(a[i] == 'J' && b[i] == 'O' || a[i] == 'O' && b[i] == 'J')
Main.cpp:69:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   69 |             if(a[i] == 'J' && b[i] == 'I' || a[i] == 'I' && b[i] == 'J')
Main.cpp:71:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   71 |             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:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 0 ; i < s.size() ; i++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 158 ms 17328 KB Output is correct
2 Correct 162 ms 18380 KB Output is correct
3 Correct 126 ms 11080 KB Output is correct
4 Incorrect 144 ms 16848 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 17328 KB Output is correct
2 Correct 162 ms 18380 KB Output is correct
3 Correct 126 ms 11080 KB Output is correct
4 Incorrect 144 ms 16848 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 17328 KB Output is correct
2 Correct 162 ms 18380 KB Output is correct
3 Correct 126 ms 11080 KB Output is correct
4 Incorrect 144 ms 16848 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 17328 KB Output is correct
2 Correct 162 ms 18380 KB Output is correct
3 Correct 126 ms 11080 KB Output is correct
4 Incorrect 144 ms 16848 KB Output isn't correct
5 Halted 0 ms 0 KB -