답안 #891382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891382 2023-12-22T20:31:59 Z coldEr66 Crossing (JOI21_crossing) C++14
100 / 100
969 ms 54536 KB
#ifndef Yamada
#define Yamada
#include Yamada __FILE__ Yamada

char JOI[] = {'J', 'O', 'I'};

vector<int> cross(vector<int> &g1, vector<int> &g2) {
    vector<int> ret;
    for (int i = 0; i < SZ(g1); ++i) {
        int cur = 2 * (g1[i] + g2[i]) % 3;
        ret.eb(cur);
    }
    return ret;
}

const int maxn = 2e5 + 5;

struct node {
    int sc, tc, val, tag;
} seg[maxn * 4];

void build(int id, int l, int r, vector<int> &v, vector<int> &t) {
    seg[id].sc = seg[id].tc = seg[id].tag = -1;
    seg[id].val = 0;
    if (l == r-1) {
        seg[id].sc = v[l];
        seg[id].tc = t[l];
        seg[id].val = (v[l] == t[l]);
        seg[id].tag = -1;
        return;
    }
    int mid = l + r >> 1;
    build(id * 2 + 1, l, mid, v, t);
    build(id * 2 + 2, mid, r, v, t);
    seg[id].sc = (seg[id * 2 + 1].sc == seg[id * 2 + 2].sc ? seg[id * 2 + 1].sc : -1);
    seg[id].tc = (seg[id * 2 + 1].tc == seg[id * 2 + 2].tc ? seg[id * 2 + 1].tc : -1);
    seg[id].val = seg[id * 2 + 1].val & seg[id * 2 + 2].val;
}

void push(int id) {
    if (seg[id].tag == -1) return;
    seg[id * 2 + 1].tag = seg[id].tag;
    seg[id * 2 + 2].tag = seg[id].tag;
    seg[id].tag = -1;
}

void ins(int id, int l, int r, int L, int R, int op) {
    if (L <= l && R >= r) {
        seg[id].tag = op;
        seg[id].tc = op;
        seg[id].val = (seg[id].tc == seg[id].sc);
        return;
    }
    if (r <= L || l >= R) return;
    int mid = l + r >> 1;
    push(id);
    ins(id * 2 + 1, l, mid, L, R, op);
    ins(id * 2 + 2, mid, r, L, R, op);

    int lc = (seg[id * 2 + 1].tag == -1 ? seg[id * 2 + 1].tc : seg[id * 2 + 1].tag);
    int rc = (seg[id * 2 + 2].tag == -1 ? seg[id * 2 + 2].tc : seg[id * 2 + 2].tag);
    int lval = (seg[id * 2 + 1].tag == -1 ? seg[id * 2 + 1].val : (seg[id * 2 + 1].tag == seg[id * 2 + 1].sc));
    int rval = (seg[id * 2 + 2].tag == -1 ? seg[id * 2 + 2].val : (seg[id * 2 + 2].tag == seg[id * 2 + 2].sc));
    seg[id].tc = (lc == rc ? lc : -1);
    seg[id].val = lval & rval;
}

void solve() {
    int n; cin >> n;
    vector<int> gene[3];
    for (int i = 0; i < 3; ++i) {
        string s; cin >> s;
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (s[j] == JOI[k]) gene[i].eb(k);
            }
        }
    }
    vector<vector<int>> G;
    G.eb(gene[0]);
    G.eb(gene[1]);
    G.eb(gene[2]);
    vector<int> t1 = cross(gene[0], gene[1]);
    vector<int> t2 = cross(gene[0], gene[2]);
    vector<int> t3 = cross(gene[1], gene[2]);
    G.eb(t1);
    G.eb(t2);
    G.eb(t3);
    G.eb(cross(t1, gene[2]));
    G.eb(cross(t2, gene[1]));
    G.eb(cross(t3, gene[0]));
    int q; cin >> q;
    string T; cin >> T;
    vector<int> gt;
    for (int i = 0; i < n; ++i) {
        for (int k = 0; k < 3; ++k) {
            if (T[i] == JOI[k]) gt.eb(k);
        }
    }
    vector<pair<pii, int>> qr;
    for (int i = 1; i <= q; ++i) {
        int l, r;
        cin >> l >> r;
        --l;
        char c; cin >> c;
        int op = -1;
        for (int k = 0; k < 3; ++k) if (c == JOI[k]) op = k;
        qr.eb(pii(l, r), op);
    }

    vector<int> ans(q + 1);
    auto cal = [&](vector<int> &v) -> void {
        build(0, 0, n, v, gt);
        ans[0] |= seg[0].val;
        for (int i = 0; i < q; ++i){
            int l = qr[i].X.X, r = qr[i].X.Y, op = qr[i].Y;

            ins(0, 0, n, l, r, op);
            ans[i+1] |= seg[0].val;
        }
    };
    for (auto vec : G) {
        cal(vec);
    }
    for (int i = 0; i <= q; ++i) {
        if (ans[i]) print("Yes");
        else print("No");
    }
}

signed main() {
    IOS();
    int t = 1; // cin >> t;
    for (int i=1;i<=t;++i) solve();
    return 0;
}

#else

#ifdef local 
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize ("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int int64_t
#define double __float80
using pii = pair<int, int>;
template <typename T> using MaxHeap = std::priority_queue<T>;
template <typename T> using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;

#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define ee emplace
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define X first
#define Y second

#ifdef local
#define IOS() void()
#define debug(...) \
    fprintf(stderr, "\e[1;93m"), \
    fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), \
    fprintf(stderr, "\e[0m")
template <typename T> void _do(T &&_t) {cerr << _t << '\n';}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#define print(...) \
    fprintf(stderr, "\e[1;96m"), \
    _P(__VA_ARGS__), \
    fprintf(stderr, "\e[0m")
#else
#define IOS() ios_base::sync_with_stdio(0); cin.tie(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#define endl '\n'
#endif

template <typename U, typename V> bool chmin(U &u, V v) {return u > v ? u = v, 1 : 0;}
template <typename U, typename V> bool chmax(U &u, V v) {return u < v ? u = v, 1 : 0;}

template <typename T> void _P(T &&_x) {cout << _x << '\n';}
template <typename T, typename ...S> void _P(T &&_x, S &&..._t) {cout << _x << " "; _P(_t...);}

#endif

Compilation message

Main.cpp: In function 'void build(int64_t, int64_t, int64_t, std::vector<long int>&, std::vector<long int>&)':
Main.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function 'void ins(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)':
Main.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 7928 KB Output is correct
2 Correct 252 ms 9420 KB Output is correct
3 Correct 208 ms 9420 KB Output is correct
4 Correct 200 ms 8884 KB Output is correct
5 Correct 192 ms 9220 KB Output is correct
6 Correct 202 ms 8888 KB Output is correct
7 Correct 194 ms 9420 KB Output is correct
8 Correct 205 ms 8912 KB Output is correct
9 Correct 215 ms 9172 KB Output is correct
10 Correct 209 ms 9072 KB Output is correct
11 Correct 214 ms 9140 KB Output is correct
12 Correct 209 ms 9560 KB Output is correct
13 Correct 217 ms 8912 KB Output is correct
14 Correct 211 ms 9424 KB Output is correct
15 Correct 216 ms 8868 KB Output is correct
16 Correct 210 ms 9420 KB Output is correct
17 Correct 220 ms 9552 KB Output is correct
18 Correct 175 ms 9292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 7928 KB Output is correct
2 Correct 252 ms 9420 KB Output is correct
3 Correct 208 ms 9420 KB Output is correct
4 Correct 200 ms 8884 KB Output is correct
5 Correct 192 ms 9220 KB Output is correct
6 Correct 202 ms 8888 KB Output is correct
7 Correct 194 ms 9420 KB Output is correct
8 Correct 205 ms 8912 KB Output is correct
9 Correct 215 ms 9172 KB Output is correct
10 Correct 209 ms 9072 KB Output is correct
11 Correct 214 ms 9140 KB Output is correct
12 Correct 209 ms 9560 KB Output is correct
13 Correct 217 ms 8912 KB Output is correct
14 Correct 211 ms 9424 KB Output is correct
15 Correct 216 ms 8868 KB Output is correct
16 Correct 210 ms 9420 KB Output is correct
17 Correct 220 ms 9552 KB Output is correct
18 Correct 175 ms 9292 KB Output is correct
19 Correct 827 ms 53284 KB Output is correct
20 Correct 769 ms 54536 KB Output is correct
21 Correct 596 ms 51496 KB Output is correct
22 Correct 571 ms 49856 KB Output is correct
23 Correct 395 ms 14236 KB Output is correct
24 Correct 398 ms 13048 KB Output is correct
25 Correct 627 ms 53980 KB Output is correct
26 Correct 614 ms 53436 KB Output is correct
27 Correct 679 ms 53692 KB Output is correct
28 Correct 687 ms 53364 KB Output is correct
29 Correct 657 ms 53396 KB Output is correct
30 Correct 439 ms 12852 KB Output is correct
31 Correct 673 ms 53372 KB Output is correct
32 Correct 643 ms 51084 KB Output is correct
33 Correct 408 ms 12884 KB Output is correct
34 Correct 684 ms 54316 KB Output is correct
35 Correct 522 ms 46820 KB Output is correct
36 Correct 399 ms 14088 KB Output is correct
37 Correct 394 ms 13304 KB Output is correct
38 Correct 608 ms 53380 KB Output is correct
39 Correct 397 ms 53628 KB Output is correct
40 Correct 514 ms 35784 KB Output is correct
41 Correct 969 ms 53720 KB Output is correct
42 Correct 77 ms 53888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 7928 KB Output is correct
2 Correct 252 ms 9420 KB Output is correct
3 Correct 208 ms 9420 KB Output is correct
4 Correct 200 ms 8884 KB Output is correct
5 Correct 192 ms 9220 KB Output is correct
6 Correct 202 ms 8888 KB Output is correct
7 Correct 194 ms 9420 KB Output is correct
8 Correct 205 ms 8912 KB Output is correct
9 Correct 215 ms 9172 KB Output is correct
10 Correct 209 ms 9072 KB Output is correct
11 Correct 214 ms 9140 KB Output is correct
12 Correct 209 ms 9560 KB Output is correct
13 Correct 217 ms 8912 KB Output is correct
14 Correct 211 ms 9424 KB Output is correct
15 Correct 216 ms 8868 KB Output is correct
16 Correct 210 ms 9420 KB Output is correct
17 Correct 220 ms 9552 KB Output is correct
18 Correct 175 ms 9292 KB Output is correct
19 Correct 241 ms 9168 KB Output is correct
20 Correct 204 ms 9584 KB Output is correct
21 Correct 208 ms 8912 KB Output is correct
22 Correct 179 ms 9396 KB Output is correct
23 Correct 209 ms 9820 KB Output is correct
24 Correct 201 ms 9160 KB Output is correct
25 Correct 211 ms 9180 KB Output is correct
26 Correct 195 ms 8900 KB Output is correct
27 Correct 208 ms 9144 KB Output is correct
28 Correct 185 ms 9136 KB Output is correct
29 Correct 218 ms 8912 KB Output is correct
30 Correct 185 ms 8796 KB Output is correct
31 Correct 207 ms 9412 KB Output is correct
32 Correct 206 ms 8896 KB Output is correct
33 Correct 214 ms 8652 KB Output is correct
34 Correct 193 ms 8944 KB Output is correct
35 Correct 209 ms 9420 KB Output is correct
36 Correct 220 ms 9420 KB Output is correct
37 Correct 210 ms 9156 KB Output is correct
38 Correct 220 ms 8536 KB Output is correct
39 Correct 211 ms 9168 KB Output is correct
40 Correct 215 ms 9168 KB Output is correct
41 Correct 211 ms 8900 KB Output is correct
42 Correct 218 ms 8912 KB Output is correct
43 Correct 199 ms 8640 KB Output is correct
44 Correct 214 ms 9652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 7928 KB Output is correct
2 Correct 252 ms 9420 KB Output is correct
3 Correct 208 ms 9420 KB Output is correct
4 Correct 200 ms 8884 KB Output is correct
5 Correct 192 ms 9220 KB Output is correct
6 Correct 202 ms 8888 KB Output is correct
7 Correct 194 ms 9420 KB Output is correct
8 Correct 205 ms 8912 KB Output is correct
9 Correct 215 ms 9172 KB Output is correct
10 Correct 209 ms 9072 KB Output is correct
11 Correct 214 ms 9140 KB Output is correct
12 Correct 209 ms 9560 KB Output is correct
13 Correct 217 ms 8912 KB Output is correct
14 Correct 211 ms 9424 KB Output is correct
15 Correct 216 ms 8868 KB Output is correct
16 Correct 210 ms 9420 KB Output is correct
17 Correct 220 ms 9552 KB Output is correct
18 Correct 175 ms 9292 KB Output is correct
19 Correct 827 ms 53284 KB Output is correct
20 Correct 769 ms 54536 KB Output is correct
21 Correct 596 ms 51496 KB Output is correct
22 Correct 571 ms 49856 KB Output is correct
23 Correct 395 ms 14236 KB Output is correct
24 Correct 398 ms 13048 KB Output is correct
25 Correct 627 ms 53980 KB Output is correct
26 Correct 614 ms 53436 KB Output is correct
27 Correct 679 ms 53692 KB Output is correct
28 Correct 687 ms 53364 KB Output is correct
29 Correct 657 ms 53396 KB Output is correct
30 Correct 439 ms 12852 KB Output is correct
31 Correct 673 ms 53372 KB Output is correct
32 Correct 643 ms 51084 KB Output is correct
33 Correct 408 ms 12884 KB Output is correct
34 Correct 684 ms 54316 KB Output is correct
35 Correct 522 ms 46820 KB Output is correct
36 Correct 399 ms 14088 KB Output is correct
37 Correct 394 ms 13304 KB Output is correct
38 Correct 608 ms 53380 KB Output is correct
39 Correct 397 ms 53628 KB Output is correct
40 Correct 514 ms 35784 KB Output is correct
41 Correct 969 ms 53720 KB Output is correct
42 Correct 77 ms 53888 KB Output is correct
43 Correct 241 ms 9168 KB Output is correct
44 Correct 204 ms 9584 KB Output is correct
45 Correct 208 ms 8912 KB Output is correct
46 Correct 179 ms 9396 KB Output is correct
47 Correct 209 ms 9820 KB Output is correct
48 Correct 201 ms 9160 KB Output is correct
49 Correct 211 ms 9180 KB Output is correct
50 Correct 195 ms 8900 KB Output is correct
51 Correct 208 ms 9144 KB Output is correct
52 Correct 185 ms 9136 KB Output is correct
53 Correct 218 ms 8912 KB Output is correct
54 Correct 185 ms 8796 KB Output is correct
55 Correct 207 ms 9412 KB Output is correct
56 Correct 206 ms 8896 KB Output is correct
57 Correct 214 ms 8652 KB Output is correct
58 Correct 193 ms 8944 KB Output is correct
59 Correct 209 ms 9420 KB Output is correct
60 Correct 220 ms 9420 KB Output is correct
61 Correct 210 ms 9156 KB Output is correct
62 Correct 220 ms 8536 KB Output is correct
63 Correct 211 ms 9168 KB Output is correct
64 Correct 215 ms 9168 KB Output is correct
65 Correct 211 ms 8900 KB Output is correct
66 Correct 218 ms 8912 KB Output is correct
67 Correct 199 ms 8640 KB Output is correct
68 Correct 214 ms 9652 KB Output is correct
69 Correct 694 ms 48228 KB Output is correct
70 Correct 762 ms 53128 KB Output is correct
71 Correct 397 ms 13876 KB Output is correct
72 Correct 393 ms 13068 KB Output is correct
73 Correct 392 ms 13184 KB Output is correct
74 Correct 546 ms 48920 KB Output is correct
75 Correct 392 ms 12792 KB Output is correct
76 Correct 608 ms 53764 KB Output is correct
77 Correct 566 ms 49700 KB Output is correct
78 Correct 391 ms 12816 KB Output is correct
79 Correct 401 ms 13816 KB Output is correct
80 Correct 532 ms 45920 KB Output is correct
81 Correct 392 ms 13632 KB Output is correct
82 Correct 596 ms 53360 KB Output is correct
83 Correct 621 ms 52748 KB Output is correct
84 Correct 398 ms 12540 KB Output is correct
85 Correct 390 ms 14072 KB Output is correct
86 Correct 660 ms 46036 KB Output is correct
87 Correct 708 ms 53376 KB Output is correct
88 Correct 441 ms 14076 KB Output is correct
89 Correct 630 ms 50252 KB Output is correct
90 Correct 665 ms 53124 KB Output is correct
91 Correct 435 ms 12796 KB Output is correct
92 Correct 530 ms 45752 KB Output is correct
93 Correct 397 ms 12752 KB Output is correct
94 Correct 394 ms 14072 KB Output is correct
95 Correct 392 ms 13560 KB Output is correct
96 Correct 617 ms 54536 KB Output is correct
97 Correct 398 ms 53288 KB Output is correct
98 Correct 510 ms 36804 KB Output is correct
99 Correct 889 ms 53888 KB Output is correct
100 Correct 79 ms 53380 KB Output is correct