Submission #881499

# Submission time Handle Problem Language Result Execution time Memory
881499 2023-12-01T10:03:41 Z Arshi Crossing (JOI21_crossing) C++17
100 / 100
650 ms 22852 KB
/**********************GOD**********************/

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll , ll> pll;

#define len                 length()
#define MP                  make_pair
#define fs                  first
#define sc                  second
#define pb                  push_back
#define all(x)              x.begin() , x.end()
#define kill(x)             cout << x , exit(0)
#define lid                 (id << 1)
#define rid                 (lid | 1)
#define mid                 ((r + l) >> 1)

const ll mod = 1000696969;
const ll base = 737;
const ll MXN = 2e5 + 4;

ll n;
set<ll> st;
map<char, ll> mp;
string s[4], t;
ll seg[MXN << 2], lz[MXN << 2];
ll pre[MXN][4];

ll pw(ll a, ll b)
{
    ll c = 1;
    while(b > 0) {
        if(b % 2)
            c = c * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return c;
}

ll Hash(string str)
{
    ll ans = 0;
    for(int i = 1; i <= n; i ++) {
        ll x = pw(base, i - 1);
        ll y = x * mp[str[i]] % mod;
        ans = (ans + y) % mod;
    }
    return ans;
}

void Build(int id = 1, int l = 1, int r = n + 1)
{
    if(r - l < 2) {
        seg[id] = mp[t[l]];
        return;
    }
    Build(lid, l, mid);
    Build(rid, mid, r);
    ll x = pw(base, mid - l);
    seg[id] = (seg[lid] + x * seg[rid] % mod) % mod;
}

void Shift(int id, int l, int r)
{
    if(!lz[id])
        return;
    lz[lid] = lz[rid] = lz[id];
    seg[lid] = pre[mid - l][lz[id]];
    seg[rid] = pre[r - mid][lz[id]];
    lz[id] = 0;
}

void Update(int ql, int qr, int v, int id = 1, int l = 1, int r = n + 1)
{
    if(qr <= l || r <= ql)
        return;
    if(ql <= l && r <= qr) {
        seg[id] = pre[r - l][v];
        lz[id] = v;
        return;
    }
    Shift(id, l, r);
    Update(ql, qr, v, lid, l, mid);
    Update(ql, qr, v, rid, mid, r);
    ll x = pw(base, mid - l);
    seg[id] = (seg[lid] + x * seg[rid] % mod) % mod;
}

string Comb(string a, string b)
{
    string c = a;
    for(int i = 1; i <= n; i ++) {
        if(a[i] == b[i])
            continue;
        if(a[i] == 'J') {
            if(b[i] == 'O')
                c[i] = 'I';
            else
                c[i] = 'O';
        }
        if(a[i] == 'O') {
            if(b[i] == 'J')
                c[i] = 'I';
            else
                c[i] = 'J';
        }
        if(a[i] == 'I') {
            if(b[i] == 'J')
                c[i] = 'O';
            else
                c[i] = 'J';
        }
    }
    return c;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n; mp['J'] = 1; mp['O'] = 2; mp['I'] = 3;
    for(int i = 0; i < 3; i ++) {
        cin >> s[i];
        s[i] ='#' + s[i];
    }

    for(int mask = 1; mask < 8; mask ++) {
        vector<string> vc;
        for(int i = 0; i < 3; i ++)
            if(mask >> i & 1) {
                vc.pb(s[i]);
            }
        ll sz = 1;
        for(ll i = 1; i <= vc.size(); i ++)
            sz *= i;
        for(ll j = 0; j < sz; j ++) {
            string tmp = vc[0];
            for(int i = 1; i < vc.size(); i ++)
                tmp = Comb(tmp, vc[i]);
            ll val = Hash(tmp);
            st.insert(val);
            next_permutation(all(vc));
        }
    }

    for(ll i = 1; i <= n; i ++)
        for(ll j = 1; j < 4; j ++)
            pre[i][j] = (pre[i - 1][j] + j * pw(base, i - 1) % mod) % mod; 
    
    int q; cin >> q >> t;
    t = '#' + t;
    Build();
    if(st.count(seg[1]))
        cout << "Yes\n";
    else
        cout << "No\n";
    while(q --) {
        char c; int l, r;
        cin >> l >> r >> c;
        Update(l, r + 1, mp[c]);
        if(st.count(seg[1]))
            cout << "Yes\n";
        else
            cout << "No\n";
    }

    return 0;
}

/*!
ahkh
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:150:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |         for(ll i = 1; i <= vc.size(); i ++)
      |                       ~~^~~~~~~~~~~~
Main.cpp:154:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |             for(int i = 1; i < vc.size(); i ++)
      |                            ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 60 ms 4432 KB Output is correct
2 Correct 71 ms 4480 KB Output is correct
3 Correct 72 ms 4432 KB Output is correct
4 Correct 61 ms 6404 KB Output is correct
5 Correct 62 ms 6384 KB Output is correct
6 Correct 60 ms 6484 KB Output is correct
7 Correct 66 ms 6532 KB Output is correct
8 Correct 63 ms 6640 KB Output is correct
9 Correct 63 ms 6480 KB Output is correct
10 Correct 78 ms 6488 KB Output is correct
11 Correct 63 ms 6620 KB Output is correct
12 Correct 62 ms 6484 KB Output is correct
13 Correct 64 ms 6624 KB Output is correct
14 Correct 64 ms 6500 KB Output is correct
15 Correct 65 ms 6484 KB Output is correct
16 Correct 63 ms 6480 KB Output is correct
17 Correct 64 ms 6484 KB Output is correct
18 Correct 65 ms 4488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 4432 KB Output is correct
2 Correct 71 ms 4480 KB Output is correct
3 Correct 72 ms 4432 KB Output is correct
4 Correct 61 ms 6404 KB Output is correct
5 Correct 62 ms 6384 KB Output is correct
6 Correct 60 ms 6484 KB Output is correct
7 Correct 66 ms 6532 KB Output is correct
8 Correct 63 ms 6640 KB Output is correct
9 Correct 63 ms 6480 KB Output is correct
10 Correct 78 ms 6488 KB Output is correct
11 Correct 63 ms 6620 KB Output is correct
12 Correct 62 ms 6484 KB Output is correct
13 Correct 64 ms 6624 KB Output is correct
14 Correct 64 ms 6500 KB Output is correct
15 Correct 65 ms 6484 KB Output is correct
16 Correct 63 ms 6480 KB Output is correct
17 Correct 64 ms 6484 KB Output is correct
18 Correct 65 ms 4488 KB Output is correct
19 Correct 572 ms 22644 KB Output is correct
20 Correct 605 ms 20760 KB Output is correct
21 Correct 465 ms 22352 KB Output is correct
22 Correct 411 ms 22084 KB Output is correct
23 Correct 147 ms 11744 KB Output is correct
24 Correct 156 ms 11796 KB Output is correct
25 Correct 480 ms 22512 KB Output is correct
26 Correct 487 ms 22544 KB Output is correct
27 Correct 513 ms 22564 KB Output is correct
28 Correct 512 ms 22716 KB Output is correct
29 Correct 509 ms 22768 KB Output is correct
30 Correct 159 ms 11856 KB Output is correct
31 Correct 521 ms 22448 KB Output is correct
32 Correct 465 ms 22452 KB Output is correct
33 Correct 150 ms 11680 KB Output is correct
34 Correct 526 ms 22744 KB Output is correct
35 Correct 387 ms 21804 KB Output is correct
36 Correct 155 ms 11760 KB Output is correct
37 Correct 147 ms 11872 KB Output is correct
38 Correct 559 ms 20924 KB Output is correct
39 Correct 467 ms 20620 KB Output is correct
40 Correct 377 ms 17776 KB Output is correct
41 Correct 621 ms 22756 KB Output is correct
42 Correct 314 ms 17812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 4432 KB Output is correct
2 Correct 71 ms 4480 KB Output is correct
3 Correct 72 ms 4432 KB Output is correct
4 Correct 61 ms 6404 KB Output is correct
5 Correct 62 ms 6384 KB Output is correct
6 Correct 60 ms 6484 KB Output is correct
7 Correct 66 ms 6532 KB Output is correct
8 Correct 63 ms 6640 KB Output is correct
9 Correct 63 ms 6480 KB Output is correct
10 Correct 78 ms 6488 KB Output is correct
11 Correct 63 ms 6620 KB Output is correct
12 Correct 62 ms 6484 KB Output is correct
13 Correct 64 ms 6624 KB Output is correct
14 Correct 64 ms 6500 KB Output is correct
15 Correct 65 ms 6484 KB Output is correct
16 Correct 63 ms 6480 KB Output is correct
17 Correct 64 ms 6484 KB Output is correct
18 Correct 65 ms 4488 KB Output is correct
19 Correct 70 ms 4432 KB Output is correct
20 Correct 82 ms 4348 KB Output is correct
21 Correct 66 ms 6672 KB Output is correct
22 Correct 62 ms 6484 KB Output is correct
23 Correct 64 ms 6484 KB Output is correct
24 Correct 66 ms 6476 KB Output is correct
25 Correct 65 ms 6480 KB Output is correct
26 Correct 62 ms 6480 KB Output is correct
27 Correct 64 ms 6732 KB Output is correct
28 Correct 64 ms 6388 KB Output is correct
29 Correct 67 ms 6484 KB Output is correct
30 Correct 59 ms 6412 KB Output is correct
31 Correct 66 ms 6480 KB Output is correct
32 Correct 71 ms 6596 KB Output is correct
33 Correct 68 ms 6484 KB Output is correct
34 Correct 60 ms 6508 KB Output is correct
35 Correct 68 ms 6652 KB Output is correct
36 Correct 67 ms 6480 KB Output is correct
37 Correct 67 ms 6480 KB Output is correct
38 Correct 74 ms 6440 KB Output is correct
39 Correct 67 ms 6600 KB Output is correct
40 Correct 74 ms 6444 KB Output is correct
41 Correct 67 ms 6684 KB Output is correct
42 Correct 67 ms 6484 KB Output is correct
43 Correct 64 ms 6484 KB Output is correct
44 Correct 68 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 4432 KB Output is correct
2 Correct 71 ms 4480 KB Output is correct
3 Correct 72 ms 4432 KB Output is correct
4 Correct 61 ms 6404 KB Output is correct
5 Correct 62 ms 6384 KB Output is correct
6 Correct 60 ms 6484 KB Output is correct
7 Correct 66 ms 6532 KB Output is correct
8 Correct 63 ms 6640 KB Output is correct
9 Correct 63 ms 6480 KB Output is correct
10 Correct 78 ms 6488 KB Output is correct
11 Correct 63 ms 6620 KB Output is correct
12 Correct 62 ms 6484 KB Output is correct
13 Correct 64 ms 6624 KB Output is correct
14 Correct 64 ms 6500 KB Output is correct
15 Correct 65 ms 6484 KB Output is correct
16 Correct 63 ms 6480 KB Output is correct
17 Correct 64 ms 6484 KB Output is correct
18 Correct 65 ms 4488 KB Output is correct
19 Correct 572 ms 22644 KB Output is correct
20 Correct 605 ms 20760 KB Output is correct
21 Correct 465 ms 22352 KB Output is correct
22 Correct 411 ms 22084 KB Output is correct
23 Correct 147 ms 11744 KB Output is correct
24 Correct 156 ms 11796 KB Output is correct
25 Correct 480 ms 22512 KB Output is correct
26 Correct 487 ms 22544 KB Output is correct
27 Correct 513 ms 22564 KB Output is correct
28 Correct 512 ms 22716 KB Output is correct
29 Correct 509 ms 22768 KB Output is correct
30 Correct 159 ms 11856 KB Output is correct
31 Correct 521 ms 22448 KB Output is correct
32 Correct 465 ms 22452 KB Output is correct
33 Correct 150 ms 11680 KB Output is correct
34 Correct 526 ms 22744 KB Output is correct
35 Correct 387 ms 21804 KB Output is correct
36 Correct 155 ms 11760 KB Output is correct
37 Correct 147 ms 11872 KB Output is correct
38 Correct 559 ms 20924 KB Output is correct
39 Correct 467 ms 20620 KB Output is correct
40 Correct 377 ms 17776 KB Output is correct
41 Correct 621 ms 22756 KB Output is correct
42 Correct 314 ms 17812 KB Output is correct
43 Correct 70 ms 4432 KB Output is correct
44 Correct 82 ms 4348 KB Output is correct
45 Correct 66 ms 6672 KB Output is correct
46 Correct 62 ms 6484 KB Output is correct
47 Correct 64 ms 6484 KB Output is correct
48 Correct 66 ms 6476 KB Output is correct
49 Correct 65 ms 6480 KB Output is correct
50 Correct 62 ms 6480 KB Output is correct
51 Correct 64 ms 6732 KB Output is correct
52 Correct 64 ms 6388 KB Output is correct
53 Correct 67 ms 6484 KB Output is correct
54 Correct 59 ms 6412 KB Output is correct
55 Correct 66 ms 6480 KB Output is correct
56 Correct 71 ms 6596 KB Output is correct
57 Correct 68 ms 6484 KB Output is correct
58 Correct 60 ms 6508 KB Output is correct
59 Correct 68 ms 6652 KB Output is correct
60 Correct 67 ms 6480 KB Output is correct
61 Correct 67 ms 6480 KB Output is correct
62 Correct 74 ms 6440 KB Output is correct
63 Correct 67 ms 6600 KB Output is correct
64 Correct 74 ms 6444 KB Output is correct
65 Correct 67 ms 6684 KB Output is correct
66 Correct 67 ms 6484 KB Output is correct
67 Correct 64 ms 6484 KB Output is correct
68 Correct 68 ms 6492 KB Output is correct
69 Correct 513 ms 21972 KB Output is correct
70 Correct 650 ms 20964 KB Output is correct
71 Correct 158 ms 11860 KB Output is correct
72 Correct 149 ms 11864 KB Output is correct
73 Correct 150 ms 11860 KB Output is correct
74 Correct 433 ms 22020 KB Output is correct
75 Correct 152 ms 11648 KB Output is correct
76 Correct 524 ms 22504 KB Output is correct
77 Correct 438 ms 22280 KB Output is correct
78 Correct 149 ms 11752 KB Output is correct
79 Correct 150 ms 11844 KB Output is correct
80 Correct 404 ms 21828 KB Output is correct
81 Correct 161 ms 11820 KB Output is correct
82 Correct 526 ms 22448 KB Output is correct
83 Correct 502 ms 22468 KB Output is correct
84 Correct 155 ms 11840 KB Output is correct
85 Correct 156 ms 11804 KB Output is correct
86 Correct 440 ms 21984 KB Output is correct
87 Correct 539 ms 22852 KB Output is correct
88 Correct 161 ms 11652 KB Output is correct
89 Correct 459 ms 22688 KB Output is correct
90 Correct 530 ms 22492 KB Output is correct
91 Correct 161 ms 11856 KB Output is correct
92 Correct 411 ms 21916 KB Output is correct
93 Correct 152 ms 11860 KB Output is correct
94 Correct 153 ms 11648 KB Output is correct
95 Correct 154 ms 11860 KB Output is correct
96 Correct 554 ms 22340 KB Output is correct
97 Correct 483 ms 20652 KB Output is correct
98 Correct 394 ms 13624 KB Output is correct
99 Correct 630 ms 22560 KB Output is correct
100 Correct 338 ms 18052 KB Output is correct