답안 #827198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
827198 2023-08-16T09:47:38 Z vjudge1 Crossing (JOI21_crossing) C++14
100 / 100
437 ms 30356 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 ;
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 ;
}

Compilation message

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')
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 16452 KB Output is correct
2 Correct 193 ms 17232 KB Output is correct
3 Correct 126 ms 10676 KB Output is correct
4 Correct 149 ms 17136 KB Output is correct
5 Correct 196 ms 18848 KB Output is correct
6 Correct 159 ms 17884 KB Output is correct
7 Correct 162 ms 18340 KB Output is correct
8 Correct 147 ms 19044 KB Output is correct
9 Correct 144 ms 18708 KB Output is correct
10 Correct 215 ms 20200 KB Output is correct
11 Correct 151 ms 19416 KB Output is correct
12 Correct 185 ms 20120 KB Output is correct
13 Correct 144 ms 19432 KB Output is correct
14 Correct 239 ms 20200 KB Output is correct
15 Correct 146 ms 19396 KB Output is correct
16 Correct 154 ms 20180 KB Output is correct
17 Correct 145 ms 19404 KB Output is correct
18 Correct 130 ms 10464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 16452 KB Output is correct
2 Correct 193 ms 17232 KB Output is correct
3 Correct 126 ms 10676 KB Output is correct
4 Correct 149 ms 17136 KB Output is correct
5 Correct 196 ms 18848 KB Output is correct
6 Correct 159 ms 17884 KB Output is correct
7 Correct 162 ms 18340 KB Output is correct
8 Correct 147 ms 19044 KB Output is correct
9 Correct 144 ms 18708 KB Output is correct
10 Correct 215 ms 20200 KB Output is correct
11 Correct 151 ms 19416 KB Output is correct
12 Correct 185 ms 20120 KB Output is correct
13 Correct 144 ms 19432 KB Output is correct
14 Correct 239 ms 20200 KB Output is correct
15 Correct 146 ms 19396 KB Output is correct
16 Correct 154 ms 20180 KB Output is correct
17 Correct 145 ms 19404 KB Output is correct
18 Correct 130 ms 10464 KB Output is correct
19 Correct 437 ms 27564 KB Output is correct
20 Correct 281 ms 25776 KB Output is correct
21 Correct 345 ms 28560 KB Output is correct
22 Correct 275 ms 25724 KB Output is correct
23 Correct 182 ms 22216 KB Output is correct
24 Correct 208 ms 21072 KB Output is correct
25 Correct 265 ms 29948 KB Output is correct
26 Correct 275 ms 27992 KB Output is correct
27 Correct 285 ms 30220 KB Output is correct
28 Correct 265 ms 27904 KB Output is correct
29 Correct 249 ms 29728 KB Output is correct
30 Correct 202 ms 22304 KB Output is correct
31 Correct 282 ms 30356 KB Output is correct
32 Correct 249 ms 26984 KB Output is correct
33 Correct 174 ms 20868 KB Output is correct
34 Correct 265 ms 27972 KB Output is correct
35 Correct 209 ms 25832 KB Output is correct
36 Correct 191 ms 21012 KB Output is correct
37 Correct 186 ms 21072 KB Output is correct
38 Correct 257 ms 22960 KB Output is correct
39 Correct 165 ms 21156 KB Output is correct
40 Correct 262 ms 25552 KB Output is correct
41 Correct 199 ms 18328 KB Output is correct
42 Correct 79 ms 14392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 16452 KB Output is correct
2 Correct 193 ms 17232 KB Output is correct
3 Correct 126 ms 10676 KB Output is correct
4 Correct 149 ms 17136 KB Output is correct
5 Correct 196 ms 18848 KB Output is correct
6 Correct 159 ms 17884 KB Output is correct
7 Correct 162 ms 18340 KB Output is correct
8 Correct 147 ms 19044 KB Output is correct
9 Correct 144 ms 18708 KB Output is correct
10 Correct 215 ms 20200 KB Output is correct
11 Correct 151 ms 19416 KB Output is correct
12 Correct 185 ms 20120 KB Output is correct
13 Correct 144 ms 19432 KB Output is correct
14 Correct 239 ms 20200 KB Output is correct
15 Correct 146 ms 19396 KB Output is correct
16 Correct 154 ms 20180 KB Output is correct
17 Correct 145 ms 19404 KB Output is correct
18 Correct 130 ms 10464 KB Output is correct
19 Correct 171 ms 18220 KB Output is correct
20 Correct 123 ms 12108 KB Output is correct
21 Correct 154 ms 19532 KB Output is correct
22 Correct 127 ms 17408 KB Output is correct
23 Correct 158 ms 19704 KB Output is correct
24 Correct 140 ms 18420 KB Output is correct
25 Correct 145 ms 19532 KB Output is correct
26 Correct 160 ms 18108 KB Output is correct
27 Correct 152 ms 19620 KB Output is correct
28 Correct 139 ms 18416 KB Output is correct
29 Correct 159 ms 18892 KB Output is correct
30 Correct 146 ms 17780 KB Output is correct
31 Correct 146 ms 19812 KB Output is correct
32 Correct 170 ms 19608 KB Output is correct
33 Correct 143 ms 19176 KB Output is correct
34 Correct 138 ms 18120 KB Output is correct
35 Correct 184 ms 20220 KB Output is correct
36 Correct 150 ms 19408 KB Output is correct
37 Correct 157 ms 20332 KB Output is correct
38 Correct 142 ms 19404 KB Output is correct
39 Correct 186 ms 20160 KB Output is correct
40 Correct 150 ms 19404 KB Output is correct
41 Correct 163 ms 20100 KB Output is correct
42 Correct 147 ms 19348 KB Output is correct
43 Correct 160 ms 18640 KB Output is correct
44 Correct 143 ms 19096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 16452 KB Output is correct
2 Correct 193 ms 17232 KB Output is correct
3 Correct 126 ms 10676 KB Output is correct
4 Correct 149 ms 17136 KB Output is correct
5 Correct 196 ms 18848 KB Output is correct
6 Correct 159 ms 17884 KB Output is correct
7 Correct 162 ms 18340 KB Output is correct
8 Correct 147 ms 19044 KB Output is correct
9 Correct 144 ms 18708 KB Output is correct
10 Correct 215 ms 20200 KB Output is correct
11 Correct 151 ms 19416 KB Output is correct
12 Correct 185 ms 20120 KB Output is correct
13 Correct 144 ms 19432 KB Output is correct
14 Correct 239 ms 20200 KB Output is correct
15 Correct 146 ms 19396 KB Output is correct
16 Correct 154 ms 20180 KB Output is correct
17 Correct 145 ms 19404 KB Output is correct
18 Correct 130 ms 10464 KB Output is correct
19 Correct 437 ms 27564 KB Output is correct
20 Correct 281 ms 25776 KB Output is correct
21 Correct 345 ms 28560 KB Output is correct
22 Correct 275 ms 25724 KB Output is correct
23 Correct 182 ms 22216 KB Output is correct
24 Correct 208 ms 21072 KB Output is correct
25 Correct 265 ms 29948 KB Output is correct
26 Correct 275 ms 27992 KB Output is correct
27 Correct 285 ms 30220 KB Output is correct
28 Correct 265 ms 27904 KB Output is correct
29 Correct 249 ms 29728 KB Output is correct
30 Correct 202 ms 22304 KB Output is correct
31 Correct 282 ms 30356 KB Output is correct
32 Correct 249 ms 26984 KB Output is correct
33 Correct 174 ms 20868 KB Output is correct
34 Correct 265 ms 27972 KB Output is correct
35 Correct 209 ms 25832 KB Output is correct
36 Correct 191 ms 21012 KB Output is correct
37 Correct 186 ms 21072 KB Output is correct
38 Correct 257 ms 22960 KB Output is correct
39 Correct 165 ms 21156 KB Output is correct
40 Correct 262 ms 25552 KB Output is correct
41 Correct 199 ms 18328 KB Output is correct
42 Correct 79 ms 14392 KB Output is correct
43 Correct 171 ms 18220 KB Output is correct
44 Correct 123 ms 12108 KB Output is correct
45 Correct 154 ms 19532 KB Output is correct
46 Correct 127 ms 17408 KB Output is correct
47 Correct 158 ms 19704 KB Output is correct
48 Correct 140 ms 18420 KB Output is correct
49 Correct 145 ms 19532 KB Output is correct
50 Correct 160 ms 18108 KB Output is correct
51 Correct 152 ms 19620 KB Output is correct
52 Correct 139 ms 18416 KB Output is correct
53 Correct 159 ms 18892 KB Output is correct
54 Correct 146 ms 17780 KB Output is correct
55 Correct 146 ms 19812 KB Output is correct
56 Correct 170 ms 19608 KB Output is correct
57 Correct 143 ms 19176 KB Output is correct
58 Correct 138 ms 18120 KB Output is correct
59 Correct 184 ms 20220 KB Output is correct
60 Correct 150 ms 19408 KB Output is correct
61 Correct 157 ms 20332 KB Output is correct
62 Correct 142 ms 19404 KB Output is correct
63 Correct 186 ms 20160 KB Output is correct
64 Correct 150 ms 19404 KB Output is correct
65 Correct 163 ms 20100 KB Output is correct
66 Correct 147 ms 19348 KB Output is correct
67 Correct 160 ms 18640 KB Output is correct
68 Correct 143 ms 19096 KB Output is correct
69 Correct 310 ms 25056 KB Output is correct
70 Correct 357 ms 25780 KB Output is correct
71 Correct 174 ms 21004 KB Output is correct
72 Correct 184 ms 21120 KB Output is correct
73 Correct 185 ms 21124 KB Output is correct
74 Correct 231 ms 27092 KB Output is correct
75 Correct 187 ms 22320 KB Output is correct
76 Correct 311 ms 30020 KB Output is correct
77 Correct 236 ms 25884 KB Output is correct
78 Correct 169 ms 21064 KB Output is correct
79 Correct 174 ms 21008 KB Output is correct
80 Correct 274 ms 25636 KB Output is correct
81 Correct 204 ms 22264 KB Output is correct
82 Correct 345 ms 29880 KB Output is correct
83 Correct 309 ms 26896 KB Output is correct
84 Correct 174 ms 21056 KB Output is correct
85 Correct 182 ms 21008 KB Output is correct
86 Correct 235 ms 25116 KB Output is correct
87 Correct 297 ms 27996 KB Output is correct
88 Correct 178 ms 20416 KB Output is correct
89 Correct 258 ms 26256 KB Output is correct
90 Correct 288 ms 28216 KB Output is correct
91 Correct 170 ms 20456 KB Output is correct
92 Correct 292 ms 25936 KB Output is correct
93 Correct 203 ms 21112 KB Output is correct
94 Correct 236 ms 21096 KB Output is correct
95 Correct 183 ms 21052 KB Output is correct
96 Correct 208 ms 22956 KB Output is correct
97 Correct 217 ms 22420 KB Output is correct
98 Correct 282 ms 25596 KB Output is correct
99 Correct 280 ms 19312 KB Output is correct
100 Correct 168 ms 15476 KB Output is correct