Submission #876174

# Submission time Handle Problem Language Result Execution time Memory
876174 2023-11-21T10:53:07 Z green_gold_dog Crossing (JOI21_crossing) C++17
100 / 100
424 ms 21564 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007, p = 239;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
T square(T a) {
        return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
        ll operator() (pair<ll, ll> p) const {
                return ((__int128)p.first * MOD + p.second) % INF64;
        }
};

map<pair<char, char>, char> m;

set<ll> can;

string make(string& s1, string& s2) {
        string ans(s1.size(), '.');
        for (ll i = 0; i < s1.size(); i++) {
                ans[i] = m[make_pair(s1[i], s2[i])];
        }
        return ans;
}

ll calc(string& s) {
        ll ans = 0, now = 1;
        for (auto i : s) {
                ans += (i - 'A') * now;
                ans %= MOD;
                now *= p;
                now %= MOD;
        }
        return ans;
}

void rec(string& s, string& s1, string& s2, string& s3) {
        can.insert(calc(s));
        s = make(s, s1);
        if (can.find(calc(s)) == can.end()) {
                rec(s, s1, s2, s3);
        }
        s = make(s, s1);
        s = make(s, s2);
        if (can.find(calc(s)) == can.end()) {
                rec(s, s1, s2, s3);
        }
        s = make(s, s2);
        s = make(s, s3);
        if (can.find(calc(s)) == can.end()) {
                rec(s, s1, s2, s3);
        }
        s = make(s, s3);
}

vector<ll> pp, ppref;

struct segment_tree {
        vector<ll> tree, m;
        ll size;
        segment_tree(ll n) {
                size = 1;
                while (size < n) {
                        size *= 2;
                }
                tree.resize(size * 2, 0);
                m.resize(size * 2, -1);
        }
        void set(ll v, ll l, ll r, ll x) {
                m[v] = x;
                tree[v] = x * ppref[r - l] % MOD;
        }
        void push(ll v, ll l, ll r) {
                if (m[v] == -1) {
                        return;
                }
                ll mid = (l + r) / 2;
                set(v * 2, l, mid, m[v]);
                set(v * 2 + 1, mid, r, m[v]);
                m[v] = -1;
        }
        ll get() {
                return tree[1];
        }
        void set(ll l, ll r, ll x) {
                set(1, 0, size, l, r, x);
        }
        void set(ll v, ll l, ll r, ll ql, ll qr, ll x) {
                if (ql <= l && r <= qr) {
                        set(v, l, r, x);
                        return;
                }
                if (qr <= l || r <= ql) {
                        return;
                }
                push(v, l, r);
                ll mid = (l + r) / 2;
                set(v * 2, l, mid, ql, qr, x);
                set(v * 2 + 1, mid, r, ql, qr, x);
                tree[v] = (tree[v * 2] + (tree[v * 2 + 1] * pp[mid - l])) % MOD;
        }
};

void solve() {
        m[make_pair('O', 'O')] = 'O';
        m[make_pair('O', 'I')] = 'J';
        m[make_pair('O', 'J')] = 'I';
        m[make_pair('I', 'O')] = 'J';
        m[make_pair('I', 'I')] = 'I';
        m[make_pair('I', 'J')] = 'O';
        m[make_pair('J', 'O')] = 'I';
        m[make_pair('J', 'I')] = 'O';
        m[make_pair('J', 'J')] = 'J';
        ll n;
        cin >> n;
        pp.push_back(1);
        while (pp.size() < n * 2) {
                pp.push_back(pp.back() * p % MOD);
        }
        ppref.push_back(0);
        for (auto i : pp) {
                ppref.push_back((ppref.back() + i) % MOD);
        }
        string s1, s2, s3;
        cin >> s1 >> s2 >> s3;
        string s = s1;
        rec(s, s1, s2, s3);
        segment_tree st(n);
        ll q;
        cin >> q;
        cin >> s;
        for (ll i = 0; i < n; i++) {
                st.set(i, i + 1, s[i] - 'A');
        }
        cout << (can.find(st.get()) == can.end() ? "No" : "Yes") << '\n';
        for (ll i = 0; i < q; i++) {
                ll l, r;
                char c;
                cin >> l >> r >> c;
                l--;
                st.set(l, r, c - 'A');
                cout << (can.find(st.get()) == can.end() ? "No" : "Yes") << '\n';
        }
}

int main() {
        if (IS_FILE) {
                freopen("", "r", stdin);
                freopen("", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t = 1;
        if (IS_TEST_CASES) {
                cin >> t;
        }
        for (ll i = 0; i < t; i++) {
                solve();
        }
}

Compilation message

Main.cpp: In function 'std::string make(std::string&, std::string&)':
Main.cpp:56:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (ll i = 0; i < s1.size(); i++) {
      |                        ~~^~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:153:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
  153 |         while (pp.size() < n * 2) {
      |                ~~~~~~~~~~^~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:184:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  184 |                 freopen("", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:185:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  185 |                 freopen("", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 53 ms 980 KB Output is correct
2 Correct 59 ms 952 KB Output is correct
3 Correct 57 ms 852 KB Output is correct
4 Correct 51 ms 1024 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 51 ms 976 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 61 ms 1192 KB Output is correct
9 Correct 55 ms 848 KB Output is correct
10 Correct 53 ms 856 KB Output is correct
11 Correct 57 ms 896 KB Output is correct
12 Correct 52 ms 944 KB Output is correct
13 Correct 53 ms 848 KB Output is correct
14 Correct 53 ms 852 KB Output is correct
15 Correct 55 ms 1048 KB Output is correct
16 Correct 52 ms 860 KB Output is correct
17 Correct 54 ms 1040 KB Output is correct
18 Correct 60 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 980 KB Output is correct
2 Correct 59 ms 952 KB Output is correct
3 Correct 57 ms 852 KB Output is correct
4 Correct 51 ms 1024 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 51 ms 976 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 61 ms 1192 KB Output is correct
9 Correct 55 ms 848 KB Output is correct
10 Correct 53 ms 856 KB Output is correct
11 Correct 57 ms 896 KB Output is correct
12 Correct 52 ms 944 KB Output is correct
13 Correct 53 ms 848 KB Output is correct
14 Correct 53 ms 852 KB Output is correct
15 Correct 55 ms 1048 KB Output is correct
16 Correct 52 ms 860 KB Output is correct
17 Correct 54 ms 1040 KB Output is correct
18 Correct 60 ms 960 KB Output is correct
19 Correct 214 ms 16736 KB Output is correct
20 Correct 218 ms 16696 KB Output is correct
21 Correct 188 ms 16184 KB Output is correct
22 Correct 158 ms 15416 KB Output is correct
23 Correct 85 ms 1872 KB Output is correct
24 Correct 86 ms 1828 KB Output is correct
25 Correct 173 ms 16700 KB Output is correct
26 Correct 182 ms 16628 KB Output is correct
27 Correct 183 ms 18492 KB Output is correct
28 Correct 179 ms 16648 KB Output is correct
29 Correct 179 ms 16444 KB Output is correct
30 Correct 91 ms 1876 KB Output is correct
31 Correct 194 ms 16896 KB Output is correct
32 Correct 173 ms 15772 KB Output is correct
33 Correct 86 ms 1848 KB Output is correct
34 Correct 181 ms 16696 KB Output is correct
35 Correct 147 ms 14712 KB Output is correct
36 Correct 86 ms 1872 KB Output is correct
37 Correct 85 ms 2012 KB Output is correct
38 Correct 197 ms 16644 KB Output is correct
39 Correct 155 ms 16700 KB Output is correct
40 Correct 140 ms 11496 KB Output is correct
41 Correct 226 ms 17132 KB Output is correct
42 Correct 125 ms 18520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 980 KB Output is correct
2 Correct 59 ms 952 KB Output is correct
3 Correct 57 ms 852 KB Output is correct
4 Correct 51 ms 1024 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 51 ms 976 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 61 ms 1192 KB Output is correct
9 Correct 55 ms 848 KB Output is correct
10 Correct 53 ms 856 KB Output is correct
11 Correct 57 ms 896 KB Output is correct
12 Correct 52 ms 944 KB Output is correct
13 Correct 53 ms 848 KB Output is correct
14 Correct 53 ms 852 KB Output is correct
15 Correct 55 ms 1048 KB Output is correct
16 Correct 52 ms 860 KB Output is correct
17 Correct 54 ms 1040 KB Output is correct
18 Correct 60 ms 960 KB Output is correct
19 Correct 58 ms 840 KB Output is correct
20 Correct 59 ms 924 KB Output is correct
21 Correct 61 ms 948 KB Output is correct
22 Correct 53 ms 936 KB Output is correct
23 Correct 54 ms 832 KB Output is correct
24 Correct 53 ms 992 KB Output is correct
25 Correct 55 ms 1004 KB Output is correct
26 Correct 56 ms 1020 KB Output is correct
27 Correct 55 ms 852 KB Output is correct
28 Correct 57 ms 848 KB Output is correct
29 Correct 55 ms 856 KB Output is correct
30 Correct 55 ms 1244 KB Output is correct
31 Correct 57 ms 836 KB Output is correct
32 Correct 55 ms 936 KB Output is correct
33 Correct 56 ms 1112 KB Output is correct
34 Correct 57 ms 848 KB Output is correct
35 Correct 55 ms 900 KB Output is correct
36 Correct 57 ms 852 KB Output is correct
37 Correct 56 ms 948 KB Output is correct
38 Correct 56 ms 988 KB Output is correct
39 Correct 55 ms 924 KB Output is correct
40 Correct 57 ms 1016 KB Output is correct
41 Correct 56 ms 856 KB Output is correct
42 Correct 57 ms 860 KB Output is correct
43 Correct 54 ms 936 KB Output is correct
44 Correct 56 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 980 KB Output is correct
2 Correct 59 ms 952 KB Output is correct
3 Correct 57 ms 852 KB Output is correct
4 Correct 51 ms 1024 KB Output is correct
5 Correct 52 ms 848 KB Output is correct
6 Correct 51 ms 976 KB Output is correct
7 Correct 52 ms 848 KB Output is correct
8 Correct 61 ms 1192 KB Output is correct
9 Correct 55 ms 848 KB Output is correct
10 Correct 53 ms 856 KB Output is correct
11 Correct 57 ms 896 KB Output is correct
12 Correct 52 ms 944 KB Output is correct
13 Correct 53 ms 848 KB Output is correct
14 Correct 53 ms 852 KB Output is correct
15 Correct 55 ms 1048 KB Output is correct
16 Correct 52 ms 860 KB Output is correct
17 Correct 54 ms 1040 KB Output is correct
18 Correct 60 ms 960 KB Output is correct
19 Correct 214 ms 16736 KB Output is correct
20 Correct 218 ms 16696 KB Output is correct
21 Correct 188 ms 16184 KB Output is correct
22 Correct 158 ms 15416 KB Output is correct
23 Correct 85 ms 1872 KB Output is correct
24 Correct 86 ms 1828 KB Output is correct
25 Correct 173 ms 16700 KB Output is correct
26 Correct 182 ms 16628 KB Output is correct
27 Correct 183 ms 18492 KB Output is correct
28 Correct 179 ms 16648 KB Output is correct
29 Correct 179 ms 16444 KB Output is correct
30 Correct 91 ms 1876 KB Output is correct
31 Correct 194 ms 16896 KB Output is correct
32 Correct 173 ms 15772 KB Output is correct
33 Correct 86 ms 1848 KB Output is correct
34 Correct 181 ms 16696 KB Output is correct
35 Correct 147 ms 14712 KB Output is correct
36 Correct 86 ms 1872 KB Output is correct
37 Correct 85 ms 2012 KB Output is correct
38 Correct 197 ms 16644 KB Output is correct
39 Correct 155 ms 16700 KB Output is correct
40 Correct 140 ms 11496 KB Output is correct
41 Correct 226 ms 17132 KB Output is correct
42 Correct 125 ms 18520 KB Output is correct
43 Correct 58 ms 840 KB Output is correct
44 Correct 59 ms 924 KB Output is correct
45 Correct 61 ms 948 KB Output is correct
46 Correct 53 ms 936 KB Output is correct
47 Correct 54 ms 832 KB Output is correct
48 Correct 53 ms 992 KB Output is correct
49 Correct 55 ms 1004 KB Output is correct
50 Correct 56 ms 1020 KB Output is correct
51 Correct 55 ms 852 KB Output is correct
52 Correct 57 ms 848 KB Output is correct
53 Correct 55 ms 856 KB Output is correct
54 Correct 55 ms 1244 KB Output is correct
55 Correct 57 ms 836 KB Output is correct
56 Correct 55 ms 936 KB Output is correct
57 Correct 56 ms 1112 KB Output is correct
58 Correct 57 ms 848 KB Output is correct
59 Correct 55 ms 900 KB Output is correct
60 Correct 57 ms 852 KB Output is correct
61 Correct 56 ms 948 KB Output is correct
62 Correct 56 ms 988 KB Output is correct
63 Correct 55 ms 924 KB Output is correct
64 Correct 57 ms 1016 KB Output is correct
65 Correct 56 ms 856 KB Output is correct
66 Correct 57 ms 860 KB Output is correct
67 Correct 54 ms 936 KB Output is correct
68 Correct 56 ms 848 KB Output is correct
69 Correct 346 ms 15420 KB Output is correct
70 Correct 424 ms 16828 KB Output is correct
71 Correct 91 ms 1916 KB Output is correct
72 Correct 90 ms 1964 KB Output is correct
73 Correct 88 ms 1876 KB Output is correct
74 Correct 206 ms 17464 KB Output is correct
75 Correct 90 ms 1876 KB Output is correct
76 Correct 230 ms 16700 KB Output is correct
77 Correct 202 ms 16820 KB Output is correct
78 Correct 90 ms 1944 KB Output is correct
79 Correct 90 ms 2008 KB Output is correct
80 Correct 288 ms 17532 KB Output is correct
81 Correct 97 ms 1888 KB Output is correct
82 Correct 379 ms 16704 KB Output is correct
83 Correct 357 ms 17536 KB Output is correct
84 Correct 113 ms 1876 KB Output is correct
85 Correct 97 ms 1808 KB Output is correct
86 Correct 232 ms 14648 KB Output is correct
87 Correct 271 ms 16704 KB Output is correct
88 Correct 100 ms 1936 KB Output is correct
89 Correct 246 ms 15892 KB Output is correct
90 Correct 271 ms 16608 KB Output is correct
91 Correct 102 ms 4180 KB Output is correct
92 Correct 296 ms 18412 KB Output is correct
93 Correct 98 ms 4296 KB Output is correct
94 Correct 99 ms 4176 KB Output is correct
95 Correct 99 ms 4176 KB Output is correct
96 Correct 195 ms 21564 KB Output is correct
97 Correct 299 ms 21360 KB Output is correct
98 Correct 264 ms 14196 KB Output is correct
99 Correct 388 ms 20448 KB Output is correct
100 Correct 299 ms 19840 KB Output is correct