답안 #526625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526625 2022-02-15T18:17:27 Z jalsol Crossing (JOI21_crossing) C++11
49 / 100
211 ms 14748 KB
#include <bits/stdc++.h>

using namespace std;

#define Task ""

struct __Init__ {
    __Init__() {
        cin.tie(nullptr)->sync_with_stdio(false);
        if (fopen(Task".inp", "r")) {
            freopen(Task".inp", "r", stdin);
            freopen(Task".out", "w", stdout); }
    }
} __init__;

using ll = long long;

#ifdef LOCAL
#define debug(x) cerr << "[" #x " = " << x << "]\n";
#else
#define debug(...)
#endif // LOCAL

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)

template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

constexpr int maxN = 2e5 + 5;
constexpr int base = 5;

struct mint {
    int v;
    static constexpr int mod = 1e9 + 123;

    mint() : v() {}
    mint(ll _v) : v(_v % mod) { v += mod * (v < 0); }

    mint& operator+=(const mint& o) {
        if ((v += o.v) >= mod) v -= mod;
        return *this;
    }

    mint& operator*=(const mint& o) {
        return *this = mint(1LL * v * o.v);
    }

    friend mint operator+(const mint& a, const mint& b) {
        return mint(a) += b;
    }

    friend mint operator*(const mint& a, const mint& b) {
        return mint(a) *= b;
    }

    bool operator==(const mint& o) const {
        return v == o.v;
    }
};

int n, nq;
string s[3];
string t;

unordered_map<char, int> mp = {{'J', 1}, {'O', 2}, {'I', 3}};
mint pw[maxN];
mint consec[4][maxN];

namespace Tree {
mint tree[maxN << 2];
int lazy[maxN << 2];

#define m ((l + r) / 2)

void pull(int i, int l, int r) {
    tree[i] = tree[i << 1] * pw[r - m] + tree[i << 1 | 1];
}

void push(int i, int l, int r) {
    if (lazy[i] == 0) return;

    tree[i] = consec[lazy[i]][r - l + 1];

    if (l < r) {
        lazy[i << 1] = lazy[i];
        lazy[i << 1 | 1] = lazy[i];
    }

    lazy[i] = 0;
}

void build(int i, int l, int r) {
    if (l == r) {
        tree[i] = mp[t[l - 1]];
        return;
    }

    build(i << 1, l, m);
    build(i << 1 | 1, m + 1, r);
    pull(i, l, r);
}

void update(int u, int v, int x, int i, int l, int r) {
    push(i, l, r);
    if (v < l || r < u) return;

    if (u <= l && r <= v) {
        lazy[i] = x;
        push(i, l, r);
        return;
    }

    update(u, v, x, i << 1, l, m);
    update(u, v, x, i << 1 | 1, m + 1, r);
    pull(i, l, r);
}

#undef m
} // namespace Tree
using namespace Tree;

struct Sub2 {
    void solve() {
        cin >> nq >> t;
        build(1, 1, n);

        mint target = 0;
        For (i, 1, n) {
            target = target * base + mp[s[0][i - 1]];
        }

        cout << (target == tree[1] ? "Yes" : "No") << '\n';

        Rep (_, nq) {
            int l, r; char c; cin >> l >> r >> c;
            update(l, r, mp[c], 1, 1, n);
            cout << (target == tree[1] ? "Yes" : "No") << '\n';
        }
    }
};

struct Sub3 {
    set<string> st;
    vector<string> v {s[0], s[1], s[2]};

    string combine(const string &a, const string& b) {
        string ret(n, ' ');

        Rep (i, n) {
            if (a[i] == b[i]) {
                ret[i] = a[i];
            } else {
                ret[i] = ('J' + 'O' + 'I') - (a[i] + b[i]);
            }
        }

        return ret;
    }

    void solve() {
        st.insert(all(v));

        Rep (i, isz(v)) {
            For (j, i + 1, isz(v) - 1) {
                string nxt = combine(v[i], v[j]);

                if (st.insert(nxt).se) {
                    v.push_back(nxt);
                }
            }
        }

        cin >> nq >> t;
        cout << (st.count(t) ? "Yes" : "No") << '\n';

        Rep (_, nq) {
            int l, r; char c; cin >> l >> r >> c;
            For (i, l, r) t[i - 1] = c;
            cout << (st.count(t) ? "Yes" : "No") << '\n';
        }
    }
};

signed main() {
    cin >> n;
    Rep (i, 3) cin >> s[i];

    pw[0] = 1;
    For (i, 1, maxN - 1) pw[i] = pw[i - 1] * base;

    For (i, 1, maxN - 1) {
        For (c, 1, 3) {
            consec[c][i] = consec[c][i - 1] * base + c;
        }
    }

#define SUB(x) \
    Sub##x* sol = new Sub##x{}; \
    sol->solve(); delete sol

    if (s[0] == s[1] && s[1] == s[2]) {
        SUB(2);
    } else if (n <= 100) {
        SUB(3);
    }
}

/*
    abc def
    1     6
    m = 3

    m + 1 -> r: 6 - 3 = 3
*/

Compilation message

Main.cpp: In constructor '__Init__::__Init__()':
Main.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |             freopen(Task".inp", "r", stdin);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |             freopen(Task".out", "w", stdout); }
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 9396 KB Output is correct
2 Correct 80 ms 9412 KB Output is correct
3 Correct 80 ms 9244 KB Output is correct
4 Correct 70 ms 9300 KB Output is correct
5 Correct 70 ms 9376 KB Output is correct
6 Correct 68 ms 9320 KB Output is correct
7 Correct 73 ms 9356 KB Output is correct
8 Correct 76 ms 9404 KB Output is correct
9 Correct 86 ms 9584 KB Output is correct
10 Correct 73 ms 9424 KB Output is correct
11 Correct 75 ms 9408 KB Output is correct
12 Correct 72 ms 9452 KB Output is correct
13 Correct 76 ms 9432 KB Output is correct
14 Correct 72 ms 9412 KB Output is correct
15 Correct 75 ms 9484 KB Output is correct
16 Correct 73 ms 9412 KB Output is correct
17 Correct 73 ms 9420 KB Output is correct
18 Correct 73 ms 9416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 9396 KB Output is correct
2 Correct 80 ms 9412 KB Output is correct
3 Correct 80 ms 9244 KB Output is correct
4 Correct 70 ms 9300 KB Output is correct
5 Correct 70 ms 9376 KB Output is correct
6 Correct 68 ms 9320 KB Output is correct
7 Correct 73 ms 9356 KB Output is correct
8 Correct 76 ms 9404 KB Output is correct
9 Correct 86 ms 9584 KB Output is correct
10 Correct 73 ms 9424 KB Output is correct
11 Correct 75 ms 9408 KB Output is correct
12 Correct 72 ms 9452 KB Output is correct
13 Correct 76 ms 9432 KB Output is correct
14 Correct 72 ms 9412 KB Output is correct
15 Correct 75 ms 9484 KB Output is correct
16 Correct 73 ms 9412 KB Output is correct
17 Correct 73 ms 9420 KB Output is correct
18 Correct 73 ms 9416 KB Output is correct
19 Correct 186 ms 14592 KB Output is correct
20 Correct 211 ms 12908 KB Output is correct
21 Correct 138 ms 14276 KB Output is correct
22 Correct 141 ms 14104 KB Output is correct
23 Correct 108 ms 10444 KB Output is correct
24 Correct 107 ms 10440 KB Output is correct
25 Correct 142 ms 14596 KB Output is correct
26 Correct 154 ms 14544 KB Output is correct
27 Correct 157 ms 14612 KB Output is correct
28 Correct 164 ms 14564 KB Output is correct
29 Correct 162 ms 14520 KB Output is correct
30 Correct 114 ms 10456 KB Output is correct
31 Correct 160 ms 14628 KB Output is correct
32 Correct 150 ms 14232 KB Output is correct
33 Correct 113 ms 10356 KB Output is correct
34 Correct 162 ms 14500 KB Output is correct
35 Correct 128 ms 13808 KB Output is correct
36 Correct 107 ms 10436 KB Output is correct
37 Correct 114 ms 10584 KB Output is correct
38 Correct 163 ms 12816 KB Output is correct
39 Correct 128 ms 12580 KB Output is correct
40 Correct 136 ms 13128 KB Output is correct
41 Correct 194 ms 14748 KB Output is correct
42 Correct 52 ms 11992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 9396 KB Output is correct
2 Correct 80 ms 9412 KB Output is correct
3 Correct 80 ms 9244 KB Output is correct
4 Correct 70 ms 9300 KB Output is correct
5 Correct 70 ms 9376 KB Output is correct
6 Correct 68 ms 9320 KB Output is correct
7 Correct 73 ms 9356 KB Output is correct
8 Correct 76 ms 9404 KB Output is correct
9 Correct 86 ms 9584 KB Output is correct
10 Correct 73 ms 9424 KB Output is correct
11 Correct 75 ms 9408 KB Output is correct
12 Correct 72 ms 9452 KB Output is correct
13 Correct 76 ms 9432 KB Output is correct
14 Correct 72 ms 9412 KB Output is correct
15 Correct 75 ms 9484 KB Output is correct
16 Correct 73 ms 9412 KB Output is correct
17 Correct 73 ms 9420 KB Output is correct
18 Correct 73 ms 9416 KB Output is correct
19 Correct 65 ms 9316 KB Output is correct
20 Correct 91 ms 9356 KB Output is correct
21 Correct 55 ms 9412 KB Output is correct
22 Correct 49 ms 9236 KB Output is correct
23 Correct 57 ms 9452 KB Output is correct
24 Correct 52 ms 9356 KB Output is correct
25 Correct 57 ms 9472 KB Output is correct
26 Correct 49 ms 9276 KB Output is correct
27 Correct 55 ms 9428 KB Output is correct
28 Correct 50 ms 9184 KB Output is correct
29 Correct 60 ms 9368 KB Output is correct
30 Correct 50 ms 9284 KB Output is correct
31 Correct 57 ms 9416 KB Output is correct
32 Correct 58 ms 9352 KB Output is correct
33 Correct 55 ms 9368 KB Output is correct
34 Correct 52 ms 9284 KB Output is correct
35 Correct 57 ms 9396 KB Output is correct
36 Correct 57 ms 9384 KB Output is correct
37 Correct 64 ms 9444 KB Output is correct
38 Correct 56 ms 9448 KB Output is correct
39 Correct 57 ms 9424 KB Output is correct
40 Correct 54 ms 9408 KB Output is correct
41 Correct 58 ms 9396 KB Output is correct
42 Correct 54 ms 9444 KB Output is correct
43 Correct 53 ms 9412 KB Output is correct
44 Correct 56 ms 9460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 9396 KB Output is correct
2 Correct 80 ms 9412 KB Output is correct
3 Correct 80 ms 9244 KB Output is correct
4 Correct 70 ms 9300 KB Output is correct
5 Correct 70 ms 9376 KB Output is correct
6 Correct 68 ms 9320 KB Output is correct
7 Correct 73 ms 9356 KB Output is correct
8 Correct 76 ms 9404 KB Output is correct
9 Correct 86 ms 9584 KB Output is correct
10 Correct 73 ms 9424 KB Output is correct
11 Correct 75 ms 9408 KB Output is correct
12 Correct 72 ms 9452 KB Output is correct
13 Correct 76 ms 9432 KB Output is correct
14 Correct 72 ms 9412 KB Output is correct
15 Correct 75 ms 9484 KB Output is correct
16 Correct 73 ms 9412 KB Output is correct
17 Correct 73 ms 9420 KB Output is correct
18 Correct 73 ms 9416 KB Output is correct
19 Correct 186 ms 14592 KB Output is correct
20 Correct 211 ms 12908 KB Output is correct
21 Correct 138 ms 14276 KB Output is correct
22 Correct 141 ms 14104 KB Output is correct
23 Correct 108 ms 10444 KB Output is correct
24 Correct 107 ms 10440 KB Output is correct
25 Correct 142 ms 14596 KB Output is correct
26 Correct 154 ms 14544 KB Output is correct
27 Correct 157 ms 14612 KB Output is correct
28 Correct 164 ms 14564 KB Output is correct
29 Correct 162 ms 14520 KB Output is correct
30 Correct 114 ms 10456 KB Output is correct
31 Correct 160 ms 14628 KB Output is correct
32 Correct 150 ms 14232 KB Output is correct
33 Correct 113 ms 10356 KB Output is correct
34 Correct 162 ms 14500 KB Output is correct
35 Correct 128 ms 13808 KB Output is correct
36 Correct 107 ms 10436 KB Output is correct
37 Correct 114 ms 10584 KB Output is correct
38 Correct 163 ms 12816 KB Output is correct
39 Correct 128 ms 12580 KB Output is correct
40 Correct 136 ms 13128 KB Output is correct
41 Correct 194 ms 14748 KB Output is correct
42 Correct 52 ms 11992 KB Output is correct
43 Correct 65 ms 9316 KB Output is correct
44 Correct 91 ms 9356 KB Output is correct
45 Correct 55 ms 9412 KB Output is correct
46 Correct 49 ms 9236 KB Output is correct
47 Correct 57 ms 9452 KB Output is correct
48 Correct 52 ms 9356 KB Output is correct
49 Correct 57 ms 9472 KB Output is correct
50 Correct 49 ms 9276 KB Output is correct
51 Correct 55 ms 9428 KB Output is correct
52 Correct 50 ms 9184 KB Output is correct
53 Correct 60 ms 9368 KB Output is correct
54 Correct 50 ms 9284 KB Output is correct
55 Correct 57 ms 9416 KB Output is correct
56 Correct 58 ms 9352 KB Output is correct
57 Correct 55 ms 9368 KB Output is correct
58 Correct 52 ms 9284 KB Output is correct
59 Correct 57 ms 9396 KB Output is correct
60 Correct 57 ms 9384 KB Output is correct
61 Correct 64 ms 9444 KB Output is correct
62 Correct 56 ms 9448 KB Output is correct
63 Correct 57 ms 9424 KB Output is correct
64 Correct 54 ms 9408 KB Output is correct
65 Correct 58 ms 9396 KB Output is correct
66 Correct 54 ms 9444 KB Output is correct
67 Correct 53 ms 9412 KB Output is correct
68 Correct 56 ms 9460 KB Output is correct
69 Incorrect 9 ms 8692 KB Output isn't correct
70 Halted 0 ms 0 KB -