Submission #1100285

# Submission time Handle Problem Language Result Execution time Memory
1100285 2024-10-13T12:32:08 Z MateiKing80 Joker (BOI20_joker) C++14
100 / 100
1029 ms 25272 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct DSU
{
    int path[400400], rnk[400400];
    vector<array<int, 3>> st;

    void init(int n)
    {
        st.clear();
        for(int i = 1; i <= n; i ++)
            path[i] = i, rnk[i] = 0;
    }
    int realpapa(int s)
    {
        if(s == path[s])
            return s;
        return realpapa(path[s]);
    }
    void unite(int x, int y)
    {
        x = realpapa(x), y = realpapa(y);
        if(x == y)
        {
            st.push_back({-1, -1, -1});
            return;
        }
        if(rnk[x] > rnk[y])
            swap(x, y);
        st.push_back({x, y, rnk[y]});
        path[x] = y;
        if(rnk[x] == rnk[y])
            rnk[y] ++;
    }
    void pop(int cnt)
    {
        for(int i = 1; i <= cnt; i ++)
        {
            auto [x, y, r] = st.back();
            st.pop_back();
            if(x == -1)
                continue;
            path[x] = x;
            rnk[y] = r;
        }
    }
} dsu;

int a[400400], b[400400], ans[400400], sz;

void rollback(int t)
{
    dsu.pop((sz - t) * 2);
    sz = t;
}

int push(int i)
{
    dsu.unite(a[i] * 2, b[i] * 2 + 1);
    dsu.unite(a[i] * 2 + 1, b[i] * 2);
    sz ++;
    if(dsu.realpapa(a[i] * 2) == dsu.realpapa(a[i] * 2 + 1))
        return 0;
    return 1;
}

void solve(int l, int r, int s, int e)
{
    if(l > r)
        return;
    int m = (l + r) >> 1;
    int t1 = sz;
    for(int i = min(r, s - 1); i >= m; i --)
        push(i);
    int t2 = sz;
    for(int i = max(s, m); i <= e; i ++)
    {
        if(!push(i))
            break;
        ans[m] = i;
    }
    rollback(t2);
    solve(l, m - 1, s, ans[m]);
    rollback(t1);
    for(int i = max(r + 1, s); i <= ans[m] - 1; i ++)
        push(i);
    solve(m + 1, r, ans[m], e);
    rollback(t1);
}

int main()
{
    int n, m, q;
    cin >> n >> m >> q;
    for(int i = 1; i <= m; i ++)
        cin >> a[i] >> b[i];
    for(int i = 1; i <= m; i ++)
        a[i + m] = a[i], b[i + m] = b[i];
    dsu.init(n * 2 + 3);
    solve(1, m * 2, 1, m * 2);
    while(q --)
    {
        int l, r;
        cin >> l >> r;
        int ll = r + 1, rr = l - 1 + m;
        if(ans[ll] >= rr)
            cout << "NO\n";
        else
            cout << "YES\n";
    }
}

Compilation message

Joker.cpp: In member function 'void DSU::pop(int)':
Joker.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |             auto [x, y, r] = st.back();
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 2 ms 6652 KB Output is correct
6 Correct 1 ms 6484 KB Output is correct
7 Correct 2 ms 6484 KB Output is correct
8 Correct 2 ms 6484 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 2 ms 6484 KB Output is correct
12 Correct 2 ms 6484 KB Output is correct
13 Correct 2 ms 6484 KB Output is correct
14 Correct 2 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 2 ms 6484 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6484 KB Output is correct
20 Correct 2 ms 6648 KB Output is correct
21 Correct 2 ms 6484 KB Output is correct
22 Correct 2 ms 6484 KB Output is correct
23 Correct 2 ms 6484 KB Output is correct
24 Correct 2 ms 6484 KB Output is correct
25 Correct 2 ms 6484 KB Output is correct
26 Correct 2 ms 6484 KB Output is correct
27 Correct 2 ms 6592 KB Output is correct
28 Correct 2 ms 6652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 2 ms 6652 KB Output is correct
6 Correct 1 ms 6484 KB Output is correct
7 Correct 2 ms 6484 KB Output is correct
8 Correct 2 ms 6484 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 2 ms 6484 KB Output is correct
12 Correct 2 ms 6484 KB Output is correct
13 Correct 2 ms 6484 KB Output is correct
14 Correct 2 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 2 ms 6484 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6484 KB Output is correct
20 Correct 2 ms 6648 KB Output is correct
21 Correct 2 ms 6484 KB Output is correct
22 Correct 2 ms 6484 KB Output is correct
23 Correct 2 ms 6484 KB Output is correct
24 Correct 2 ms 6484 KB Output is correct
25 Correct 2 ms 6484 KB Output is correct
26 Correct 2 ms 6484 KB Output is correct
27 Correct 2 ms 6592 KB Output is correct
28 Correct 2 ms 6652 KB Output is correct
29 Correct 6 ms 6484 KB Output is correct
30 Correct 8 ms 6484 KB Output is correct
31 Correct 7 ms 6484 KB Output is correct
32 Correct 7 ms 6484 KB Output is correct
33 Correct 8 ms 6484 KB Output is correct
34 Correct 8 ms 6644 KB Output is correct
35 Correct 8 ms 6740 KB Output is correct
36 Correct 8 ms 6632 KB Output is correct
37 Correct 7 ms 6748 KB Output is correct
38 Correct 8 ms 6752 KB Output is correct
39 Correct 7 ms 6752 KB Output is correct
40 Correct 7 ms 6648 KB Output is correct
41 Correct 8 ms 6708 KB Output is correct
42 Correct 7 ms 6484 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 7 ms 6484 KB Output is correct
45 Correct 7 ms 6484 KB Output is correct
46 Correct 7 ms 6484 KB Output is correct
47 Correct 7 ms 6692 KB Output is correct
48 Correct 8 ms 6484 KB Output is correct
49 Correct 7 ms 6484 KB Output is correct
50 Correct 9 ms 6740 KB Output is correct
51 Correct 7 ms 6484 KB Output is correct
52 Correct 7 ms 6484 KB Output is correct
53 Correct 7 ms 6484 KB Output is correct
54 Correct 7 ms 6740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 706 ms 14492 KB Output is correct
4 Correct 781 ms 25272 KB Output is correct
5 Correct 823 ms 19380 KB Output is correct
6 Correct 697 ms 14516 KB Output is correct
7 Correct 707 ms 14520 KB Output is correct
8 Correct 958 ms 13608 KB Output is correct
9 Correct 988 ms 13852 KB Output is correct
10 Correct 997 ms 15136 KB Output is correct
11 Correct 808 ms 14312 KB Output is correct
12 Correct 805 ms 15544 KB Output is correct
13 Correct 962 ms 13688 KB Output is correct
14 Correct 961 ms 14216 KB Output is correct
15 Correct 891 ms 14876 KB Output is correct
16 Correct 891 ms 15544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 2 ms 6652 KB Output is correct
6 Correct 1 ms 6484 KB Output is correct
7 Correct 2 ms 6484 KB Output is correct
8 Correct 2 ms 6484 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 2 ms 6484 KB Output is correct
12 Correct 2 ms 6484 KB Output is correct
13 Correct 2 ms 6484 KB Output is correct
14 Correct 2 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 2 ms 6484 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6484 KB Output is correct
20 Correct 2 ms 6648 KB Output is correct
21 Correct 2 ms 6484 KB Output is correct
22 Correct 2 ms 6484 KB Output is correct
23 Correct 2 ms 6484 KB Output is correct
24 Correct 2 ms 6484 KB Output is correct
25 Correct 2 ms 6484 KB Output is correct
26 Correct 2 ms 6484 KB Output is correct
27 Correct 2 ms 6592 KB Output is correct
28 Correct 2 ms 6652 KB Output is correct
29 Correct 706 ms 14492 KB Output is correct
30 Correct 781 ms 25272 KB Output is correct
31 Correct 823 ms 19380 KB Output is correct
32 Correct 697 ms 14516 KB Output is correct
33 Correct 707 ms 14520 KB Output is correct
34 Correct 958 ms 13608 KB Output is correct
35 Correct 988 ms 13852 KB Output is correct
36 Correct 997 ms 15136 KB Output is correct
37 Correct 808 ms 14312 KB Output is correct
38 Correct 805 ms 15544 KB Output is correct
39 Correct 962 ms 13688 KB Output is correct
40 Correct 961 ms 14216 KB Output is correct
41 Correct 891 ms 14876 KB Output is correct
42 Correct 891 ms 15544 KB Output is correct
43 Correct 749 ms 14776 KB Output is correct
44 Correct 851 ms 25016 KB Output is correct
45 Correct 925 ms 19376 KB Output is correct
46 Correct 758 ms 14776 KB Output is correct
47 Correct 738 ms 14916 KB Output is correct
48 Correct 928 ms 14524 KB Output is correct
49 Correct 1029 ms 15604 KB Output is correct
50 Correct 824 ms 14512 KB Output is correct
51 Correct 825 ms 15288 KB Output is correct
52 Correct 864 ms 16140 KB Output is correct
53 Correct 904 ms 14008 KB Output is correct
54 Correct 1010 ms 14532 KB Output is correct
55 Correct 926 ms 15188 KB Output is correct
56 Correct 959 ms 15756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 2 ms 6652 KB Output is correct
6 Correct 1 ms 6484 KB Output is correct
7 Correct 2 ms 6484 KB Output is correct
8 Correct 2 ms 6484 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 2 ms 6484 KB Output is correct
12 Correct 2 ms 6484 KB Output is correct
13 Correct 2 ms 6484 KB Output is correct
14 Correct 2 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 2 ms 6484 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6484 KB Output is correct
20 Correct 2 ms 6648 KB Output is correct
21 Correct 2 ms 6484 KB Output is correct
22 Correct 2 ms 6484 KB Output is correct
23 Correct 2 ms 6484 KB Output is correct
24 Correct 2 ms 6484 KB Output is correct
25 Correct 2 ms 6484 KB Output is correct
26 Correct 2 ms 6484 KB Output is correct
27 Correct 2 ms 6592 KB Output is correct
28 Correct 2 ms 6652 KB Output is correct
29 Correct 6 ms 6484 KB Output is correct
30 Correct 8 ms 6484 KB Output is correct
31 Correct 7 ms 6484 KB Output is correct
32 Correct 7 ms 6484 KB Output is correct
33 Correct 8 ms 6484 KB Output is correct
34 Correct 8 ms 6644 KB Output is correct
35 Correct 8 ms 6740 KB Output is correct
36 Correct 8 ms 6632 KB Output is correct
37 Correct 7 ms 6748 KB Output is correct
38 Correct 8 ms 6752 KB Output is correct
39 Correct 7 ms 6752 KB Output is correct
40 Correct 7 ms 6648 KB Output is correct
41 Correct 8 ms 6708 KB Output is correct
42 Correct 7 ms 6484 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 7 ms 6484 KB Output is correct
45 Correct 7 ms 6484 KB Output is correct
46 Correct 7 ms 6484 KB Output is correct
47 Correct 7 ms 6692 KB Output is correct
48 Correct 8 ms 6484 KB Output is correct
49 Correct 7 ms 6484 KB Output is correct
50 Correct 9 ms 6740 KB Output is correct
51 Correct 7 ms 6484 KB Output is correct
52 Correct 7 ms 6484 KB Output is correct
53 Correct 7 ms 6484 KB Output is correct
54 Correct 7 ms 6740 KB Output is correct
55 Correct 388 ms 13216 KB Output is correct
56 Correct 459 ms 25024 KB Output is correct
57 Correct 508 ms 17560 KB Output is correct
58 Correct 391 ms 13248 KB Output is correct
59 Correct 559 ms 13260 KB Output is correct
60 Correct 532 ms 13856 KB Output is correct
61 Correct 439 ms 13248 KB Output is correct
62 Correct 524 ms 13988 KB Output is correct
63 Correct 565 ms 12736 KB Output is correct
64 Correct 509 ms 13364 KB Output is correct
65 Correct 517 ms 13980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6484 KB Output is correct
2 Correct 1 ms 6484 KB Output is correct
3 Correct 1 ms 6648 KB Output is correct
4 Correct 1 ms 6484 KB Output is correct
5 Correct 2 ms 6652 KB Output is correct
6 Correct 1 ms 6484 KB Output is correct
7 Correct 2 ms 6484 KB Output is correct
8 Correct 2 ms 6484 KB Output is correct
9 Correct 2 ms 6484 KB Output is correct
10 Correct 2 ms 6484 KB Output is correct
11 Correct 2 ms 6484 KB Output is correct
12 Correct 2 ms 6484 KB Output is correct
13 Correct 2 ms 6484 KB Output is correct
14 Correct 2 ms 6484 KB Output is correct
15 Correct 2 ms 6484 KB Output is correct
16 Correct 2 ms 6484 KB Output is correct
17 Correct 2 ms 6484 KB Output is correct
18 Correct 2 ms 6652 KB Output is correct
19 Correct 2 ms 6484 KB Output is correct
20 Correct 2 ms 6648 KB Output is correct
21 Correct 2 ms 6484 KB Output is correct
22 Correct 2 ms 6484 KB Output is correct
23 Correct 2 ms 6484 KB Output is correct
24 Correct 2 ms 6484 KB Output is correct
25 Correct 2 ms 6484 KB Output is correct
26 Correct 2 ms 6484 KB Output is correct
27 Correct 2 ms 6592 KB Output is correct
28 Correct 2 ms 6652 KB Output is correct
29 Correct 6 ms 6484 KB Output is correct
30 Correct 8 ms 6484 KB Output is correct
31 Correct 7 ms 6484 KB Output is correct
32 Correct 7 ms 6484 KB Output is correct
33 Correct 8 ms 6484 KB Output is correct
34 Correct 8 ms 6644 KB Output is correct
35 Correct 8 ms 6740 KB Output is correct
36 Correct 8 ms 6632 KB Output is correct
37 Correct 7 ms 6748 KB Output is correct
38 Correct 8 ms 6752 KB Output is correct
39 Correct 7 ms 6752 KB Output is correct
40 Correct 7 ms 6648 KB Output is correct
41 Correct 8 ms 6708 KB Output is correct
42 Correct 7 ms 6484 KB Output is correct
43 Correct 7 ms 6484 KB Output is correct
44 Correct 7 ms 6484 KB Output is correct
45 Correct 7 ms 6484 KB Output is correct
46 Correct 7 ms 6484 KB Output is correct
47 Correct 7 ms 6692 KB Output is correct
48 Correct 8 ms 6484 KB Output is correct
49 Correct 7 ms 6484 KB Output is correct
50 Correct 9 ms 6740 KB Output is correct
51 Correct 7 ms 6484 KB Output is correct
52 Correct 7 ms 6484 KB Output is correct
53 Correct 7 ms 6484 KB Output is correct
54 Correct 7 ms 6740 KB Output is correct
55 Correct 706 ms 14492 KB Output is correct
56 Correct 781 ms 25272 KB Output is correct
57 Correct 823 ms 19380 KB Output is correct
58 Correct 697 ms 14516 KB Output is correct
59 Correct 707 ms 14520 KB Output is correct
60 Correct 958 ms 13608 KB Output is correct
61 Correct 988 ms 13852 KB Output is correct
62 Correct 997 ms 15136 KB Output is correct
63 Correct 808 ms 14312 KB Output is correct
64 Correct 805 ms 15544 KB Output is correct
65 Correct 962 ms 13688 KB Output is correct
66 Correct 961 ms 14216 KB Output is correct
67 Correct 891 ms 14876 KB Output is correct
68 Correct 891 ms 15544 KB Output is correct
69 Correct 749 ms 14776 KB Output is correct
70 Correct 851 ms 25016 KB Output is correct
71 Correct 925 ms 19376 KB Output is correct
72 Correct 758 ms 14776 KB Output is correct
73 Correct 738 ms 14916 KB Output is correct
74 Correct 928 ms 14524 KB Output is correct
75 Correct 1029 ms 15604 KB Output is correct
76 Correct 824 ms 14512 KB Output is correct
77 Correct 825 ms 15288 KB Output is correct
78 Correct 864 ms 16140 KB Output is correct
79 Correct 904 ms 14008 KB Output is correct
80 Correct 1010 ms 14532 KB Output is correct
81 Correct 926 ms 15188 KB Output is correct
82 Correct 959 ms 15756 KB Output is correct
83 Correct 388 ms 13216 KB Output is correct
84 Correct 459 ms 25024 KB Output is correct
85 Correct 508 ms 17560 KB Output is correct
86 Correct 391 ms 13248 KB Output is correct
87 Correct 559 ms 13260 KB Output is correct
88 Correct 532 ms 13856 KB Output is correct
89 Correct 439 ms 13248 KB Output is correct
90 Correct 524 ms 13988 KB Output is correct
91 Correct 565 ms 12736 KB Output is correct
92 Correct 509 ms 13364 KB Output is correct
93 Correct 517 ms 13980 KB Output is correct
94 Correct 735 ms 15384 KB Output is correct
95 Correct 854 ms 20144 KB Output is correct
96 Correct 812 ms 20060 KB Output is correct
97 Correct 810 ms 15492 KB Output is correct
98 Correct 739 ms 15680 KB Output is correct
99 Correct 876 ms 15032 KB Output is correct
100 Correct 989 ms 16704 KB Output is correct
101 Correct 821 ms 15292 KB Output is correct
102 Correct 879 ms 15880 KB Output is correct
103 Correct 919 ms 16860 KB Output is correct
104 Correct 932 ms 15008 KB Output is correct
105 Correct 993 ms 15768 KB Output is correct
106 Correct 906 ms 16312 KB Output is correct
107 Correct 772 ms 20284 KB Output is correct
108 Correct 734 ms 15400 KB Output is correct
109 Correct 748 ms 15288 KB Output is correct
110 Correct 753 ms 15408 KB Output is correct
111 Correct 834 ms 15288 KB Output is correct
112 Correct 741 ms 15408 KB Output is correct
113 Correct 802 ms 15320 KB Output is correct
114 Correct 737 ms 15324 KB Output is correct
115 Correct 783 ms 15316 KB Output is correct
116 Correct 747 ms 15268 KB Output is correct