제출 #827198

#제출 시각아이디문제언어결과실행 시간메모리
827198vjudge1Crossing (JOI21_crossing)C++14
100 / 100
437 ms30356 KiB
#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 ;
ll n, q, pw[N + 1], sum[2 * N + 1], ans[2 * N + 1], psh[2 * N + 1] ;
string sa, sb, sc, t ;
map<char, int> mp ;
map<ll, bool> us ;
void push(ll l, ll r, ll v)
{
    if(!psh[v])
        return ;
    ll num = psh[v] ;
    psh[v] &= 0 ;
    ans[v] = (sum[v] * num) % mod ;
    if(l == r)
        return ;
    psh[v * 2] = psh[v * 2 + 1] = num ;
}
void build(ll l, ll r, ll v)
{
    if(l == r)
    {
        if(l >= t.size())
            return ;
        sum[v] = pw[l] ;
        ans[v] = (pw[l] * mp[t[l]]) % mod ;
        return ;
    }
    ll mid = (l + r) >> 1 ;
    build(l, mid, v * 2) ;
    build(mid + 1, r, v * 2 + 1) ;
    ans[v] = (ans[v * 2] + ans[v * 2 + 1]) % mod ;
    sum[v] = (sum[v * 2] + sum[v * 2 + 1]) % mod ;
}
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)
    {
//        cout<<l<<' '<<r<<' '<<sum[v] << '\n' ;
        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]) % mod ;
}
ll get_hash(string s)
{
    ll now = 0 ;
    for(ll i = 0 ; i < s.size() ; i++)
    {
        now += mp[s[i]] * pw[i] ;
        now %= mod ;
    }
    return now ;
}
string mrg(string &a, string &b)
{
    string c ;
    for(ll i = 0 ; i < a.size() ; i++)
        if(a[i] == b[i])
            c += a[i] ;
        else
        {
            if(a[i] == 'J' && b[i] == 'O' || a[i] == 'O' && b[i] == 'J')
                c += 'I' ;
            if(a[i] == 'J' && b[i] == 'I' || a[i] == 'I' && b[i] == 'J')
                c += 'O' ;
            if(a[i] == 'I' && b[i] == 'O' || a[i] == 'O' && b[i] == 'I')
                c += 'J' ;
        }
    return c ;
}
void bfs()
{
    mp['J'] = 1 ;
    mp['O'] = 2 ;
    mp['I'] = 3 ;
    deque<string> d ;
    pw[0] = 1 ;
    for(ll i = 1 ; i <= N ; i++)
    {
        pw[i] = pw[i - 1] * x ;
        pw[i] %= mod ;
    }
    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], now1 = mrg(now, sa), now2 = mrg(now, sb), now3 = mrg(now, sc) ;
        ll num1 = get_hash(now1), num2 = get_hash(now2), num3 = get_hash(now3) ;
        d.pop_front() ;
        if(!us[num1])
        {
            us[num1] = 1 ;
            d.push_back(now1) ;
        }
        if(!us[num2])
        {
            us[num2] = 1 ;
            d.push_back(now2) ;
        }
        if(!us[num3])
        {
            us[num3] = 1 ;
            d.push_back(now3) ;
        }
    }
}
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    cin >> n >> sa >> sb >> sc >> q >> t ;
    bfs() ;
    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) ;
//        cout << ans[1] << '\n' ;
        if(us[ans[1]])
            cout << "Yes\n" ;
        else
            cout << "No\n" ;
    }
    return 0 ;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void build(long long int, long long int, long long int)':
Main.cpp:26:14: 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]
   26 |         if(l >= t.size())
      |            ~~^~~~~~~~~~~
Main.cpp: In function 'long long int get_hash(std::string)':
Main.cpp:58: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]
   58 |     for(ll i = 0 ; i < s.size() ; i++)
      |                    ~~^~~~~~~~~~
Main.cpp: In function 'std::string mrg(std::string&, std::string&)':
Main.cpp:68: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]
   68 |     for(ll i = 0 ; i < a.size() ; i++)
      |                    ~~^~~~~~~~~~
Main.cpp:73:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   73 |             if(a[i] == 'J' && b[i] == 'O' || a[i] == 'O' && b[i] == 'J')
Main.cpp:75:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   75 |             if(a[i] == 'J' && b[i] == 'I' || a[i] == 'I' && b[i] == 'J')
Main.cpp:77:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   77 |             if(a[i] == 'I' && b[i] == 'O' || a[i] == 'O' && b[i] == 'I')
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...