Submission #420339

# Submission time Handle Problem Language Result Execution time Memory
420339 2021-06-08T09:55:27 Z egorlifar Crossing (JOI21_crossing) C++17
100 / 100
411 ms 14588 KB
/*
KAMUI!
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓▓▓██████████▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓█████▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓███▓▒▒░▒▒▒▒▒░░░▒▒▒▓▓███▓▓▓▓▓▓▓ 
▓▓▓▓▓▓█▓▒▒▒▓▓████████▓▒▒░▒▒▒▓██▓▓▓▓▓▓
▓▓▓▓██▒▓████████████████▓░▒▒▒▒▓██▓▓▓▓ 
▓▓▓██▓███████▓▒░░░░░░░▒███▒░░▒▒▒██▓▓▓ 
▓▓█████████▓░░░░░░░░░░░░░██▓▓██████▓▓ 
▓▓█▒▓███████████▓▓▒▒▒▓▓██████████▓█▓▓ 
▓██▒▒▒███████████████████████████▓▓█▓ 
▓█▓▒▒░░████████▒░░░░▓███████████▓░▒█▓ 
▓█▒▒▒░██░▒████░░░░░░█████░░████▓░░▒█▓ 
▓█▒▒▒▒██░░░██▓░░░░░░░███▒░░████▒▒▒▒█▓ 
▓█▓▒▒▒██▒░░░▓█▓░░░░░▓█▓░░░▓███▓▒▒░▓█▓ 
▓█▓▒▒▒███░░░░████████▓░░░░░████▒▒▒▓█▓ 
▓▓█▒▒░▓███░░░▒███████▒░░░▒███▓▒▒▒▒█▓▓ 
▓▓██▒▒░████▒░░███████░░░▓███▓░▒▒▒██▓▓ 
▓▓▓██▒▒▒█████▓░░██████▒▓███▓▒░▒▒██▓▓▓ 
▓▓▓▓██▓▒░▓██████████████▓▒░▒▒▒▓██▓▓▓▓ 
▓▓▓▓▓▓██▓░▒▓█████████▒░░▒▒▒▒▓██▓▓▓▓▓▓ 
▓▓▓▓▓▓▓███▓▒▒▓██████▓░▒▒▒▓▓███▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓███▓▓▓████▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓▓▓███████████▓▓▓▓▓▓▓▓▓▓▓▓▓ 
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double; 
const string FILENAME = "input";
const int Mod = 998244353;
const int P = 424243;


int sum(int a, int b) {
    return (a + b >= Mod ? a + b - Mod: a + b);
}


int mul(int a, int b) {
    return ((ll)a * b) % Mod;
}


int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}


int inv(int a) {
    return powm(a, Mod - 2);
}
 

const int MAXN = 200228;


int n;
string s[3];
int q;
string t0;
int p[MAXN];


struct node
{
    char mod = 0;
    int hsh = 0;
    int len = 0;
};


node operator +(const node& a, const node& b) {
    node c;
    c.len = a.len + b.len;
    c.hsh = sum(mul(a.hsh, p[b.len]), b.hsh);
    return c;
}


int h[3][MAXN];


struct rmq
{
    vector<node> d;
    int ss = 1;
    void init(int n, string t0) {
        ss = 1;
        while (ss < n) {
            ss <<= 1;
        }
        d.resize(2 * ss);
        for (int i = 0; i < n; i++) {
            d[ss + i].len = 1;
            d[ss + i].hsh = t0[i];
        }
        for (int i = ss - 1; i >= 1; i--) {
            d[i] = d[i * 2] + d[i * 2 + 1];
        }
    }
    void push(int v) {
        if (d[v].mod != 0) {
            d[v].hsh = h[(d[v].mod == 'J' ? 0: (d[v].mod == 'O' ? 1: 2))][d[v].len];
            if (v < ss) {
                d[v * 2].mod = d[v].mod;
                d[v * 2 + 1].mod = d[v].mod;
            }
            d[v].mod = 0;
        }
    }
    void add(int v, int vl, int vr, int l, int r, char c) {
        if (vl > r || vr < l) {
            push(v);
            return;
        }
        if (l <= vl && vr <= r) {
            d[v].mod = c;
            push(v);
            return;
        } 
        push(v);
        add(v * 2, vl, (vl + vr) / 2, l, r, c);
        add(v * 2 + 1, (vl + vr) / 2 + 1, vr, l, r, c);
        d[v] = d[v * 2] + d[v * 2 + 1];
    }
};


void solve() {
    cin >> n;
    p[0] = 1;
    for (int i = 1; i <= n; i++) {
        p[i] = mul(p[i - 1], P);
    }
    char c[3] = {'J', 'O', 'I'};
    for (int t = 0; t < 3; t++) {
        for (int i = 1; i <= n; i++) {
            h[t][i] = sum(mul(h[t][i - 1], P), c[t]); 
        }
    }
    for (int i = 0; i < 3; i++) {
        cin >> s[i];
    }    
    cin >> q;
    cin >> t0;
    vector<string> goods;
    for (int mask = 1; mask <= 7; mask++) {
        vector<int> st;
        for (int i = 0; i < 3; i++) {
            if (mask & (1 << i)) {
                st.pb(i);
            }
        }
        do {
            string cur;
            for (auto i: st) {
                if (cur.empty()) {
                    cur = s[i];
                } else {
                    for (int j = 0; j < n; j++) {
                        if (cur[j] == s[i][j]) {
                            continue;
                        } 
                        cur[j] = cur[j] ^ s[i][j] ^ 'J' ^ 'O' ^ 'I';
                    }
                }
            }
            goods.pb(cur);
        } while (next_permutation(all(st)));
    }
    bool ok = false;
    for (auto x: goods) {
        if (x == t0) {
            ok = true;
        }
    }
    if (ok) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    rmq kek;
    kek.init(n, t0);
    vector<int> goodhs;
    for (auto x: goods) {
        int cur = 0;
        for (auto y: x) {
            cur = sum(mul(cur, P), y);
        }  
        goodhs.pb(cur);
    }
    for (int it = 0; it < q; it++) {
        int l, r;
        char c;
        cin >> l >> r >> c;
        kek.add(1, 1, kek.ss, l, r, c);
        kek.push(1);
        bool ok = false;
        for (auto x: goodhs) {
            if (x == kek.d[1].hsh) {
                ok = true;
            }
        }
        if (ok) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }      
}


int main() {
    //12:15
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   // read(FILENAME);
    int t;
    t = 1;
  //  cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 88 ms 836 KB Output is correct
2 Correct 97 ms 908 KB Output is correct
3 Correct 99 ms 892 KB Output is correct
4 Correct 86 ms 836 KB Output is correct
5 Correct 81 ms 876 KB Output is correct
6 Correct 81 ms 796 KB Output is correct
7 Correct 89 ms 932 KB Output is correct
8 Correct 96 ms 904 KB Output is correct
9 Correct 88 ms 904 KB Output is correct
10 Correct 87 ms 824 KB Output is correct
11 Correct 87 ms 888 KB Output is correct
12 Correct 89 ms 836 KB Output is correct
13 Correct 94 ms 836 KB Output is correct
14 Correct 85 ms 908 KB Output is correct
15 Correct 92 ms 916 KB Output is correct
16 Correct 88 ms 880 KB Output is correct
17 Correct 89 ms 916 KB Output is correct
18 Correct 92 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 836 KB Output is correct
2 Correct 97 ms 908 KB Output is correct
3 Correct 99 ms 892 KB Output is correct
4 Correct 86 ms 836 KB Output is correct
5 Correct 81 ms 876 KB Output is correct
6 Correct 81 ms 796 KB Output is correct
7 Correct 89 ms 932 KB Output is correct
8 Correct 96 ms 904 KB Output is correct
9 Correct 88 ms 904 KB Output is correct
10 Correct 87 ms 824 KB Output is correct
11 Correct 87 ms 888 KB Output is correct
12 Correct 89 ms 836 KB Output is correct
13 Correct 94 ms 836 KB Output is correct
14 Correct 85 ms 908 KB Output is correct
15 Correct 92 ms 916 KB Output is correct
16 Correct 88 ms 880 KB Output is correct
17 Correct 89 ms 916 KB Output is correct
18 Correct 92 ms 832 KB Output is correct
19 Correct 346 ms 14276 KB Output is correct
20 Correct 350 ms 14276 KB Output is correct
21 Correct 214 ms 13828 KB Output is correct
22 Correct 232 ms 13132 KB Output is correct
23 Correct 138 ms 1724 KB Output is correct
24 Correct 137 ms 1692 KB Output is correct
25 Correct 235 ms 14268 KB Output is correct
26 Correct 251 ms 14236 KB Output is correct
27 Correct 258 ms 14288 KB Output is correct
28 Correct 255 ms 14288 KB Output is correct
29 Correct 246 ms 14064 KB Output is correct
30 Correct 150 ms 1660 KB Output is correct
31 Correct 271 ms 14292 KB Output is correct
32 Correct 262 ms 13620 KB Output is correct
33 Correct 142 ms 1612 KB Output is correct
34 Correct 259 ms 14220 KB Output is correct
35 Correct 203 ms 12372 KB Output is correct
36 Correct 136 ms 1632 KB Output is correct
37 Correct 138 ms 1604 KB Output is correct
38 Correct 290 ms 14272 KB Output is correct
39 Correct 187 ms 14252 KB Output is correct
40 Correct 216 ms 8720 KB Output is correct
41 Correct 346 ms 14588 KB Output is correct
42 Correct 144 ms 14396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 836 KB Output is correct
2 Correct 97 ms 908 KB Output is correct
3 Correct 99 ms 892 KB Output is correct
4 Correct 86 ms 836 KB Output is correct
5 Correct 81 ms 876 KB Output is correct
6 Correct 81 ms 796 KB Output is correct
7 Correct 89 ms 932 KB Output is correct
8 Correct 96 ms 904 KB Output is correct
9 Correct 88 ms 904 KB Output is correct
10 Correct 87 ms 824 KB Output is correct
11 Correct 87 ms 888 KB Output is correct
12 Correct 89 ms 836 KB Output is correct
13 Correct 94 ms 836 KB Output is correct
14 Correct 85 ms 908 KB Output is correct
15 Correct 92 ms 916 KB Output is correct
16 Correct 88 ms 880 KB Output is correct
17 Correct 89 ms 916 KB Output is correct
18 Correct 92 ms 832 KB Output is correct
19 Correct 98 ms 904 KB Output is correct
20 Correct 99 ms 940 KB Output is correct
21 Correct 89 ms 872 KB Output is correct
22 Correct 89 ms 872 KB Output is correct
23 Correct 87 ms 908 KB Output is correct
24 Correct 82 ms 836 KB Output is correct
25 Correct 90 ms 860 KB Output is correct
26 Correct 85 ms 880 KB Output is correct
27 Correct 93 ms 964 KB Output is correct
28 Correct 78 ms 792 KB Output is correct
29 Correct 87 ms 820 KB Output is correct
30 Correct 79 ms 860 KB Output is correct
31 Correct 87 ms 964 KB Output is correct
32 Correct 86 ms 808 KB Output is correct
33 Correct 93 ms 836 KB Output is correct
34 Correct 86 ms 852 KB Output is correct
35 Correct 85 ms 836 KB Output is correct
36 Correct 101 ms 832 KB Output is correct
37 Correct 86 ms 840 KB Output is correct
38 Correct 87 ms 932 KB Output is correct
39 Correct 91 ms 964 KB Output is correct
40 Correct 89 ms 888 KB Output is correct
41 Correct 87 ms 1004 KB Output is correct
42 Correct 86 ms 836 KB Output is correct
43 Correct 83 ms 824 KB Output is correct
44 Correct 88 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 836 KB Output is correct
2 Correct 97 ms 908 KB Output is correct
3 Correct 99 ms 892 KB Output is correct
4 Correct 86 ms 836 KB Output is correct
5 Correct 81 ms 876 KB Output is correct
6 Correct 81 ms 796 KB Output is correct
7 Correct 89 ms 932 KB Output is correct
8 Correct 96 ms 904 KB Output is correct
9 Correct 88 ms 904 KB Output is correct
10 Correct 87 ms 824 KB Output is correct
11 Correct 87 ms 888 KB Output is correct
12 Correct 89 ms 836 KB Output is correct
13 Correct 94 ms 836 KB Output is correct
14 Correct 85 ms 908 KB Output is correct
15 Correct 92 ms 916 KB Output is correct
16 Correct 88 ms 880 KB Output is correct
17 Correct 89 ms 916 KB Output is correct
18 Correct 92 ms 832 KB Output is correct
19 Correct 346 ms 14276 KB Output is correct
20 Correct 350 ms 14276 KB Output is correct
21 Correct 214 ms 13828 KB Output is correct
22 Correct 232 ms 13132 KB Output is correct
23 Correct 138 ms 1724 KB Output is correct
24 Correct 137 ms 1692 KB Output is correct
25 Correct 235 ms 14268 KB Output is correct
26 Correct 251 ms 14236 KB Output is correct
27 Correct 258 ms 14288 KB Output is correct
28 Correct 255 ms 14288 KB Output is correct
29 Correct 246 ms 14064 KB Output is correct
30 Correct 150 ms 1660 KB Output is correct
31 Correct 271 ms 14292 KB Output is correct
32 Correct 262 ms 13620 KB Output is correct
33 Correct 142 ms 1612 KB Output is correct
34 Correct 259 ms 14220 KB Output is correct
35 Correct 203 ms 12372 KB Output is correct
36 Correct 136 ms 1632 KB Output is correct
37 Correct 138 ms 1604 KB Output is correct
38 Correct 290 ms 14272 KB Output is correct
39 Correct 187 ms 14252 KB Output is correct
40 Correct 216 ms 8720 KB Output is correct
41 Correct 346 ms 14588 KB Output is correct
42 Correct 144 ms 14396 KB Output is correct
43 Correct 98 ms 904 KB Output is correct
44 Correct 99 ms 940 KB Output is correct
45 Correct 89 ms 872 KB Output is correct
46 Correct 89 ms 872 KB Output is correct
47 Correct 87 ms 908 KB Output is correct
48 Correct 82 ms 836 KB Output is correct
49 Correct 90 ms 860 KB Output is correct
50 Correct 85 ms 880 KB Output is correct
51 Correct 93 ms 964 KB Output is correct
52 Correct 78 ms 792 KB Output is correct
53 Correct 87 ms 820 KB Output is correct
54 Correct 79 ms 860 KB Output is correct
55 Correct 87 ms 964 KB Output is correct
56 Correct 86 ms 808 KB Output is correct
57 Correct 93 ms 836 KB Output is correct
58 Correct 86 ms 852 KB Output is correct
59 Correct 85 ms 836 KB Output is correct
60 Correct 101 ms 832 KB Output is correct
61 Correct 86 ms 840 KB Output is correct
62 Correct 87 ms 932 KB Output is correct
63 Correct 91 ms 964 KB Output is correct
64 Correct 89 ms 888 KB Output is correct
65 Correct 87 ms 1004 KB Output is correct
66 Correct 86 ms 836 KB Output is correct
67 Correct 83 ms 824 KB Output is correct
68 Correct 88 ms 856 KB Output is correct
69 Correct 296 ms 13068 KB Output is correct
70 Correct 326 ms 14320 KB Output is correct
71 Correct 142 ms 1804 KB Output is correct
72 Correct 144 ms 1688 KB Output is correct
73 Correct 148 ms 1732 KB Output is correct
74 Correct 226 ms 13140 KB Output is correct
75 Correct 137 ms 1576 KB Output is correct
76 Correct 244 ms 14232 KB Output is correct
77 Correct 227 ms 13052 KB Output is correct
78 Correct 143 ms 1680 KB Output is correct
79 Correct 143 ms 1688 KB Output is correct
80 Correct 209 ms 12120 KB Output is correct
81 Correct 139 ms 1656 KB Output is correct
82 Correct 267 ms 14240 KB Output is correct
83 Correct 261 ms 13884 KB Output is correct
84 Correct 137 ms 1648 KB Output is correct
85 Correct 162 ms 1684 KB Output is correct
86 Correct 280 ms 12540 KB Output is correct
87 Correct 300 ms 14292 KB Output is correct
88 Correct 152 ms 1656 KB Output is correct
89 Correct 261 ms 13432 KB Output is correct
90 Correct 279 ms 14224 KB Output is correct
91 Correct 154 ms 1656 KB Output is correct
92 Correct 228 ms 12448 KB Output is correct
93 Correct 145 ms 1608 KB Output is correct
94 Correct 147 ms 1656 KB Output is correct
95 Correct 145 ms 1576 KB Output is correct
96 Correct 289 ms 14300 KB Output is correct
97 Correct 183 ms 14248 KB Output is correct
98 Correct 239 ms 8712 KB Output is correct
99 Correct 411 ms 14504 KB Output is correct
100 Correct 159 ms 14448 KB Output is correct