답안 #608979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
608979 2022-07-27T11:34:58 Z Duy_e Crossing (JOI21_crossing) C++14
100 / 100
512 ms 25528 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long INF = 1e18;
const long long N = 2e5 + 5;
const long long MOD = 2e9 + 11;
const long long base = 311;

int n, q;
string t[4];
ll id[N], f[N], pw[N];
map <ll, bool> mp;

string cross(string a, string b) {
    ll sum = 'J' ^ 'O' ^ 'I';
    string ans = "";
    for (int i = 0; i < n; i ++)
        if (a[i] == b[i])
            ans += a[i];
        else 
            ans += sum ^ a[i] ^ b[i];
    
    return ans;
}

ll decode(string &s) {
    ll ans = 0;
    for (char ch: s) 
        ans = (ans * base + ch) % MOD;

    return ans;
} 

void genall() {
    set <string> S;
    S.insert(t[1]);
    S.insert(t[3]);
    S.insert(t[2]);

    while (true) {
        bool check = false;
        for (string u: S) {
            for (string v: S) {
                string tmp = cross(u, v);
                if (!S.count(tmp)) {
                    check = true;
                    S.insert(tmp);
                    break;
                }
            } 
            if (check) break;
        }
        if (check == false) break;
    }

    for (string u: S) 
        mp[decode(u)] = true;
}

ll st[4 * N], lazy[4 * N];

void build(int id, int l, int r) {
    if (l > r) return;
    if (l == r) {
        ll v = t[0][l - 1];
        st[id] = pw[l] * v % MOD;
        return;
    }

    int mid = l + r >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    st[id] = (st[id << 1] + st[id << 1 | 1]) % MOD;
}

void down(int id, int l, int r) {
    if (lazy[id] == 0) return;
    ll &t = lazy[id];
    int mid = l + r >> 1;
    int u = id << 1, v = id << 1 | 1;
    lazy[u] = lazy[v] = t;
    st[u] = (f[mid] - f[l - 1] + MOD) * t % MOD;
    st[v] = (f[r] - f[mid] + MOD) * t % MOD;
    t = 0;
}

void upd(int id, int l, int r, int lef, int rig, ll ch) {
    if (l > rig || r < lef) return;
    if (lef <= l && r <= rig) {
        st[id] = (f[r] - f[l - 1] + MOD) * ch % MOD;
        lazy[id] = ch;
        return;
    }

    down(id, l, r);
    int mid = l + r >> 1;
    upd(id << 1, l, mid, lef, rig, ch);
    upd(id << 1 | 1, mid + 1, r, lef, rig, ch);
    st[id] = (st[id << 1] + st[id << 1 | 1]) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        //freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif
    
    cin >> n;
    cin >> t[1] >> t[2] >> t[3];
    genall();

    cin >> q;
    cin >> t[0];

    pw[n] = 1;
    for (int i = n - 1; i >= 1; i --) pw[i] = pw[i + 1] * base % MOD;
    for (int i = 1; i <= n; i ++) f[i] = (f[i - 1] + pw[i]) % MOD;

    build(1, 1, n);

    int l, r; char ch;

    if (mp[st[1]]) cout << "Yes\n"; else cout << "No\n";

    while (q --) {
        cin >> l >> r >> ch;
        upd(1, 1, n, l, r, ch);
        if (mp[st[1]]) cout << "Yes\n"; else cout << "No\n";
    }

    return 0;
}    
/**  /\_/\
*   (= ._.)
*   / >🍵 \>🍮
**/

Compilation message

Main.cpp:138:9: warning: "/*" within comment [-Wcomment]
  138 | /**  /\_/\
      |          
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:74:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   74 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function 'void down(int, int, int)':
Main.cpp:83:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |     int mid = l + r >> 1;
      |               ~~^~~
Main.cpp: In function 'void upd(int, int, int, int, int, long long int)':
Main.cpp:100:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  100 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 10240 KB Output is correct
2 Correct 190 ms 11080 KB Output is correct
3 Correct 112 ms 4612 KB Output is correct
4 Correct 140 ms 10984 KB Output is correct
5 Correct 133 ms 11088 KB Output is correct
6 Correct 156 ms 10284 KB Output is correct
7 Correct 151 ms 10572 KB Output is correct
8 Correct 143 ms 11340 KB Output is correct
9 Correct 144 ms 10976 KB Output is correct
10 Correct 173 ms 12500 KB Output is correct
11 Correct 164 ms 11820 KB Output is correct
12 Correct 175 ms 12472 KB Output is correct
13 Correct 151 ms 11724 KB Output is correct
14 Correct 205 ms 12488 KB Output is correct
15 Correct 180 ms 11716 KB Output is correct
16 Correct 199 ms 12460 KB Output is correct
17 Correct 209 ms 11644 KB Output is correct
18 Correct 91 ms 2892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 10240 KB Output is correct
2 Correct 190 ms 11080 KB Output is correct
3 Correct 112 ms 4612 KB Output is correct
4 Correct 140 ms 10984 KB Output is correct
5 Correct 133 ms 11088 KB Output is correct
6 Correct 156 ms 10284 KB Output is correct
7 Correct 151 ms 10572 KB Output is correct
8 Correct 143 ms 11340 KB Output is correct
9 Correct 144 ms 10976 KB Output is correct
10 Correct 173 ms 12500 KB Output is correct
11 Correct 164 ms 11820 KB Output is correct
12 Correct 175 ms 12472 KB Output is correct
13 Correct 151 ms 11724 KB Output is correct
14 Correct 205 ms 12488 KB Output is correct
15 Correct 180 ms 11716 KB Output is correct
16 Correct 199 ms 12460 KB Output is correct
17 Correct 209 ms 11644 KB Output is correct
18 Correct 91 ms 2892 KB Output is correct
19 Correct 391 ms 22728 KB Output is correct
20 Correct 357 ms 20288 KB Output is correct
21 Correct 267 ms 24108 KB Output is correct
22 Correct 256 ms 21724 KB Output is correct
23 Correct 243 ms 14068 KB Output is correct
24 Correct 203 ms 12880 KB Output is correct
25 Correct 327 ms 25152 KB Output is correct
26 Correct 338 ms 23160 KB Output is correct
27 Correct 334 ms 25528 KB Output is correct
28 Correct 369 ms 23136 KB Output is correct
29 Correct 382 ms 25060 KB Output is correct
30 Correct 266 ms 14080 KB Output is correct
31 Correct 427 ms 25436 KB Output is correct
32 Correct 375 ms 22604 KB Output is correct
33 Correct 256 ms 12740 KB Output is correct
34 Correct 388 ms 23152 KB Output is correct
35 Correct 340 ms 22364 KB Output is correct
36 Correct 221 ms 12924 KB Output is correct
37 Correct 234 ms 12788 KB Output is correct
38 Correct 293 ms 17596 KB Output is correct
39 Correct 165 ms 15336 KB Output is correct
40 Correct 304 ms 18160 KB Output is correct
41 Correct 220 ms 13568 KB Output is correct
42 Correct 52 ms 9448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 10240 KB Output is correct
2 Correct 190 ms 11080 KB Output is correct
3 Correct 112 ms 4612 KB Output is correct
4 Correct 140 ms 10984 KB Output is correct
5 Correct 133 ms 11088 KB Output is correct
6 Correct 156 ms 10284 KB Output is correct
7 Correct 151 ms 10572 KB Output is correct
8 Correct 143 ms 11340 KB Output is correct
9 Correct 144 ms 10976 KB Output is correct
10 Correct 173 ms 12500 KB Output is correct
11 Correct 164 ms 11820 KB Output is correct
12 Correct 175 ms 12472 KB Output is correct
13 Correct 151 ms 11724 KB Output is correct
14 Correct 205 ms 12488 KB Output is correct
15 Correct 180 ms 11716 KB Output is correct
16 Correct 199 ms 12460 KB Output is correct
17 Correct 209 ms 11644 KB Output is correct
18 Correct 91 ms 2892 KB Output is correct
19 Correct 170 ms 10572 KB Output is correct
20 Correct 112 ms 4524 KB Output is correct
21 Correct 158 ms 11872 KB Output is correct
22 Correct 134 ms 10052 KB Output is correct
23 Correct 161 ms 11944 KB Output is correct
24 Correct 150 ms 10760 KB Output is correct
25 Correct 158 ms 11832 KB Output is correct
26 Correct 123 ms 10536 KB Output is correct
27 Correct 141 ms 11848 KB Output is correct
28 Correct 123 ms 10744 KB Output is correct
29 Correct 178 ms 11288 KB Output is correct
30 Correct 138 ms 10188 KB Output is correct
31 Correct 165 ms 12056 KB Output is correct
32 Correct 141 ms 12004 KB Output is correct
33 Correct 147 ms 11468 KB Output is correct
34 Correct 167 ms 10544 KB Output is correct
35 Correct 193 ms 12484 KB Output is correct
36 Correct 145 ms 11748 KB Output is correct
37 Correct 142 ms 12440 KB Output is correct
38 Correct 145 ms 11752 KB Output is correct
39 Correct 156 ms 12428 KB Output is correct
40 Correct 146 ms 11692 KB Output is correct
41 Correct 143 ms 12392 KB Output is correct
42 Correct 155 ms 11780 KB Output is correct
43 Correct 150 ms 11032 KB Output is correct
44 Correct 176 ms 11344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 10240 KB Output is correct
2 Correct 190 ms 11080 KB Output is correct
3 Correct 112 ms 4612 KB Output is correct
4 Correct 140 ms 10984 KB Output is correct
5 Correct 133 ms 11088 KB Output is correct
6 Correct 156 ms 10284 KB Output is correct
7 Correct 151 ms 10572 KB Output is correct
8 Correct 143 ms 11340 KB Output is correct
9 Correct 144 ms 10976 KB Output is correct
10 Correct 173 ms 12500 KB Output is correct
11 Correct 164 ms 11820 KB Output is correct
12 Correct 175 ms 12472 KB Output is correct
13 Correct 151 ms 11724 KB Output is correct
14 Correct 205 ms 12488 KB Output is correct
15 Correct 180 ms 11716 KB Output is correct
16 Correct 199 ms 12460 KB Output is correct
17 Correct 209 ms 11644 KB Output is correct
18 Correct 91 ms 2892 KB Output is correct
19 Correct 391 ms 22728 KB Output is correct
20 Correct 357 ms 20288 KB Output is correct
21 Correct 267 ms 24108 KB Output is correct
22 Correct 256 ms 21724 KB Output is correct
23 Correct 243 ms 14068 KB Output is correct
24 Correct 203 ms 12880 KB Output is correct
25 Correct 327 ms 25152 KB Output is correct
26 Correct 338 ms 23160 KB Output is correct
27 Correct 334 ms 25528 KB Output is correct
28 Correct 369 ms 23136 KB Output is correct
29 Correct 382 ms 25060 KB Output is correct
30 Correct 266 ms 14080 KB Output is correct
31 Correct 427 ms 25436 KB Output is correct
32 Correct 375 ms 22604 KB Output is correct
33 Correct 256 ms 12740 KB Output is correct
34 Correct 388 ms 23152 KB Output is correct
35 Correct 340 ms 22364 KB Output is correct
36 Correct 221 ms 12924 KB Output is correct
37 Correct 234 ms 12788 KB Output is correct
38 Correct 293 ms 17596 KB Output is correct
39 Correct 165 ms 15336 KB Output is correct
40 Correct 304 ms 18160 KB Output is correct
41 Correct 220 ms 13568 KB Output is correct
42 Correct 52 ms 9448 KB Output is correct
43 Correct 170 ms 10572 KB Output is correct
44 Correct 112 ms 4524 KB Output is correct
45 Correct 158 ms 11872 KB Output is correct
46 Correct 134 ms 10052 KB Output is correct
47 Correct 161 ms 11944 KB Output is correct
48 Correct 150 ms 10760 KB Output is correct
49 Correct 158 ms 11832 KB Output is correct
50 Correct 123 ms 10536 KB Output is correct
51 Correct 141 ms 11848 KB Output is correct
52 Correct 123 ms 10744 KB Output is correct
53 Correct 178 ms 11288 KB Output is correct
54 Correct 138 ms 10188 KB Output is correct
55 Correct 165 ms 12056 KB Output is correct
56 Correct 141 ms 12004 KB Output is correct
57 Correct 147 ms 11468 KB Output is correct
58 Correct 167 ms 10544 KB Output is correct
59 Correct 193 ms 12484 KB Output is correct
60 Correct 145 ms 11748 KB Output is correct
61 Correct 142 ms 12440 KB Output is correct
62 Correct 145 ms 11752 KB Output is correct
63 Correct 156 ms 12428 KB Output is correct
64 Correct 146 ms 11692 KB Output is correct
65 Correct 143 ms 12392 KB Output is correct
66 Correct 155 ms 11780 KB Output is correct
67 Correct 150 ms 11032 KB Output is correct
68 Correct 176 ms 11344 KB Output is correct
69 Correct 449 ms 21360 KB Output is correct
70 Correct 512 ms 20284 KB Output is correct
71 Correct 202 ms 12780 KB Output is correct
72 Correct 230 ms 12908 KB Output is correct
73 Correct 190 ms 12876 KB Output is correct
74 Correct 272 ms 23260 KB Output is correct
75 Correct 213 ms 14160 KB Output is correct
76 Correct 362 ms 25096 KB Output is correct
77 Correct 297 ms 22104 KB Output is correct
78 Correct 200 ms 12916 KB Output is correct
79 Correct 209 ms 12864 KB Output is correct
80 Correct 387 ms 22488 KB Output is correct
81 Correct 229 ms 14200 KB Output is correct
82 Correct 500 ms 25208 KB Output is correct
83 Correct 427 ms 22616 KB Output is correct
84 Correct 270 ms 12852 KB Output is correct
85 Correct 192 ms 12828 KB Output is correct
86 Correct 375 ms 21572 KB Output is correct
87 Correct 455 ms 23224 KB Output is correct
88 Correct 198 ms 12216 KB Output is correct
89 Correct 471 ms 22176 KB Output is correct
90 Correct 432 ms 23452 KB Output is correct
91 Correct 303 ms 12196 KB Output is correct
92 Correct 422 ms 22356 KB Output is correct
93 Correct 217 ms 12912 KB Output is correct
94 Correct 227 ms 12972 KB Output is correct
95 Correct 258 ms 12852 KB Output is correct
96 Correct 303 ms 17872 KB Output is correct
97 Correct 330 ms 16660 KB Output is correct
98 Correct 422 ms 18188 KB Output is correct
99 Correct 419 ms 15108 KB Output is correct
100 Correct 245 ms 11032 KB Output is correct