Submission #1035107

# Submission time Handle Problem Language Result Execution time Memory
1035107 2024-07-26T04:39:15 Z CommandMaster Crossing (JOI21_crossing) C++17
100 / 100
209 ms 19600 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>

inline int ser(char c) {
    return c == 'J' ? 1 : c == 'O' ? 2 : 3;
}

string comb(string&a, string&b) {
    string ans = a;
    for (int i = 0; i < b.size(); i++) {
        if (ans[i] != b[i]) ans[i] ^= 76 ^ b[i]; // ('J' ^ 'O' ^ 'I')
    }
    return ans;
}

const ll maxN = 2e5+5;
const ll MOD = 1e9+7;
const ll P = 5;
const ll invP1 = 250000002;

ll powP[maxN];

ll get_hash(string s) {
    ll hash = 0;
    for (int i = 0; i < s.size(); i++) {
        hash += powP[i] * ser(s[i]);
        hash %= MOD;
    }
    return hash;
}

inline ll cohash(ll val, int sz) {
    return val * (powP[sz] - 1) * invP1 % MOD;
}

struct SEG {
    vll toset;
    vll hash;

    void make(ll n) {
        toset.resize(n*4);
        hash.resize(n*4);
    }

    void push(ll v, ll tl, ll tm, ll tr) {
        if (toset[v]) {
            toset[v*2] = toset[v];
            hash[v*2] = cohash(toset[v], tm-tl+1);
            toset[v*2+1] = toset[v];
            hash[v*2+1] = cohash(toset[v], tr-tm);
            toset[v] = 0;
        }
    }

    void pull(ll v, ll tl, ll tm, ll tr) {
        hash[v] = (hash[v*2] + powP[tm - tl + 1] * hash[v*2+1]) % MOD;
    }

    void set(ll v, ll tl, ll tr, ll l, ll r, ll val) {
        if (l > r) return;
        if (tl == l && tr == r) {
            toset[v] = val;
            hash[v] = cohash(val, tr-tl+1);
            return;
        }
        ll tm = (tl + tr) / 2;
        push(v, tl, tm, tr);
        set(v*2, tl, tm, l, min(r, tm), val);
        set(v*2+1, tm+1, tr, max(l, tm+1), r, val);
        pull(v, tl, tm, tr);
    }

    void get(ll v, ll tl, ll tr, ll ind) {
        if (tl == tr) {
            cout << ind << ": " << hash[v] << '\n';
            return;
        }
        ll tm = (tl + tr) / 2;
        push(v, tl, tm, tr);
        if (ind <= tm) get(v*2, tl, tm, ind);
        else get(v*2+1, tm+1, tr, ind);
    }
};

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0);
    ll n;
    cin >> n;
    powP[0] = 1;
    for (int i = 1; i <= n; i++) powP[i] = powP[i-1] * P % MOD;
    unordered_set<ll> hashes;
    {
        string s1, s2, s3;
        cin >> s1 >> s2 >> s3;
        hashes.insert(get_hash(s1));
        hashes.insert(get_hash(s2));
        hashes.insert(get_hash(s3));
        string s12 = comb(s1, s2);
        string s13 = comb(s1, s3);
        string s23 = comb(s2, s3);
        hashes.insert(get_hash(s12));
        hashes.insert(get_hash(s23));
        hashes.insert(get_hash(s13));
        hashes.insert(get_hash(comb(s12, s3)));
        hashes.insert(get_hash(comb(s23, s1)));
        hashes.insert(get_hash(comb(s13, s2)));
    }
    // cout << "hash: " << h << endl;
    ll q;
    cin >> q;
    SEG seg;
    seg.make(n);
    for (ll i =0 ; i < n; i++) {
        char c;
        cin >> c;
        seg.set(1, 0, n-1, i, i, ser(c));
    }
    // for (int i = 0; i < n; i++) seg.get(1, 0, n-1, i);
    if (hashes.count(seg.hash[1])) cout << "Yes\n";
    else cout << "No\n";
    while (q--) {
        ll l, r;
        char c;
        cin >> l >> r >> c;
        l--, r--;
        seg.set(1, 0, n-1, l, r, ser(c));
        // for (int i = 0; i < n; i++) seg.get(1, 0, n-1, i);
        if (hashes.count(seg.hash[1])) cout << "Yes\n";
        else cout << "No\n";
    }
}

Compilation message

Main.cpp: In function 'std::string comb(std::string&, std::string&)':
Main.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for (int i = 0; i < b.size(); i++) {
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'long long int get_hash(std::string)':
Main.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2320 KB Output is correct
2 Correct 52 ms 2392 KB Output is correct
3 Correct 51 ms 2388 KB Output is correct
4 Correct 42 ms 2384 KB Output is correct
5 Correct 42 ms 2380 KB Output is correct
6 Correct 42 ms 2384 KB Output is correct
7 Correct 48 ms 2384 KB Output is correct
8 Correct 46 ms 2388 KB Output is correct
9 Correct 44 ms 2384 KB Output is correct
10 Correct 48 ms 2392 KB Output is correct
11 Correct 45 ms 2580 KB Output is correct
12 Correct 49 ms 2384 KB Output is correct
13 Correct 45 ms 2384 KB Output is correct
14 Correct 44 ms 2388 KB Output is correct
15 Correct 45 ms 2516 KB Output is correct
16 Correct 44 ms 2388 KB Output is correct
17 Correct 44 ms 2460 KB Output is correct
18 Correct 46 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2320 KB Output is correct
2 Correct 52 ms 2392 KB Output is correct
3 Correct 51 ms 2388 KB Output is correct
4 Correct 42 ms 2384 KB Output is correct
5 Correct 42 ms 2380 KB Output is correct
6 Correct 42 ms 2384 KB Output is correct
7 Correct 48 ms 2384 KB Output is correct
8 Correct 46 ms 2388 KB Output is correct
9 Correct 44 ms 2384 KB Output is correct
10 Correct 48 ms 2392 KB Output is correct
11 Correct 45 ms 2580 KB Output is correct
12 Correct 49 ms 2384 KB Output is correct
13 Correct 45 ms 2384 KB Output is correct
14 Correct 44 ms 2388 KB Output is correct
15 Correct 45 ms 2516 KB Output is correct
16 Correct 44 ms 2388 KB Output is correct
17 Correct 44 ms 2460 KB Output is correct
18 Correct 46 ms 2388 KB Output is correct
19 Correct 181 ms 18764 KB Output is correct
20 Correct 209 ms 18748 KB Output is correct
21 Correct 145 ms 17804 KB Output is correct
22 Correct 130 ms 16180 KB Output is correct
23 Correct 73 ms 4072 KB Output is correct
24 Correct 73 ms 4148 KB Output is correct
25 Correct 149 ms 18884 KB Output is correct
26 Correct 150 ms 18892 KB Output is correct
27 Correct 162 ms 18796 KB Output is correct
28 Correct 170 ms 18764 KB Output is correct
29 Correct 160 ms 18584 KB Output is correct
30 Correct 84 ms 4180 KB Output is correct
31 Correct 162 ms 18764 KB Output is correct
32 Correct 150 ms 17448 KB Output is correct
33 Correct 74 ms 4180 KB Output is correct
34 Correct 161 ms 18768 KB Output is correct
35 Correct 128 ms 14864 KB Output is correct
36 Correct 80 ms 4108 KB Output is correct
37 Correct 73 ms 3952 KB Output is correct
38 Correct 171 ms 18508 KB Output is correct
39 Correct 132 ms 18764 KB Output is correct
40 Correct 125 ms 13776 KB Output is correct
41 Correct 194 ms 19024 KB Output is correct
42 Correct 80 ms 18340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2320 KB Output is correct
2 Correct 52 ms 2392 KB Output is correct
3 Correct 51 ms 2388 KB Output is correct
4 Correct 42 ms 2384 KB Output is correct
5 Correct 42 ms 2380 KB Output is correct
6 Correct 42 ms 2384 KB Output is correct
7 Correct 48 ms 2384 KB Output is correct
8 Correct 46 ms 2388 KB Output is correct
9 Correct 44 ms 2384 KB Output is correct
10 Correct 48 ms 2392 KB Output is correct
11 Correct 45 ms 2580 KB Output is correct
12 Correct 49 ms 2384 KB Output is correct
13 Correct 45 ms 2384 KB Output is correct
14 Correct 44 ms 2388 KB Output is correct
15 Correct 45 ms 2516 KB Output is correct
16 Correct 44 ms 2388 KB Output is correct
17 Correct 44 ms 2460 KB Output is correct
18 Correct 46 ms 2388 KB Output is correct
19 Correct 51 ms 2384 KB Output is correct
20 Correct 52 ms 2452 KB Output is correct
21 Correct 44 ms 2576 KB Output is correct
22 Correct 40 ms 2376 KB Output is correct
23 Correct 47 ms 2592 KB Output is correct
24 Correct 44 ms 2384 KB Output is correct
25 Correct 45 ms 2468 KB Output is correct
26 Correct 43 ms 2292 KB Output is correct
27 Correct 45 ms 2388 KB Output is correct
28 Correct 42 ms 2396 KB Output is correct
29 Correct 45 ms 2388 KB Output is correct
30 Correct 40 ms 2412 KB Output is correct
31 Correct 48 ms 2388 KB Output is correct
32 Correct 46 ms 2380 KB Output is correct
33 Correct 51 ms 2420 KB Output is correct
34 Correct 49 ms 2388 KB Output is correct
35 Correct 47 ms 2468 KB Output is correct
36 Correct 48 ms 2388 KB Output is correct
37 Correct 47 ms 2388 KB Output is correct
38 Correct 48 ms 2440 KB Output is correct
39 Correct 48 ms 2372 KB Output is correct
40 Correct 48 ms 2388 KB Output is correct
41 Correct 47 ms 2560 KB Output is correct
42 Correct 47 ms 2376 KB Output is correct
43 Correct 45 ms 2388 KB Output is correct
44 Correct 49 ms 2388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 2320 KB Output is correct
2 Correct 52 ms 2392 KB Output is correct
3 Correct 51 ms 2388 KB Output is correct
4 Correct 42 ms 2384 KB Output is correct
5 Correct 42 ms 2380 KB Output is correct
6 Correct 42 ms 2384 KB Output is correct
7 Correct 48 ms 2384 KB Output is correct
8 Correct 46 ms 2388 KB Output is correct
9 Correct 44 ms 2384 KB Output is correct
10 Correct 48 ms 2392 KB Output is correct
11 Correct 45 ms 2580 KB Output is correct
12 Correct 49 ms 2384 KB Output is correct
13 Correct 45 ms 2384 KB Output is correct
14 Correct 44 ms 2388 KB Output is correct
15 Correct 45 ms 2516 KB Output is correct
16 Correct 44 ms 2388 KB Output is correct
17 Correct 44 ms 2460 KB Output is correct
18 Correct 46 ms 2388 KB Output is correct
19 Correct 181 ms 18764 KB Output is correct
20 Correct 209 ms 18748 KB Output is correct
21 Correct 145 ms 17804 KB Output is correct
22 Correct 130 ms 16180 KB Output is correct
23 Correct 73 ms 4072 KB Output is correct
24 Correct 73 ms 4148 KB Output is correct
25 Correct 149 ms 18884 KB Output is correct
26 Correct 150 ms 18892 KB Output is correct
27 Correct 162 ms 18796 KB Output is correct
28 Correct 170 ms 18764 KB Output is correct
29 Correct 160 ms 18584 KB Output is correct
30 Correct 84 ms 4180 KB Output is correct
31 Correct 162 ms 18764 KB Output is correct
32 Correct 150 ms 17448 KB Output is correct
33 Correct 74 ms 4180 KB Output is correct
34 Correct 161 ms 18768 KB Output is correct
35 Correct 128 ms 14864 KB Output is correct
36 Correct 80 ms 4108 KB Output is correct
37 Correct 73 ms 3952 KB Output is correct
38 Correct 171 ms 18508 KB Output is correct
39 Correct 132 ms 18764 KB Output is correct
40 Correct 125 ms 13776 KB Output is correct
41 Correct 194 ms 19024 KB Output is correct
42 Correct 80 ms 18340 KB Output is correct
43 Correct 51 ms 2384 KB Output is correct
44 Correct 52 ms 2452 KB Output is correct
45 Correct 44 ms 2576 KB Output is correct
46 Correct 40 ms 2376 KB Output is correct
47 Correct 47 ms 2592 KB Output is correct
48 Correct 44 ms 2384 KB Output is correct
49 Correct 45 ms 2468 KB Output is correct
50 Correct 43 ms 2292 KB Output is correct
51 Correct 45 ms 2388 KB Output is correct
52 Correct 42 ms 2396 KB Output is correct
53 Correct 45 ms 2388 KB Output is correct
54 Correct 40 ms 2412 KB Output is correct
55 Correct 48 ms 2388 KB Output is correct
56 Correct 46 ms 2380 KB Output is correct
57 Correct 51 ms 2420 KB Output is correct
58 Correct 49 ms 2388 KB Output is correct
59 Correct 47 ms 2468 KB Output is correct
60 Correct 48 ms 2388 KB Output is correct
61 Correct 47 ms 2388 KB Output is correct
62 Correct 48 ms 2440 KB Output is correct
63 Correct 48 ms 2372 KB Output is correct
64 Correct 48 ms 2388 KB Output is correct
65 Correct 47 ms 2560 KB Output is correct
66 Correct 47 ms 2376 KB Output is correct
67 Correct 45 ms 2388 KB Output is correct
68 Correct 49 ms 2388 KB Output is correct
69 Correct 147 ms 16496 KB Output is correct
70 Correct 187 ms 19412 KB Output is correct
71 Correct 75 ms 4072 KB Output is correct
72 Correct 78 ms 4184 KB Output is correct
73 Correct 74 ms 4180 KB Output is correct
74 Correct 130 ms 16412 KB Output is correct
75 Correct 77 ms 4176 KB Output is correct
76 Correct 150 ms 19144 KB Output is correct
77 Correct 128 ms 16508 KB Output is correct
78 Correct 85 ms 4164 KB Output is correct
79 Correct 74 ms 4064 KB Output is correct
80 Correct 125 ms 14640 KB Output is correct
81 Correct 78 ms 3988 KB Output is correct
82 Correct 147 ms 19404 KB Output is correct
83 Correct 134 ms 18032 KB Output is correct
84 Correct 74 ms 4180 KB Output is correct
85 Correct 74 ms 4176 KB Output is correct
86 Correct 134 ms 15568 KB Output is correct
87 Correct 169 ms 19416 KB Output is correct
88 Correct 79 ms 4176 KB Output is correct
89 Correct 131 ms 17400 KB Output is correct
90 Correct 153 ms 19532 KB Output is correct
91 Correct 80 ms 4180 KB Output is correct
92 Correct 121 ms 15152 KB Output is correct
93 Correct 75 ms 4024 KB Output is correct
94 Correct 71 ms 4104 KB Output is correct
95 Correct 79 ms 4176 KB Output is correct
96 Correct 157 ms 18752 KB Output is correct
97 Correct 119 ms 19564 KB Output is correct
98 Correct 126 ms 13780 KB Output is correct
99 Correct 182 ms 19600 KB Output is correct
100 Correct 80 ms 18908 KB Output is correct