답안 #534197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534197 2022-03-08T02:06:51 Z Monarchuwu Crossing (JOI21_crossing) C++17
26 / 100
246 ms 14996 KB
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;

const int N = 2e5 + 8, base = 7, mod = 1e9 + 2277;
const ll mod2 = (ll)mod * mod;
int n;
string sa, sb, sc;

ll add(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; }
ll ha, hb, hc, pw[N], prf[N];
int ch[256];
void init_hsh() {
    pw[0] = prf[0] = 1;
    for (int i = 1; i <= n; ++i) {
        pw[i] = pw[i - 1] * base % mod;
        prf[i] = add(prf[i - 1], pw[i]);
    }

    ch['J'] = 1, ch['O'] = 2, ch['I'] = 3;
    for (int i = 0; i < n; ++i) {
        ha = (ha + ch[sa[i]] * pw[i]) % mod;
        hb = (hb + ch[sb[i]] * pw[i]) % mod;
        hc = (hc + ch[sc[i]] * pw[i]) % mod;
    }
}

int q;
string t;
ll seg[N << 2];
int laz[N << 2];
void build(int u, int l, int r) {
    if (l == r) {
        seg[u] = ch[t[l]] * pw[l] % mod;
        return;
    }
    int m = (l + r) >> 1, u1 = u << 1, u2 = u1 | 1;
    build(u1, l, m);
    build(u2, m + 1, r);
    seg[u] = add(seg[u1], seg[u2]);
}
void upd(int u, int l, int r, int a, int b, int x) {
    if (a <= l && r <= b) {
        seg[u] = x * (prf[r] - prf[l] + pw[l] + mod) % mod;
        laz[u] = x;
        return;
    }
    int m = (l + r) >> 1, u1 = u << 1, u2 = u1 | 1;
    if (laz[u]) {
        seg[u1] = laz[u] * (prf[m] - prf[l] + pw[l] + mod) % mod;
        seg[u2] = laz[u] * (prf[r] - prf[m] + mod) % mod;
        laz[u1] = laz[u2] = laz[u];
        laz[u] = 0;
    }
    if (a <= m) upd(u1, l, m, a, b, x);
    if (m < b) upd(u2, m + 1, r, a, b, x);
    seg[u] = add(seg[u1], seg[u2]);
}

int main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cin >> n >> sa >> sb >> sc;

    cin >> q >> t;
    init_hsh();
    build(1, 0, n - 1);
    cout << (ha == seg[1] ? "Yes\n" : "No\n");

    int l, r; char c; while (q--) {
        cin >> l >> r >> c;
        upd(1, 0, n - 1, l - 1, r - 1, ch[c]);
        cout << (ha == seg[1] ? "Yes\n" : "No\n");
    }
}
/**  /\_/\
 *  (= ._.)
 *  / >0  \>1
**/

Compilation message

Main.cpp: In function 'void init_hsh()':
Main.cpp:24:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   24 |         ha = (ha + ch[sa[i]] * pw[i]) % mod;
      |                            ^
Main.cpp:25:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |         hb = (hb + ch[sb[i]] * pw[i]) % mod;
      |                            ^
Main.cpp:26:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   26 |         hc = (hc + ch[sc[i]] * pw[i]) % mod;
      |                            ^
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:36:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   36 |         seg[u] = ch[t[l]] * pw[l] % mod;
      |                         ^
Main.cpp: In function 'int main()':
Main.cpp:73:43: warning: array subscript has type 'char' [-Wchar-subscripts]
   73 |         upd(1, 0, n - 1, l - 1, r - 1, ch[c]);
      |                                           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2232 KB Output is correct
2 Correct 65 ms 2380 KB Output is correct
3 Correct 59 ms 2324 KB Output is correct
4 Correct 50 ms 2352 KB Output is correct
5 Correct 56 ms 2332 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 56 ms 2376 KB Output is correct
8 Correct 52 ms 2460 KB Output is correct
9 Correct 54 ms 2456 KB Output is correct
10 Correct 58 ms 2368 KB Output is correct
11 Correct 59 ms 2348 KB Output is correct
12 Correct 53 ms 2372 KB Output is correct
13 Correct 54 ms 2404 KB Output is correct
14 Correct 53 ms 2440 KB Output is correct
15 Correct 60 ms 2372 KB Output is correct
16 Correct 60 ms 2380 KB Output is correct
17 Correct 54 ms 2372 KB Output is correct
18 Correct 57 ms 2336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2232 KB Output is correct
2 Correct 65 ms 2380 KB Output is correct
3 Correct 59 ms 2324 KB Output is correct
4 Correct 50 ms 2352 KB Output is correct
5 Correct 56 ms 2332 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 56 ms 2376 KB Output is correct
8 Correct 52 ms 2460 KB Output is correct
9 Correct 54 ms 2456 KB Output is correct
10 Correct 58 ms 2368 KB Output is correct
11 Correct 59 ms 2348 KB Output is correct
12 Correct 53 ms 2372 KB Output is correct
13 Correct 54 ms 2404 KB Output is correct
14 Correct 53 ms 2440 KB Output is correct
15 Correct 60 ms 2372 KB Output is correct
16 Correct 60 ms 2380 KB Output is correct
17 Correct 54 ms 2372 KB Output is correct
18 Correct 57 ms 2336 KB Output is correct
19 Correct 246 ms 14100 KB Output is correct
20 Correct 170 ms 12532 KB Output is correct
21 Correct 116 ms 13816 KB Output is correct
22 Correct 123 ms 13432 KB Output is correct
23 Correct 112 ms 3804 KB Output is correct
24 Correct 77 ms 3792 KB Output is correct
25 Correct 126 ms 14048 KB Output is correct
26 Correct 154 ms 14100 KB Output is correct
27 Correct 160 ms 14156 KB Output is correct
28 Correct 159 ms 14100 KB Output is correct
29 Correct 152 ms 14136 KB Output is correct
30 Correct 85 ms 3860 KB Output is correct
31 Correct 144 ms 14136 KB Output is correct
32 Correct 185 ms 13776 KB Output is correct
33 Correct 78 ms 3856 KB Output is correct
34 Correct 186 ms 14108 KB Output is correct
35 Correct 143 ms 13164 KB Output is correct
36 Correct 78 ms 3748 KB Output is correct
37 Correct 79 ms 3760 KB Output is correct
38 Correct 202 ms 12976 KB Output is correct
39 Correct 96 ms 12720 KB Output is correct
40 Correct 113 ms 10028 KB Output is correct
41 Correct 237 ms 14996 KB Output is correct
42 Correct 48 ms 12180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2232 KB Output is correct
2 Correct 65 ms 2380 KB Output is correct
3 Correct 59 ms 2324 KB Output is correct
4 Correct 50 ms 2352 KB Output is correct
5 Correct 56 ms 2332 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 56 ms 2376 KB Output is correct
8 Correct 52 ms 2460 KB Output is correct
9 Correct 54 ms 2456 KB Output is correct
10 Correct 58 ms 2368 KB Output is correct
11 Correct 59 ms 2348 KB Output is correct
12 Correct 53 ms 2372 KB Output is correct
13 Correct 54 ms 2404 KB Output is correct
14 Correct 53 ms 2440 KB Output is correct
15 Correct 60 ms 2372 KB Output is correct
16 Correct 60 ms 2380 KB Output is correct
17 Correct 54 ms 2372 KB Output is correct
18 Correct 57 ms 2336 KB Output is correct
19 Correct 63 ms 2292 KB Output is correct
20 Correct 62 ms 2328 KB Output is correct
21 Incorrect 51 ms 2460 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2232 KB Output is correct
2 Correct 65 ms 2380 KB Output is correct
3 Correct 59 ms 2324 KB Output is correct
4 Correct 50 ms 2352 KB Output is correct
5 Correct 56 ms 2332 KB Output is correct
6 Correct 62 ms 2292 KB Output is correct
7 Correct 56 ms 2376 KB Output is correct
8 Correct 52 ms 2460 KB Output is correct
9 Correct 54 ms 2456 KB Output is correct
10 Correct 58 ms 2368 KB Output is correct
11 Correct 59 ms 2348 KB Output is correct
12 Correct 53 ms 2372 KB Output is correct
13 Correct 54 ms 2404 KB Output is correct
14 Correct 53 ms 2440 KB Output is correct
15 Correct 60 ms 2372 KB Output is correct
16 Correct 60 ms 2380 KB Output is correct
17 Correct 54 ms 2372 KB Output is correct
18 Correct 57 ms 2336 KB Output is correct
19 Correct 246 ms 14100 KB Output is correct
20 Correct 170 ms 12532 KB Output is correct
21 Correct 116 ms 13816 KB Output is correct
22 Correct 123 ms 13432 KB Output is correct
23 Correct 112 ms 3804 KB Output is correct
24 Correct 77 ms 3792 KB Output is correct
25 Correct 126 ms 14048 KB Output is correct
26 Correct 154 ms 14100 KB Output is correct
27 Correct 160 ms 14156 KB Output is correct
28 Correct 159 ms 14100 KB Output is correct
29 Correct 152 ms 14136 KB Output is correct
30 Correct 85 ms 3860 KB Output is correct
31 Correct 144 ms 14136 KB Output is correct
32 Correct 185 ms 13776 KB Output is correct
33 Correct 78 ms 3856 KB Output is correct
34 Correct 186 ms 14108 KB Output is correct
35 Correct 143 ms 13164 KB Output is correct
36 Correct 78 ms 3748 KB Output is correct
37 Correct 79 ms 3760 KB Output is correct
38 Correct 202 ms 12976 KB Output is correct
39 Correct 96 ms 12720 KB Output is correct
40 Correct 113 ms 10028 KB Output is correct
41 Correct 237 ms 14996 KB Output is correct
42 Correct 48 ms 12180 KB Output is correct
43 Correct 63 ms 2292 KB Output is correct
44 Correct 62 ms 2328 KB Output is correct
45 Incorrect 51 ms 2460 KB Output isn't correct
46 Halted 0 ms 0 KB -