Submission #423473

# Submission time Handle Problem Language Result Execution time Memory
423473 2021-06-11T07:48:32 Z 최서현(#7497) Crossing (JOI21_crossing) C++17
100 / 100
4106 ms 45032 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <string>
#include <map>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG
const int INF = (int)1e9 + 7;

using namespace std;

string d;

struct SEG
{
    string a;
    int nxt[202020];

    SEG(int n, string _a) : a(_a)
    {
        int pr = 0;
        for(int i = 1; i < n; ++i)
        {
            if(a[pr] != a[i])
            {
                for(int j = pr; j < i; ++j) nxt[j] = i;
                pr = i;
            }
        }
        for(int j = pr; j < n; ++j) nxt[j] = n;
    }

    struct Node
    {
        char c;
        bool con, val;
    }seg[808080];

    void prop(int ind, int s, int e)
    {
        if(seg[ind].con)
        {
            int x = ind << 1, y = ind << 1 | 1;
            seg[x].con = seg[y].con = true;
            seg[x].c = seg[y].c = seg[ind].c;

            int mid = s + e >> 1;
            seg[x].val = (a[s] == seg[x].c && nxt[s] >= mid);
            seg[y].val = (a[mid] == seg[y].c && nxt[mid] >= e);
        }
    }

    void mrge(int ind)
    {
        Node &nd = seg[ind], &x = seg[ind << 1], &y = seg[ind << 1 | 1];
        if(x.con && y.con && x.c == y.c) nd.c = x.c, nd.con = true;
        else nd.con = false;
        nd.val = (x.val && y.val);
    }

    void init(int ind, int s, int e)
    {
        if(s + 1 == e)
        {
            seg[ind].c = d[s];
            seg[ind].con = true;
            seg[ind].val = (a[s] == d[s]);
            return;
        }

        int mid = s + e >> 1;
        init(ind << 1, s, mid);
        init(ind << 1 | 1, mid, e);
        mrge(ind);
    }

    void upd(int ind, int s, int e, int l, int r, char c)
    {
        if(e <= l || r <= s) return;
        if(l <= s && e <= r)
        {
            seg[ind].con = true;
            seg[ind].c = c;
            seg[ind].val = (a[s] == seg[ind].c && nxt[s] >= e);
            return;
        }

        prop(ind, s, e);
        int mid = s + e >> 1;
        upd(ind << 1, s, mid, l, r, c);
        upd(ind << 1 | 1, mid, e, l, r, c);
        mrge(ind);
    }
};
vector<SEG> seg;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    string a, b, c;
    cin >> a >> b >> c;

    map<char, int> MM;
    MM['I'] = 0;
    MM['J'] = 1;
    MM['O'] = 2;
    map<int, char> MMM;
    MMM[0] = 'I';
    MMM[1] = 'J';
    MMM[2] = 'O';

    for(int i = 0; i < 3; ++i)
    {
        for(int j = 0; j < 3; ++j)
        {
            for(int k = 0; k < 3; ++k)
            {
                if((i + j + k) % 3 == 1)
                {
                    string s;
                    for(int l = 0; l < n; ++l)
                        s += MMM[(i * MM[a[l]] + j * MM[b[l]] + k * MM[c[l]]) % 3];
                    seg.emplace_back(n, s);
                }
            }
        }
    }

    int T; cin >> T >> d;
    bool flag = false;
    for(auto &s : seg)
    {
        s.init(1, 0, n);
        if(s.seg[1].val) flag = true;
    }
    cout << (flag ? "Yes\n" : "No\n");

    while(T--)
    {
        int l, r; char c; cin >> l >> r >> c; --l;
        flag = false;
        for(auto &s : seg)
        {
            s.upd(1, 0, n, l, r, c);
            if(s.seg[1].val) flag = true;
        }
        cout << (flag ? "Yes\n" : "No\n");
    }
}

Compilation message

Main.cpp: In member function 'void SEG::prop(int, int, int)':
Main.cpp:58:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |             int mid = s + e >> 1;
      |                       ~~^~~
Main.cpp: In member function 'void SEG::init(int, int, int)':
Main.cpp:82:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |         int mid = s + e >> 1;
      |                   ~~^~~
Main.cpp: In member function 'void SEG::upd(int, int, int, int, int, char)':
Main.cpp:100:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  100 |         int mid = s + e >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 403 ms 38268 KB Output is correct
2 Correct 442 ms 38356 KB Output is correct
3 Correct 465 ms 38292 KB Output is correct
4 Correct 352 ms 38336 KB Output is correct
5 Correct 316 ms 38312 KB Output is correct
6 Correct 337 ms 38336 KB Output is correct
7 Correct 324 ms 38316 KB Output is correct
8 Correct 354 ms 38236 KB Output is correct
9 Correct 346 ms 38336 KB Output is correct
10 Correct 346 ms 38308 KB Output is correct
11 Correct 346 ms 38336 KB Output is correct
12 Correct 341 ms 38236 KB Output is correct
13 Correct 359 ms 38204 KB Output is correct
14 Correct 344 ms 38268 KB Output is correct
15 Correct 352 ms 38280 KB Output is correct
16 Correct 346 ms 38336 KB Output is correct
17 Correct 346 ms 38244 KB Output is correct
18 Correct 372 ms 38236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 38268 KB Output is correct
2 Correct 442 ms 38356 KB Output is correct
3 Correct 465 ms 38292 KB Output is correct
4 Correct 352 ms 38336 KB Output is correct
5 Correct 316 ms 38312 KB Output is correct
6 Correct 337 ms 38336 KB Output is correct
7 Correct 324 ms 38316 KB Output is correct
8 Correct 354 ms 38236 KB Output is correct
9 Correct 346 ms 38336 KB Output is correct
10 Correct 346 ms 38308 KB Output is correct
11 Correct 346 ms 38336 KB Output is correct
12 Correct 341 ms 38236 KB Output is correct
13 Correct 359 ms 38204 KB Output is correct
14 Correct 344 ms 38268 KB Output is correct
15 Correct 352 ms 38280 KB Output is correct
16 Correct 346 ms 38336 KB Output is correct
17 Correct 346 ms 38244 KB Output is correct
18 Correct 372 ms 38236 KB Output is correct
19 Correct 3176 ms 44952 KB Output is correct
20 Correct 2223 ms 45000 KB Output is correct
21 Correct 1359 ms 44612 KB Output is correct
22 Correct 1570 ms 43920 KB Output is correct
23 Correct 709 ms 38688 KB Output is correct
24 Correct 714 ms 38684 KB Output is correct
25 Correct 1598 ms 44928 KB Output is correct
26 Correct 1793 ms 44952 KB Output is correct
27 Correct 1926 ms 44976 KB Output is correct
28 Correct 2060 ms 44952 KB Output is correct
29 Correct 1891 ms 44748 KB Output is correct
30 Correct 795 ms 38672 KB Output is correct
31 Correct 1919 ms 44904 KB Output is correct
32 Correct 1853 ms 44316 KB Output is correct
33 Correct 727 ms 38696 KB Output is correct
34 Correct 1980 ms 44948 KB Output is correct
35 Correct 1299 ms 43256 KB Output is correct
36 Correct 713 ms 38676 KB Output is correct
37 Correct 721 ms 38664 KB Output is correct
38 Correct 1700 ms 44964 KB Output is correct
39 Correct 871 ms 44900 KB Output is correct
40 Correct 1301 ms 42696 KB Output is correct
41 Correct 4106 ms 44956 KB Output is correct
42 Correct 141 ms 44992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 38268 KB Output is correct
2 Correct 442 ms 38356 KB Output is correct
3 Correct 465 ms 38292 KB Output is correct
4 Correct 352 ms 38336 KB Output is correct
5 Correct 316 ms 38312 KB Output is correct
6 Correct 337 ms 38336 KB Output is correct
7 Correct 324 ms 38316 KB Output is correct
8 Correct 354 ms 38236 KB Output is correct
9 Correct 346 ms 38336 KB Output is correct
10 Correct 346 ms 38308 KB Output is correct
11 Correct 346 ms 38336 KB Output is correct
12 Correct 341 ms 38236 KB Output is correct
13 Correct 359 ms 38204 KB Output is correct
14 Correct 344 ms 38268 KB Output is correct
15 Correct 352 ms 38280 KB Output is correct
16 Correct 346 ms 38336 KB Output is correct
17 Correct 346 ms 38244 KB Output is correct
18 Correct 372 ms 38236 KB Output is correct
19 Correct 494 ms 38360 KB Output is correct
20 Correct 534 ms 38328 KB Output is correct
21 Correct 380 ms 38336 KB Output is correct
22 Correct 323 ms 38336 KB Output is correct
23 Correct 367 ms 38284 KB Output is correct
24 Correct 383 ms 38336 KB Output is correct
25 Correct 379 ms 38352 KB Output is correct
26 Correct 347 ms 38276 KB Output is correct
27 Correct 372 ms 38324 KB Output is correct
28 Correct 336 ms 38328 KB Output is correct
29 Correct 392 ms 38332 KB Output is correct
30 Correct 331 ms 38328 KB Output is correct
31 Correct 384 ms 38300 KB Output is correct
32 Correct 380 ms 38336 KB Output is correct
33 Correct 404 ms 38356 KB Output is correct
34 Correct 354 ms 38328 KB Output is correct
35 Correct 394 ms 38240 KB Output is correct
36 Correct 389 ms 38336 KB Output is correct
37 Correct 376 ms 38336 KB Output is correct
38 Correct 402 ms 38240 KB Output is correct
39 Correct 378 ms 38340 KB Output is correct
40 Correct 402 ms 38336 KB Output is correct
41 Correct 385 ms 38284 KB Output is correct
42 Correct 397 ms 38336 KB Output is correct
43 Correct 378 ms 38308 KB Output is correct
44 Correct 438 ms 38316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 38268 KB Output is correct
2 Correct 442 ms 38356 KB Output is correct
3 Correct 465 ms 38292 KB Output is correct
4 Correct 352 ms 38336 KB Output is correct
5 Correct 316 ms 38312 KB Output is correct
6 Correct 337 ms 38336 KB Output is correct
7 Correct 324 ms 38316 KB Output is correct
8 Correct 354 ms 38236 KB Output is correct
9 Correct 346 ms 38336 KB Output is correct
10 Correct 346 ms 38308 KB Output is correct
11 Correct 346 ms 38336 KB Output is correct
12 Correct 341 ms 38236 KB Output is correct
13 Correct 359 ms 38204 KB Output is correct
14 Correct 344 ms 38268 KB Output is correct
15 Correct 352 ms 38280 KB Output is correct
16 Correct 346 ms 38336 KB Output is correct
17 Correct 346 ms 38244 KB Output is correct
18 Correct 372 ms 38236 KB Output is correct
19 Correct 3176 ms 44952 KB Output is correct
20 Correct 2223 ms 45000 KB Output is correct
21 Correct 1359 ms 44612 KB Output is correct
22 Correct 1570 ms 43920 KB Output is correct
23 Correct 709 ms 38688 KB Output is correct
24 Correct 714 ms 38684 KB Output is correct
25 Correct 1598 ms 44928 KB Output is correct
26 Correct 1793 ms 44952 KB Output is correct
27 Correct 1926 ms 44976 KB Output is correct
28 Correct 2060 ms 44952 KB Output is correct
29 Correct 1891 ms 44748 KB Output is correct
30 Correct 795 ms 38672 KB Output is correct
31 Correct 1919 ms 44904 KB Output is correct
32 Correct 1853 ms 44316 KB Output is correct
33 Correct 727 ms 38696 KB Output is correct
34 Correct 1980 ms 44948 KB Output is correct
35 Correct 1299 ms 43256 KB Output is correct
36 Correct 713 ms 38676 KB Output is correct
37 Correct 721 ms 38664 KB Output is correct
38 Correct 1700 ms 44964 KB Output is correct
39 Correct 871 ms 44900 KB Output is correct
40 Correct 1301 ms 42696 KB Output is correct
41 Correct 4106 ms 44956 KB Output is correct
42 Correct 141 ms 44992 KB Output is correct
43 Correct 494 ms 38360 KB Output is correct
44 Correct 534 ms 38328 KB Output is correct
45 Correct 380 ms 38336 KB Output is correct
46 Correct 323 ms 38336 KB Output is correct
47 Correct 367 ms 38284 KB Output is correct
48 Correct 383 ms 38336 KB Output is correct
49 Correct 379 ms 38352 KB Output is correct
50 Correct 347 ms 38276 KB Output is correct
51 Correct 372 ms 38324 KB Output is correct
52 Correct 336 ms 38328 KB Output is correct
53 Correct 392 ms 38332 KB Output is correct
54 Correct 331 ms 38328 KB Output is correct
55 Correct 384 ms 38300 KB Output is correct
56 Correct 380 ms 38336 KB Output is correct
57 Correct 404 ms 38356 KB Output is correct
58 Correct 354 ms 38328 KB Output is correct
59 Correct 394 ms 38240 KB Output is correct
60 Correct 389 ms 38336 KB Output is correct
61 Correct 376 ms 38336 KB Output is correct
62 Correct 402 ms 38240 KB Output is correct
63 Correct 378 ms 38340 KB Output is correct
64 Correct 402 ms 38336 KB Output is correct
65 Correct 385 ms 38284 KB Output is correct
66 Correct 397 ms 38336 KB Output is correct
67 Correct 378 ms 38308 KB Output is correct
68 Correct 438 ms 38316 KB Output is correct
69 Correct 3102 ms 43988 KB Output is correct
70 Correct 2505 ms 44944 KB Output is correct
71 Correct 785 ms 38680 KB Output is correct
72 Correct 800 ms 38688 KB Output is correct
73 Correct 834 ms 38688 KB Output is correct
74 Correct 1461 ms 43924 KB Output is correct
75 Correct 800 ms 38720 KB Output is correct
76 Correct 1695 ms 45000 KB Output is correct
77 Correct 1902 ms 43892 KB Output is correct
78 Correct 788 ms 38668 KB Output is correct
79 Correct 770 ms 38640 KB Output is correct
80 Correct 1466 ms 43024 KB Output is correct
81 Correct 776 ms 38684 KB Output is correct
82 Correct 1679 ms 44952 KB Output is correct
83 Correct 1912 ms 44516 KB Output is correct
84 Correct 827 ms 38696 KB Output is correct
85 Correct 765 ms 38716 KB Output is correct
86 Correct 2109 ms 43552 KB Output is correct
87 Correct 2190 ms 44928 KB Output is correct
88 Correct 945 ms 38664 KB Output is correct
89 Correct 1899 ms 44228 KB Output is correct
90 Correct 2262 ms 44924 KB Output is correct
91 Correct 920 ms 38632 KB Output is correct
92 Correct 1447 ms 43336 KB Output is correct
93 Correct 788 ms 38668 KB Output is correct
94 Correct 816 ms 38696 KB Output is correct
95 Correct 875 ms 38692 KB Output is correct
96 Correct 1897 ms 44916 KB Output is correct
97 Correct 919 ms 44932 KB Output is correct
98 Correct 1489 ms 42828 KB Output is correct
99 Correct 4070 ms 45032 KB Output is correct
100 Correct 178 ms 44904 KB Output is correct