Submission #561296

# Submission time Handle Problem Language Result Execution time Memory
561296 2022-05-12T15:25:40 Z messiuuuuu Joker (BOI20_joker) C++14
100 / 100
194 ms 11216 KB
#include<bits/stdc++.h>
#define task "F"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 2e5 + 5;
const ll INF = 1e18 + 5;

int n, m, q;
pair<int, int> es[MAXN];

void Input()
{
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++)
        cin >> es[i].fi >> es[i].se;
}

struct TRback
{
    int u, lu, v, lv, parev;
};

stack<TRback> Q;

int lab[MAXN], f[MAXN];
bool pare[MAXN];

pair<int, int> FindSet(int u)
{
    bool w = 0;
    while (lab[u] > 0)
    {
        w ^= pare[u];
        u = lab[u];
    }
    return {u, w};
}

bool Unite(int u, int v)
{
    auto pu = FindSet(u);
    auto pv = FindSet(v);
    if (pu.fi == pv.fi)
    {
        return (pu.se != pv.se);
    }
    if (lab[pu.fi] > lab[pv.fi])
        swap(pu, pv);
    u = pu.fi;
    v = pv.fi;
    Q.push({u, lab[u], v, lab[v], pare[v]});
    lab[u] += lab[v];
    lab[v] = u;
    pare[v] = pu.se ^ pv.se ^ 1;
    return 1;
}

void rollback(int sz)
{
    while (Q.size() > sz)
    {
        auto p = Q.top();
        Q.pop();
        lab[p.u] = p.lu;
        lab[p.v] = p.lv;
        pare[p.v] = p.parev;
    }
}

void Dnc(int l, int r, int pl, int pr)
{
    if (l > r)
        return;
    int mid = (l + r) / 2;
    int s = Q.size();
    bool kt = 1;
    for (int i = l; i <= mid; i++)
    {
        if (!Unite(es[i].fi, es[i].se))
        {
            kt = 0;
            break;
        }
    }
    if (kt)
    {
        int s1 = Q.size();
        f[mid] = 0;
        for (int i = min(m, pr); i >= max(mid + 1, pl); i--)
        {
            if (!Unite(es[i].fi, es[i].se))
            {
                f[mid] = i;
                break;
            }
        }

        //if (mid == 1)
         //   cerr << f[mid] << '\n';

        rollback(s1);
        Dnc(mid + 1, r, f[mid], pr);
    }
    rollback(s);
    for (int i = f[mid] + 1; i <= pr; i++)
        Unite(es[i].fi, es[i].se);
    Dnc(l, mid - 1, pl, f[mid]);
    rollback(s);
}

void Solve()
{
    memset(lab, -1, sizeof(lab));
    fill(f + 1, f + 1 + m, m + 1);

    es[0] = {n + 1, n + 2};
    Dnc(0, m, 1, m);

    //for (int i = 0; i <= m; i++)
     //   cerr << f[i] << ' ';
    //cerr << '\n';

    while (q-- > 0)
    {
        int l, r;
        cin >> l >> r;
        l--;
        r++;
        cout << (r <= f[l] ? "YES\n" : "NO\n");
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen(task".INP","r",stdin);
    //freopen(task".OUT","w",stdout);
    Input();
    Solve();
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::stack<TRback>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     while (Q.size() > sz)
      |            ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1104 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1104 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1108 KB Output is correct
30 Correct 2 ms 1148 KB Output is correct
31 Correct 2 ms 1120 KB Output is correct
32 Correct 3 ms 1108 KB Output is correct
33 Correct 2 ms 1108 KB Output is correct
34 Correct 2 ms 1108 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1108 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 2 ms 1108 KB Output is correct
39 Correct 3 ms 1108 KB Output is correct
40 Correct 2 ms 1116 KB Output is correct
41 Correct 2 ms 1108 KB Output is correct
42 Correct 2 ms 1108 KB Output is correct
43 Correct 2 ms 1148 KB Output is correct
44 Correct 2 ms 1108 KB Output is correct
45 Correct 2 ms 1108 KB Output is correct
46 Correct 3 ms 1148 KB Output is correct
47 Correct 2 ms 1148 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1144 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 3 ms 1156 KB Output is correct
53 Correct 2 ms 1108 KB Output is correct
54 Correct 2 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 130 ms 6796 KB Output is correct
4 Correct 137 ms 11176 KB Output is correct
5 Correct 118 ms 9100 KB Output is correct
6 Correct 117 ms 8916 KB Output is correct
7 Correct 106 ms 8920 KB Output is correct
8 Correct 122 ms 8316 KB Output is correct
9 Correct 125 ms 8988 KB Output is correct
10 Correct 178 ms 9292 KB Output is correct
11 Correct 129 ms 8892 KB Output is correct
12 Correct 150 ms 9104 KB Output is correct
13 Correct 122 ms 7440 KB Output is correct
14 Correct 123 ms 8372 KB Output is correct
15 Correct 158 ms 9180 KB Output is correct
16 Correct 169 ms 9112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1104 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 130 ms 6796 KB Output is correct
30 Correct 137 ms 11176 KB Output is correct
31 Correct 118 ms 9100 KB Output is correct
32 Correct 117 ms 8916 KB Output is correct
33 Correct 106 ms 8920 KB Output is correct
34 Correct 122 ms 8316 KB Output is correct
35 Correct 125 ms 8988 KB Output is correct
36 Correct 178 ms 9292 KB Output is correct
37 Correct 129 ms 8892 KB Output is correct
38 Correct 150 ms 9104 KB Output is correct
39 Correct 122 ms 7440 KB Output is correct
40 Correct 123 ms 8372 KB Output is correct
41 Correct 158 ms 9180 KB Output is correct
42 Correct 169 ms 9112 KB Output is correct
43 Correct 132 ms 8956 KB Output is correct
44 Correct 123 ms 11208 KB Output is correct
45 Correct 184 ms 11216 KB Output is correct
46 Correct 106 ms 9168 KB Output is correct
47 Correct 109 ms 9196 KB Output is correct
48 Correct 155 ms 8936 KB Output is correct
49 Correct 177 ms 9256 KB Output is correct
50 Correct 136 ms 8624 KB Output is correct
51 Correct 149 ms 9060 KB Output is correct
52 Correct 156 ms 9144 KB Output is correct
53 Correct 128 ms 7444 KB Output is correct
54 Correct 151 ms 8564 KB Output is correct
55 Correct 161 ms 9112 KB Output is correct
56 Correct 172 ms 9032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1104 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1108 KB Output is correct
30 Correct 2 ms 1148 KB Output is correct
31 Correct 2 ms 1120 KB Output is correct
32 Correct 3 ms 1108 KB Output is correct
33 Correct 2 ms 1108 KB Output is correct
34 Correct 2 ms 1108 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1108 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 2 ms 1108 KB Output is correct
39 Correct 3 ms 1108 KB Output is correct
40 Correct 2 ms 1116 KB Output is correct
41 Correct 2 ms 1108 KB Output is correct
42 Correct 2 ms 1108 KB Output is correct
43 Correct 2 ms 1148 KB Output is correct
44 Correct 2 ms 1108 KB Output is correct
45 Correct 2 ms 1108 KB Output is correct
46 Correct 3 ms 1148 KB Output is correct
47 Correct 2 ms 1148 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1144 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 3 ms 1156 KB Output is correct
53 Correct 2 ms 1108 KB Output is correct
54 Correct 2 ms 1108 KB Output is correct
55 Correct 101 ms 7904 KB Output is correct
56 Correct 105 ms 10320 KB Output is correct
57 Correct 81 ms 9804 KB Output is correct
58 Correct 72 ms 7824 KB Output is correct
59 Correct 108 ms 7540 KB Output is correct
60 Correct 146 ms 8100 KB Output is correct
61 Correct 119 ms 7592 KB Output is correct
62 Correct 107 ms 8268 KB Output is correct
63 Correct 88 ms 6556 KB Output is correct
64 Correct 114 ms 7824 KB Output is correct
65 Correct 142 ms 8176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1100 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1100 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 2 ms 1108 KB Output is correct
11 Correct 1 ms 1104 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1108 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1108 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 1 ms 1108 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 2 ms 1104 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 2 ms 1108 KB Output is correct
30 Correct 2 ms 1148 KB Output is correct
31 Correct 2 ms 1120 KB Output is correct
32 Correct 3 ms 1108 KB Output is correct
33 Correct 2 ms 1108 KB Output is correct
34 Correct 2 ms 1108 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 2 ms 1108 KB Output is correct
37 Correct 3 ms 1108 KB Output is correct
38 Correct 2 ms 1108 KB Output is correct
39 Correct 3 ms 1108 KB Output is correct
40 Correct 2 ms 1116 KB Output is correct
41 Correct 2 ms 1108 KB Output is correct
42 Correct 2 ms 1108 KB Output is correct
43 Correct 2 ms 1148 KB Output is correct
44 Correct 2 ms 1108 KB Output is correct
45 Correct 2 ms 1108 KB Output is correct
46 Correct 3 ms 1148 KB Output is correct
47 Correct 2 ms 1148 KB Output is correct
48 Correct 2 ms 1108 KB Output is correct
49 Correct 2 ms 1144 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 2 ms 1108 KB Output is correct
52 Correct 3 ms 1156 KB Output is correct
53 Correct 2 ms 1108 KB Output is correct
54 Correct 2 ms 1108 KB Output is correct
55 Correct 130 ms 6796 KB Output is correct
56 Correct 137 ms 11176 KB Output is correct
57 Correct 118 ms 9100 KB Output is correct
58 Correct 117 ms 8916 KB Output is correct
59 Correct 106 ms 8920 KB Output is correct
60 Correct 122 ms 8316 KB Output is correct
61 Correct 125 ms 8988 KB Output is correct
62 Correct 178 ms 9292 KB Output is correct
63 Correct 129 ms 8892 KB Output is correct
64 Correct 150 ms 9104 KB Output is correct
65 Correct 122 ms 7440 KB Output is correct
66 Correct 123 ms 8372 KB Output is correct
67 Correct 158 ms 9180 KB Output is correct
68 Correct 169 ms 9112 KB Output is correct
69 Correct 132 ms 8956 KB Output is correct
70 Correct 123 ms 11208 KB Output is correct
71 Correct 184 ms 11216 KB Output is correct
72 Correct 106 ms 9168 KB Output is correct
73 Correct 109 ms 9196 KB Output is correct
74 Correct 155 ms 8936 KB Output is correct
75 Correct 177 ms 9256 KB Output is correct
76 Correct 136 ms 8624 KB Output is correct
77 Correct 149 ms 9060 KB Output is correct
78 Correct 156 ms 9144 KB Output is correct
79 Correct 128 ms 7444 KB Output is correct
80 Correct 151 ms 8564 KB Output is correct
81 Correct 161 ms 9112 KB Output is correct
82 Correct 172 ms 9032 KB Output is correct
83 Correct 101 ms 7904 KB Output is correct
84 Correct 105 ms 10320 KB Output is correct
85 Correct 81 ms 9804 KB Output is correct
86 Correct 72 ms 7824 KB Output is correct
87 Correct 108 ms 7540 KB Output is correct
88 Correct 146 ms 8100 KB Output is correct
89 Correct 119 ms 7592 KB Output is correct
90 Correct 107 ms 8268 KB Output is correct
91 Correct 88 ms 6556 KB Output is correct
92 Correct 114 ms 7824 KB Output is correct
93 Correct 142 ms 8176 KB Output is correct
94 Correct 152 ms 8996 KB Output is correct
95 Correct 177 ms 9608 KB Output is correct
96 Correct 128 ms 8640 KB Output is correct
97 Correct 116 ms 9064 KB Output is correct
98 Correct 119 ms 9016 KB Output is correct
99 Correct 137 ms 8376 KB Output is correct
100 Correct 153 ms 9172 KB Output is correct
101 Correct 141 ms 8552 KB Output is correct
102 Correct 164 ms 8960 KB Output is correct
103 Correct 171 ms 8864 KB Output is correct
104 Correct 135 ms 7900 KB Output is correct
105 Correct 160 ms 8908 KB Output is correct
106 Correct 194 ms 9120 KB Output is correct
107 Correct 118 ms 10824 KB Output is correct
108 Correct 143 ms 8916 KB Output is correct
109 Correct 136 ms 8892 KB Output is correct
110 Correct 141 ms 8824 KB Output is correct
111 Correct 128 ms 8812 KB Output is correct
112 Correct 138 ms 8828 KB Output is correct
113 Correct 135 ms 8892 KB Output is correct
114 Correct 132 ms 8804 KB Output is correct
115 Correct 130 ms 8824 KB Output is correct
116 Correct 133 ms 8808 KB Output is correct